Search in sources :

Example 96 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class TestValidation method validateLoadProperties.

@Test
public void validateLoadProperties() {
    System.setProperty("hikaricp.configurationFile", "/propfile1.properties");
    HikariConfig config = newHikariConfig();
    System.clearProperty("hikaricp.configurationFile");
    assertEquals(5, config.getMinimumIdle());
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 97 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project jphp by jphp-compiler.

the class PSqlDriverManager method getPool.

@Signature
public static PSqlConnectionPool getPool(Environment env, String url, String driverName, @Nullable Properties properties) throws SQLException {
    HikariConfig config = new HikariConfig(properties == null ? new Properties() : properties);
    if (config.getDataSourceClassName() == null) {
        config.setDataSourceClassName(dataSourceClasses.get(driverName));
    }
    HikariDataSource pool = new HikariDataSource(config);
    pool.setDriverClassName(_getDriverClass(driverName));
    pool.setJdbcUrl("jdbc:" + url);
    return new PSqlConnectionPool(env, pool);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) Properties(java.util.Properties) Signature(php.runtime.annotation.Reflection.Signature)

Example 98 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project torodb by torodb.

the class AbstractDbBackendService method createPooledDataSource.

private HikariDataSource createPooledDataSource(ConfigurationT configuration, String poolName, int poolSize, TransactionIsolationLevel transactionIsolationLevel, boolean readOnly) {
    HikariConfig hikariConfig = new HikariConfig();
    // Delegate database-specific setting of connection parameters and any specific configuration
    hikariConfig.setDataSource(getConfiguredDataSource(configuration, poolName));
    // Apply ToroDB-specific datasource configuration
    hikariConfig.setConnectionTimeout(configuration.getConnectionPoolTimeout());
    hikariConfig.setPoolName(poolName);
    hikariConfig.setMaximumPoolSize(poolSize);
    hikariConfig.setTransactionIsolation(transactionIsolationLevel.name());
    hikariConfig.setReadOnly(readOnly);
    /*
     * TODO: implement to add metric support. See
     * https://github.com/brettwooldridge/HikariCP/wiki/Codahale-Metrics
     * hikariConfig.setMetricRegistry(...);
     */
    LOGGER.info("Created pool {} with size {} and level {}", poolName, poolSize, transactionIsolationLevel.name());
    return new HikariDataSource(hikariConfig);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 99 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project opennms by OpenNMS.

the class HikariCPConnectionFactory method initializePool.

/* (non-Javadoc)
     * @see org.opennms.core.db.BaseConnectionFactory#initializePool(org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource)
     */
// TODO Enable and configure MetricRegistry
@Override
protected void initializePool(final JdbcDataSource dataSource) throws SQLException {
    final Properties properties = new Properties();
    for (final Param parameter : dataSource.getParamCollection()) {
        properties.setProperty(parameter.getName(), parameter.getValue());
    }
    final HikariConfig config = new HikariConfig(properties);
    config.setPoolName(dataSource.getName());
    config.setJdbcUrl(dataSource.getUrl());
    config.setUsername(dataSource.getUserName());
    config.setPassword(dataSource.getPassword());
    config.setDriverClassName(dataSource.getClassName());
    // NMS-9387: Block indefinitely when waiting for a connection
    config.setConnectionTimeout(0);
    // For JMX Monitoring
    config.setRegisterMbeans(true);
    config.validate();
    m_pool = new HikariDataSource(config);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Param(org.opennms.netmgt.config.opennmsDataSources.Param) Properties(java.util.Properties) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 100 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project AuthMeReloaded by AuthMe.

the class LoginSecurityConverterTest method initializeMySqlTable.

private Connection initializeMySqlTable() throws IOException, SQLException {
    File sqlInitFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "datasource/converter/loginsecurity.sql");
    String initStatement = new String(Files.readAllBytes(sqlInitFile.toPath()));
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.setConnectionTestQuery("VALUES 1");
    config.addDataSourceProperty("URL", "jdbc:h2:mem:test");
    config.addDataSourceProperty("user", "sa");
    config.addDataSourceProperty("password", "sa");
    HikariDataSource ds = new HikariDataSource(config);
    Connection connection = ds.getConnection();
    try (Statement st = connection.createStatement()) {
        st.execute("DROP TABLE IF EXISTS authme");
        st.execute(initStatement);
    }
    return connection;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) File(java.io.File)

Aggregations

HikariConfig (com.zaxxer.hikari.HikariConfig)101 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)85 HikariDataSource (com.zaxxer.hikari.HikariDataSource)75 Test (org.junit.Test)75 Connection (java.sql.Connection)48 StubConnection (com.zaxxer.hikari.mocks.StubConnection)28 SQLException (java.sql.SQLException)23 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)17 TestElf.setConfigUnitTest (com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)15 Properties (java.util.Properties)10 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)8 PreparedStatement (java.sql.PreparedStatement)6 DataSource (javax.sql.DataSource)6 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SQLTransientConnectionException (java.sql.SQLTransientConnectionException)5 Statement (java.sql.Statement)5 PrintStream (java.io.PrintStream)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 ResultSet (java.sql.ResultSet)3