Search in sources :

Example 1 with HikariDataSource

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

the class HikariCPConnectionProvider method prepare.

@Override
public synchronized void prepare() {
    if (dataSource == null) {
        Properties properties = new Properties();
        properties.putAll(configMap);
        HikariConfig config = new HikariConfig(properties);
        if (properties.containsKey("dataSource.url")) {
            LOG.info("DataSource Url: " + properties.getProperty("dataSource.url"));
        } else if (config.getJdbcUrl() != null) {
            LOG.info("JDBC Url: " + config.getJdbcUrl());
        }
        this.dataSource = new HikariDataSource(config);
        this.dataSource.setAutoCommit(false);
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Properties(java.util.Properties) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 2 with HikariDataSource

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

the class TxnHandler method setupJdbcConnectionPool.

private static synchronized void setupJdbcConnectionPool(HiveConf conf) throws SQLException {
    if (connPool != null)
        return;
    String driverUrl = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORECONNECTURLKEY);
    String user = getMetastoreJdbcUser(conf);
    String passwd = getMetastoreJdbcPasswd(conf);
    String connectionPooler = conf.getVar(HiveConf.ConfVars.METASTORE_CONNECTION_POOLING_TYPE).toLowerCase();
    if ("bonecp".equals(connectionPooler)) {
        BoneCPConfig config = new BoneCPConfig();
        config.setJdbcUrl(driverUrl);
        //if we are waiting for connection for 60s, something is really wrong
        //better raise an error than hang forever
        config.setConnectionTimeoutInMs(60000);
        config.setMaxConnectionsPerPartition(10);
        config.setPartitionCount(1);
        config.setUser(user);
        config.setPassword(passwd);
        connPool = new BoneCPDataSource(config);
        // Enable retries to work around BONECP bug.
        doRetryOnConnPool = true;
    } else if ("dbcp".equals(connectionPooler)) {
        ObjectPool objectPool = new GenericObjectPool();
        ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, user, passwd);
        // This doesn't get used, but it's still necessary, see
        // http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/doc/ManualPoolingDataSourceExample.java?view=markup
        PoolableConnectionFactory poolConnFactory = new PoolableConnectionFactory(connFactory, objectPool, null, null, false, true);
        connPool = new PoolingDataSource(objectPool);
    } else if ("hikaricp".equals(connectionPooler)) {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(driverUrl);
        config.setUsername(user);
        config.setPassword(passwd);
        connPool = new HikariDataSource(config);
    } else if ("none".equals(connectionPooler)) {
        LOG.info("Choosing not to pool JDBC connections");
        connPool = new NoPoolConnectionPool(conf);
    } else {
        throw new RuntimeException("Unknown JDBC connection pooling " + connectionPooler);
    }
}
Also used : PoolingDataSource(org.apache.commons.dbcp.PoolingDataSource) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool) HikariConfig(com.zaxxer.hikari.HikariConfig) PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory) ConnectionFactory(org.apache.commons.dbcp.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool) ObjectPool(org.apache.commons.pool.ObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory)

Example 3 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project jOOQ by jOOQ.

the class SakilaReportService method initDB.

private static void initDB() throws Exception {
    final Properties properties = new Properties();
    properties.load(SakilaReportService.class.getResourceAsStream("/config.properties"));
    Class.forName(properties.getProperty("db.driver"));
    HikariDataSource ds = new HikariDataSource();
    ds.setJdbcUrl(properties.getProperty("db.url"));
    ds.setUsername(properties.getProperty("db.username"));
    ds.setPassword(properties.getProperty("db.password"));
    // Some nice debug logging of formatted queries and the first 5 rows in each result set.
    dsl = DSL.using(new DefaultConfiguration().set(ds).set(DefaultExecuteListenerProvider.providers(new DefaultExecuteListener() {

        @Override
        public void executeEnd(ExecuteContext ctx) {
            Configuration config = ctx.configuration().derive();
            config.settings().setRenderFormatted(true);
            log.info("\n" + DSL.using(config).renderInlined(ctx.query()));
        }

        @Override
        public void fetchEnd(ExecuteContext ctx) {
            log.info("\n" + ctx.result().format(5));
        }
    })));
}
Also used : DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Configuration(org.jooq.Configuration) ExecuteContext(org.jooq.ExecuteContext) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Properties(java.util.Properties)

Example 4 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project killbill by killbill.

the class TestKillbillJdbcTenantRealm method beforeMethod.

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
    super.beforeMethod();
    // Create the tenant
    final DefaultTenantDao tenantDao = new DefaultTenantDao(dbi, clock, cacheControllerDispatcher, new DefaultNonEntityDao(dbi), Mockito.mock(InternalCallContextFactory.class), securityConfig);
    tenant = new DefaultTenant(UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    tenantDao.create(new TenantModelDao(tenant), internalCallContext);
    // Setup the security manager
    final HikariConfig dbConfig = new HikariConfig();
    dbConfig.setJdbcUrl(helper.getJdbcConnectionString());
    dbConfig.setUsername(helper.getUsername());
    dbConfig.setPassword(helper.getPassword());
    final KillbillJdbcTenantRealm jdbcRealm = new KillbillJdbcTenantRealm(shiroDataSource, securityConfig);
    jdbcRealm.setDataSource(new HikariDataSource(dbConfig));
    securityManager = new DefaultSecurityManager(jdbcRealm);
}
Also used : DefaultNonEntityDao(org.killbill.billing.util.dao.DefaultNonEntityDao) DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) HikariDataSource(com.zaxxer.hikari.HikariDataSource) TenantModelDao(org.killbill.billing.tenant.dao.TenantModelDao) HikariConfig(com.zaxxer.hikari.HikariConfig) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) InternalCallContextFactory(org.killbill.billing.util.callcontext.InternalCallContextFactory) DefaultTenantDao(org.killbill.billing.tenant.dao.DefaultTenantDao) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource in project hibernate-orm by hibernate.

the class HikariCPConnectionProvider method configure.

// *************************************************************************
// Configurable
// *************************************************************************
@SuppressWarnings("rawtypes")
@Override
public void configure(Map props) throws HibernateException {
    try {
        LOGGER.debug("Configuring HikariCP");
        hcfg = HikariConfigurationUtil.loadConfiguration(props);
        hds = new HikariDataSource(hcfg);
    } catch (Exception e) {
        throw new HibernateException(e);
    }
    LOGGER.debug("HikariCP Configured");
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) UnknownUnwrapTypeException(org.hibernate.service.UnknownUnwrapTypeException) HibernateException(org.hibernate.HibernateException)

Aggregations

HikariDataSource (com.zaxxer.hikari.HikariDataSource)114 Test (org.junit.Test)78 HikariConfig (com.zaxxer.hikari.HikariConfig)75 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)63 Connection (java.sql.Connection)63 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)33 StubConnection (com.zaxxer.hikari.mocks.StubConnection)29 SQLException (java.sql.SQLException)27 TestElf.setConfigUnitTest (com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)16 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)10 MetricRegistry (com.codahale.metrics.MetricRegistry)8 PreparedStatement (java.sql.PreparedStatement)6 Statement (java.sql.Statement)6 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)5 SQLTransientConnectionException (java.sql.SQLTransientConnectionException)5 Properties (java.util.Properties)5 ResultSet (java.sql.ResultSet)4 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)3 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3