コード例 #1
1
ファイル: ContextMysqL.java プロジェクト: BohdanKorinnyi/JPA
 @Bean(destroyMethod = "close")
 DataSource dataSource() {
   HikariConfig dataSourceConfig = new HikariConfig();
   dataSourceConfig.setJdbcUrl(env.getRequiredProperty("db.url"));
   dataSourceConfig.setDriverClassName(env.getRequiredProperty("db.driver"));
   dataSourceConfig.setUsername(env.getRequiredProperty("db.username"));
   dataSourceConfig.setPassword(env.getRequiredProperty("db.password"));
   return new HikariDataSource(dataSourceConfig);
 }
コード例 #2
0
ファイル: DataSourceModule.java プロジェクト: cogman/gluews
  @Provides
  @Singleton
  DataSource provideDataSource() {
    HikariConfig config = new HikariConfig();

    // The URL and driver should be changed to match your database
    // for MSSQL, this is a valid URI, cwad is the address of the database server and LM is the
    // database name
    // Similar to saying "USE LM" in your sql code
    config.setJdbcUrl("jdbc:sqlserver://cwad;database=LM");
    config.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    config.setConnectionTimeout(20000);
    config.setMaximumPoolSize(20);

    // Change this to an easy to identify thread pool name.  This helps with debugging
    config.setPoolName("LM-DB-POOL");

    // This should probably be gotten in a different way, ideally it would be something like
    // an environment variable or a config file value rather than a hard coded value.
    config.setUsername("perseus");
    config.setPassword("perseus");

    return new HikariDataSource(config);
  }
コード例 #3
0
  @Bean(destroyMethod = "close")
  public DataSource dataSource() throws SQLException {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setDriverClassName(databaseDriverClassName);
    hikariConfig.setJdbcUrl(datasourceUrl);
    hikariConfig.setUsername(databaseUsername);
    hikariConfig.setPassword(databasePassword);

    return new HikariDataSource(hikariConfig);
  }
コード例 #4
0
  @Bean
  public DataSource dataSource() {

    HikariConfig config = new HikariConfig();
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://127.0.0.1:3307/meer-spring-jpa");
    config.setUsername("root");
    config.setPassword("");

    return new HikariDataSource(config);
  }
コード例 #5
0
  public MySQLDatabase(
      Logger log, String ip, String port, String database, String username, String password) {
    super(log, "MySQL");
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:mysql://" + ip + ":" + port + "/" + database);
    hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
    hikariConfig.setUsername(username);
    hikariConfig.setPassword(password);
    hikariConfig.setMinimumIdle(1);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setConnectionTimeout(10000);

    _source = new HikariDataSource(hikariConfig);
  }
コード例 #6
0
  @Bean
  public DataSource configureDataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setJdbcUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("useServerPrepStmts", "true");

    return new HikariDataSource(config);
  }
コード例 #7
0
  public static HikariDataSource getHikari() {

    config.setJdbcUrl(urlHC);
    config.setUsername(userHC);
    config.setPassword(passwordHC);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.setMaximumPoolSize(3);
    config.setIdleTimeout(28740000);
    config.setMaxLifetime(28740000);
    config.setConnectionTimeout(34000);

    HikariDataSource ds = new HikariDataSource(config);

    System.out.println("Returning HikairDataSource \n");
    return ds;
  }
コード例 #8
0
ファイル: Database.java プロジェクト: Civcraft/NameLayer
  /**
   * Configure the database pool.
   *
   * @param logger A JUL logger to use for error reporting, etc.
   * @param user The user to connect as
   * @param pass The password to use
   * @param host The host to connect to
   * @param port The port to connect to
   * @param database The database to use
   * @param poolSize How many connections at most to keep in the connection pool awaiting activity.
   *     Consider this against your Database's max connections across all askers.
   * @param connectionTimeout How long will a single connection wait for activity before timing out.
   * @param idleTimeout How long will a connection wait in the pool, typically, inactive.
   * @param maxLifetime How long will a connection be kept alive at maximum
   */
  public Database(
      Logger logger,
      String user,
      String pass,
      String host,
      int port,
      String database,
      int poolSize,
      long connectionTimeout,
      long idleTimeout,
      long maxLifetime) {
    this.logger = logger;
    if (user != null && host != null && port > 0 && database != null) {
      HikariConfig config = new HikariConfig();
      config.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database);
      config.setConnectionTimeout(connectionTimeout); // 10000l);
      config.setIdleTimeout(idleTimeout); // 600000l);
      config.setMaxLifetime(maxLifetime); // 7200000l);
      config.setMaximumPoolSize(poolSize); // 10);
      config.setUsername(user);
      if (pass != null) {
        config.setPassword(pass);
      }
      this.datasource = new HikariDataSource(config);

      try { // No-op test.
        Connection connection = getConnection();
        Statement statement = connection.createStatement();
        statement.execute("SELECT 1");
        statement.close();
        connection.close();
      } catch (SQLException se) {
        this.logger.log(Level.SEVERE, "Unable to initialize Database", se);
        this.datasource = null;
      }
    } else {
      this.datasource = null;
      this.logger.log(Level.SEVERE, "Database not configured and is unavaiable");
    }
  }