Search in sources :

Example 36 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project aries by apache.

the class AbstractInternalJDBCConnectionProviderFactory method poolIfNecessary.

protected DataSource poolIfNecessary(Map<String, Object> resourceProviderProperties, DataSource unpooled) {
    DataSource toUse;
    if (toBoolean(resourceProviderProperties, CONNECTION_POOLING_ENABLED, true)) {
        HikariConfig hcfg = new HikariConfig();
        hcfg.setDataSource(unpooled);
        // Sizes
        hcfg.setMaximumPoolSize(toInt(resourceProviderProperties, MAX_CONNECTIONS, 10));
        hcfg.setMinimumIdle(toInt(resourceProviderProperties, MIN_CONNECTIONS, 10));
        // Timeouts
        hcfg.setConnectionTimeout(toLong(resourceProviderProperties, CONNECTION_TIMEOUT, SECONDS.toMillis(30)));
        hcfg.setIdleTimeout(toLong(resourceProviderProperties, IDLE_TIMEOUT, TimeUnit.MINUTES.toMillis(3)));
        hcfg.setMaxLifetime(toLong(resourceProviderProperties, CONNECTION_LIFETIME, HOURS.toMillis(3)));
        hcfg.setConnectionTestQuery(toString(resourceProviderProperties, CONNECTION_TEST_QUERY, null));
        toUse = new HikariDataSource(hcfg);
    } else {
        toUse = unpooled;
    }
    return toUse;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource)

Example 37 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project spring-boot by spring-projects.

the class DataSourceAutoConfigurationTests method hikariValidatesConnectionByDefault.

@Test
public void hikariValidatesConnectionByDefault() throws Exception {
    HikariDataSource dataSource = autoConfigureDataSource(HikariDataSource.class, "org.apache.tomcat");
    assertThat(dataSource.getConnectionTestQuery()).isNull();
// Use Connection#isValid()
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Test(org.junit.Test)

Example 38 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project spring-boot by spring-projects.

the class HikariDataSourcePoolMetadataTests method getValidationQuery.

@Override
public void getValidationQuery() {
    HikariDataSource dataSource = createDataSource(0, 4);
    dataSource.setConnectionTestQuery("SELECT FROM FOO");
    assertThat(new HikariDataSourcePoolMetadata(dataSource).getValidationQuery()).isEqualTo("SELECT FROM FOO");
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource)

Example 39 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project spring-boot by spring-projects.

the class HikariDataSourcePoolMetadataTests method createDataSource.

private HikariDataSource createDataSource(int minSize, int maxSize) {
    HikariDataSource dataSource = (HikariDataSource) initializeBuilder().type(HikariDataSource.class).build();
    dataSource.setMinimumIdle(minSize);
    dataSource.setMaximumPoolSize(maxSize);
    return dataSource;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource)

Example 40 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project jDialects by drinkjava2.

the class DialectTest method buildH2Datasource.

// =======test guess dialects=======
private static HikariDataSource buildH2Datasource() {
    HikariDataSource ds = new HikariDataSource();
    ds.addDataSourceProperty("cachePrepStmts", true);
    ds.addDataSourceProperty("prepStmtCacheSize", 250);
    ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
    ds.addDataSourceProperty("useServerPrepStmts", true);
    ds.setMaximumPoolSize(3);
    ds.setConnectionTimeout(5000);
    ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
    ds.setDriverClassName("org.h2.Driver");
    ds.setUsername("sa");
    ds.setPassword("");
    return ds;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource)

Aggregations

HikariDataSource (com.zaxxer.hikari.HikariDataSource)185 HikariConfig (com.zaxxer.hikari.HikariConfig)109 Test (org.junit.Test)106 Connection (java.sql.Connection)61 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)57 SQLException (java.sql.SQLException)33 StubConnection (com.zaxxer.hikari.mocks.StubConnection)30 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)18 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataSource (javax.sql.DataSource)8 Statement (java.sql.Statement)7 ArrayList (java.util.ArrayList)7 FacesMessage (javax.faces.application.FacesMessage)7 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)6 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)6 Properties (java.util.Properties)6 ConnexionTest (connexion.ConnexionTest)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5