@Test public void test() throws SQLException { Config config = ConfigFactory.empty() .withValue("poolName", ConfigValueFactory.fromAnyRef("test pool")) .withValue("jdbcUrl", ConfigValueFactory.fromAnyRef("jdbc:hsqldb:mem:testdb")) .withValue("maximumPoolSize", ConfigValueFactory.fromAnyRef(10)) .withValue("minimumIdle", ConfigValueFactory.fromAnyRef(2)) .withValue("username", ConfigValueFactory.fromAnyRef("SA")) .withValue("password", ConfigValueFactory.fromAnyRef("")) .withValue("cachePrepStmts", ConfigValueFactory.fromAnyRef(true)) .withValue("prepStmtCacheSize", ConfigValueFactory.fromAnyRef(256)) .withValue("prepStmtCacheSqlLimit", ConfigValueFactory.fromAnyRef(2048)) .withValue("useServerPrepStmts", ConfigValueFactory.fromAnyRef(true)) ; MetricRegistry metricRegistry = new MetricRegistry(); HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry(); try (HikariDataSource ds = ConnectionPool.getDataSourceFromConfig(config, metricRegistry, healthCheckRegistry)) { assertTrue(ds.getPoolName().equals("test pool")); assertTrue(ds.getMaximumPoolSize() == 10); assertTrue(ds.getMinimumIdle() == 2); assertTrue(ds.getUsername().equals("SA")); assertTrue(ds.getPassword().equals("")); Properties dsp = ds.getDataSourceProperties(); assertTrue(((boolean)dsp.get("cachePrepStmts")) == true); assertTrue(((int)dsp.get("prepStmtCacheSize")) == 256); assertTrue(((int)dsp.get("prepStmtCacheSqlLimit")) == 2048); assertTrue(((boolean)dsp.get("useServerPrepStmts")) == true); assertTrue(ds.getHealthCheckRegistry() == healthCheckRegistry); assertTrue(ds.getMetricRegistry() == metricRegistry); try (Connection conn = ds.getConnection()) { assertTrue(conn.isValid(1000)); } } }
public static HikariDataSource getDataSourceFromConfig( Config conf , MetricRegistry metricRegistry , HealthCheckRegistry healthCheckRegistry) { HikariConfig jdbcConfig = new HikariConfig(); jdbcConfig.setPoolName(conf.getString("poolName")); jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize")); jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle")); jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl")); jdbcConfig.setUsername(conf.getString("username")); jdbcConfig.setPassword(conf.getString("password")); jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts")); jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize")); jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit")); jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts")); jdbcConfig.setHealthCheckRegistry(healthCheckRegistry); jdbcConfig.setMetricRegistry(metricRegistry); return new HikariDataSource(jdbcConfig); }
ConnectionPool { public static HikariDataSource getDataSourceFromConfig( Config conf , MetricRegistry metricRegistry , HealthCheckRegistry healthCheckRegistry) { HikariConfig jdbcConfig = new HikariConfig(); jdbcConfig.setPoolName(conf.getString("poolName")); jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize")); jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle")); jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl")); jdbcConfig.setUsername(conf.getString("username")); jdbcConfig.setPassword(conf.getString("password")); jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts")); jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize")); jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit")); jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts")); jdbcConfig.setHealthCheckRegistry(healthCheckRegistry); jdbcConfig.setMetricRegistry(metricRegistry); return new HikariDataSource(jdbcConfig); } }
ConnectionPool { public static HikariDataSource getDataSourceFromConfig( Config conf , MetricRegistry metricRegistry , HealthCheckRegistry healthCheckRegistry) { HikariConfig jdbcConfig = new HikariConfig(); jdbcConfig.setPoolName(conf.getString("poolName")); jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize")); jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle")); jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl")); jdbcConfig.setUsername(conf.getString("username")); jdbcConfig.setPassword(conf.getString("password")); jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts")); jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize")); jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit")); jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts")); jdbcConfig.setHealthCheckRegistry(healthCheckRegistry); jdbcConfig.setMetricRegistry(metricRegistry); return new HikariDataSource(jdbcConfig); } private  ConnectionPool(); }
ConnectionPool { public static HikariDataSource getDataSourceFromConfig( Config conf , MetricRegistry metricRegistry , HealthCheckRegistry healthCheckRegistry) { HikariConfig jdbcConfig = new HikariConfig(); jdbcConfig.setPoolName(conf.getString("poolName")); jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize")); jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle")); jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl")); jdbcConfig.setUsername(conf.getString("username")); jdbcConfig.setPassword(conf.getString("password")); jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts")); jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize")); jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit")); jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts")); jdbcConfig.setHealthCheckRegistry(healthCheckRegistry); jdbcConfig.setMetricRegistry(metricRegistry); return new HikariDataSource(jdbcConfig); } private  ConnectionPool(); static HikariDataSource getDataSourceFromConfig(
        Config conf
        , MetricRegistry metricRegistry
        , HealthCheckRegistry healthCheckRegistry); }
ConnectionPool { public static HikariDataSource getDataSourceFromConfig( Config conf , MetricRegistry metricRegistry , HealthCheckRegistry healthCheckRegistry) { HikariConfig jdbcConfig = new HikariConfig(); jdbcConfig.setPoolName(conf.getString("poolName")); jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize")); jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle")); jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl")); jdbcConfig.setUsername(conf.getString("username")); jdbcConfig.setPassword(conf.getString("password")); jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts")); jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize")); jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit")); jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts")); jdbcConfig.setHealthCheckRegistry(healthCheckRegistry); jdbcConfig.setMetricRegistry(metricRegistry); return new HikariDataSource(jdbcConfig); } private  ConnectionPool(); static HikariDataSource getDataSourceFromConfig(
        Config conf
        , MetricRegistry metricRegistry
        , HealthCheckRegistry healthCheckRegistry);  }