public void connect() {
   if (dataSource == null || dataSource.isClosed()) {
     dataSource = new HikariDataSource();
     dataSource.setJdbcUrl(jdbcURL);
     dataSource.setUsername(username);
     dataSource.setPoolName(poolname);
     dataSource.setAutoCommit(autoCommit);
     dataSource.setMaximumPoolSize(maximalPoolSize);
     if (passwd != null) dataSource.setPassword(passwd);
     if (sqlInit != null) dataSource.setConnectionInitSql(sqlInit);
     if (sqlTest != null) dataSource.setConnectionTestQuery(sqlTest);
     if (timeout != null) dataSource.setConnectionTimeout(timeout);
     if (jdbcDriverClassName != null) dataSource.setDriverClassName(jdbcDriverClassName);
   }
 }
Example #2
0
  /**
   * @return Connection from the connection pool. Clients must <code>close()</code> it when they are
   *     done with it.
   * @throws SQLException
   */
  public static synchronized Connection getConnection() throws SQLException {
    if (dataSource == null) {
      final Configuration config = Application.getConfiguration();
      final String connectionString = config.getString(JDBC_URL_CONFIG_KEY, "");
      final int connectionTimeout = 1000 * config.getInt(CONNECTION_TIMEOUT_CONFIG_KEY, 10);
      final int maxPoolSize = config.getInt(MAX_POOL_SIZE_CONFIG_KEY, 10);
      final String user = config.getString(USER_CONFIG_KEY, "");
      final String password = config.getString(PASSWORD_CONFIG_KEY, "");

      dataSource = new HikariDataSource();
      dataSource.setJdbcUrl(connectionString);
      dataSource.setUsername(user);
      dataSource.setPassword(password);
      dataSource.setPoolName("JdbcResolverPool");
      dataSource.setMaximumPoolSize(maxPoolSize);
      dataSource.setConnectionTimeout(connectionTimeout);
    }
    return dataSource.getConnection();
  }