Skip to content

Instantly share code, notes, and snippets.

@djerraballi
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djerraballi/46b46ff89f5635af1c3e to your computer and use it in GitHub Desktop.
Save djerraballi/46b46ff89f5635af1c3e to your computer and use it in GitHub Desktop.
private static final Integer IDLE_TIMEOUT_DEFAULT = 240000;
private static final Boolean PREP_STMT_CACHE_DEFAULT = true;
private static final Integer PREP_STMT_CACHE_SIZE_DEFAULT = 250;
private static final Integer PREP_STMT_CACHE_SQL_LIMIT_DEFAULT = 2048;
private static final Integer MAX_POOL_SIZE = 15;
private static final Integer MIN_IDLE_POOL = 5;
private static final Integer LEAK_DETECTION_THRESHOLD = 30000;
final HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(getDBConnectionUrl());
hikariConfig.setDriverClassName(config.getString(getConfigKey("driver_name")));
hikariConfig.setUsername(getUser());
hikariConfig.setPassword(getPassword());
hikariConfig.addDataSourceProperty("cachePrepStmts", config.getBooleanOrDefault(
getConfigKey("prep_stmt_cache"), PREP_STMT_CACHE_DEFAULT));
hikariConfig.addDataSourceProperty("prepStmtCacheSize", config.getIntegerOrDefault(
getConfigKey("prep_stmt_cache_size"), PREP_STMT_CACHE_SIZE_DEFAULT));
hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", config.getIntegerOrDefault(
getConfigKey("prep_stmt_cache_sql_limit"), PREP_STMT_CACHE_SQL_LIMIT_DEFAULT));
hikariConfig.setPoolName(config.getString(getConfigKey("pool_instance_name")));
hikariConfig.setMetricRegistry(metricRegistry);
// TODO DEFAULTS
int maxPoolSize = config.getIntegerOrDefault(
getConfigKey("max_pool_size"), MAX_POOL_SIZE);
hikariConfig.setMaximumPoolSize(maxPoolSize);
int minIdle = config.getIntegerOrDefault(
getConfigKey("min_idle"), MIN_IDLE_POOL);
hikariConfig.setMinimumIdle(minIdle);
// 30 seconds less than ANY database connection timeout
long maxLifetime = config.getIntegerOrDefault(
getConfigKey("max_lifetime"), IDLE_TIMEOUT_DEFAULT);
hikariConfig.setMaxLifetime(maxLifetime);
// 30 seconds less than ANY connection timeout
long idleTimeout = config.getIntegerOrDefault(
getConfigKey("idle_timeout"), IDLE_TIMEOUT_DEFAULT);
hikariConfig.setIdleTimeout(idleTimeout);
long leakDetectionThreshold = config.getIntegerOrDefault(
getConfigKey("leak_detection_threshold"), LEAK_DETECTION_THRESHOLD);
hikariConfig.setLeakDetectionThreshold(leakDetectionThreshold);
final HikariDataSource ds = new HikariDataSource(hikariConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment