Search in sources :

Example 6 with BoneCPDataSource

use of com.jolbox.bonecp.BoneCPDataSource in project platformlayer by platformlayer.

the class BonecpDataSourceBuilder method buildDataSource.

@Override
public DataSource buildDataSource(String key, JdbcConfiguration jdbcConfig) {
    BoneCPDataSource pooledDataSource = new BoneCPDataSource();
    if (jdbcConfig.driverClassName != null) {
        try {
            Class.forName(jdbcConfig.driverClassName);
        } catch (ClassNotFoundException e) {
            log.warn("Ignoring error loading DB driver", e);
        }
    }
    // pooledDataSource.setDriverClassName(getProperty(keyPrefix + "driverClassName"));
    pooledDataSource.setJdbcUrl(jdbcConfig.jdbcUrl);
    pooledDataSource.setUsername(jdbcConfig.username);
    pooledDataSource.setPassword(jdbcConfig.password);
    String sqlDebug = null;
    if (jdbcConfig.extraProperties != null) {
        sqlDebug = jdbcConfig.extraProperties.get("sql.debug");
    }
    Properties jdbcProperties = buildDbProperties(jdbcConfig);
    if (!jdbcProperties.isEmpty()) {
        try {
            pooledDataSource.setDriverProperties(jdbcProperties);
        } catch (Exception e) {
            throw new IllegalStateException("Unable to set JDBC properties", e);
        }
    }
    if (!Strings.isNullOrEmpty(sqlDebug)) {
        pooledDataSource.setLogStatementsEnabled(Boolean.parseBoolean(sqlDebug));
    }
    pooledDataSource.setPartitionCount(1);
    pooledDataSource.setMinConnectionsPerPartition(1);
    // Don't auto-acquire new connections
    // TODO: This is broken!!!
    pooledDataSource.setPoolAvailabilityThreshold(0);
    // Enable statement caching
    pooledDataSource.setStatementsCacheSize(32);
    // Track statistics
    pooledDataSource.setStatisticsEnabled(true);
    pooledDataSource.setConnectionHook(new BoneCPConnectionHook(key));
    databaseStatistics.register(key, pooledDataSource, new BoneCpMetricsReporter(databaseStatistics.getMetricKey(key), pooledDataSource));
    log.warn("Building data source for " + jdbcConfig.jdbcUrl);
    return pooledDataSource;
}
Also used : BoneCpMetricsReporter(org.platformlayer.metrics.BoneCpMetricsReporter) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) Properties(java.util.Properties)

Example 7 with BoneCPDataSource

use of com.jolbox.bonecp.BoneCPDataSource in project querydsl by querydsl.

the class JdbcConfiguration method dataSource.

@Bean
public DataSource dataSource() {
    BoneCPDataSource dataSource = new BoneCPDataSource();
    dataSource.setDriverClass(env.getRequiredProperty("jdbc.driver"));
    dataSource.setJdbcUrl(env.getRequiredProperty("jdbc.url"));
    dataSource.setUsername(env.getRequiredProperty("jdbc.user"));
    dataSource.setPassword(env.getRequiredProperty("jdbc.password"));
    return dataSource;
}
Also used : BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) Bean(org.springframework.context.annotation.Bean)

Example 8 with BoneCPDataSource

use of com.jolbox.bonecp.BoneCPDataSource in project druid by alibaba.

the class Case1 method test_bonecp.

public void test_bonecp() throws Exception {
    BoneCPDataSource dataSource = new BoneCPDataSource();
    // dataSource.(10);
    // dataSource.setMaxActive(50);
    dataSource.setMinConnectionsPerPartition(minPoolSize);
    dataSource.setMaxConnectionsPerPartition(maxPoolSize);
    dataSource.setDriverClass(driverClass);
    dataSource.setJdbcUrl(jdbcUrl);
    dataSource.setStatementsCacheSize(100);
    dataSource.setServiceOrder("LIFO");
    // dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    // dataSource.setConnectionTestStatement("SELECT 1");
    dataSource.setPartitionCount(1);
    dataSource.setAcquireIncrement(5);
    dataSource.setIdleConnectionTestPeriod(0L);
    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "boneCP", threadCount);
    }
    System.out.println();
}
Also used : BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource)

Example 9 with BoneCPDataSource

use of com.jolbox.bonecp.BoneCPDataSource in project druid by alibaba.

the class Case3 method boneCP.

public void boneCP() throws Exception {
    BoneCPDataSource dataSource = new BoneCPDataSource();
    // dataSource.(10);
    // dataSource.setMaxActive(50);
    dataSource.setMinConnectionsPerPartition(minIdle);
    dataSource.setMaxConnectionsPerPartition(maxIdle);
    dataSource.setDriverClass(driverClass);
    dataSource.setJdbcUrl(jdbcUrl);
    // dataSource.setPoolPreparedStatements(true);
    // dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setConnectionTestStatement(validationQuery);
    dataSource.setPartitionCount(1);
    Properties connectionProperties = new Properties();
    connectionProperties.put("connectSleep", "3");
    connectionProperties.put("executeSleep", "1");
    dataSource.setDriverProperties(connectionProperties);
    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "boneCP", threadCount);
    }
    System.out.println();
}
Also used : BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) Properties(java.util.Properties)

Example 10 with BoneCPDataSource

use of com.jolbox.bonecp.BoneCPDataSource in project druid by alibaba.

the class Case4 method test_bonecp.

public void test_bonecp() throws Exception {
    BoneCPDataSource dataSource = new BoneCPDataSource();
    // dataSource.(10);
    // dataSource.setMaxActive(50);
    dataSource.setMinConnectionsPerPartition(minPoolSize);
    dataSource.setMaxConnectionsPerPartition(maxPoolSize);
    dataSource.setDriverClass(driverClass);
    dataSource.setJdbcUrl(jdbcUrl);
    dataSource.setStatementsCacheSize(maxOpenPreparedStatements);
    dataSource.setServiceOrder("LIFO");
    // dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    // dataSource.setConnectionTestStatement("SELECT 1");
    dataSource.setPartitionCount(1);
    dataSource.setAcquireIncrement(5);
    dataSource.setIdleConnectionTestPeriod(0L);
    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "boneCP", threadCount);
    }
    System.out.println();
}
Also used : BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource)

Aggregations

BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)15 BoneCPConfig (com.jolbox.bonecp.BoneCPConfig)3 Properties (java.util.Properties)3 HikariConfig (com.zaxxer.hikari.HikariConfig)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 DataSource (javax.sql.DataSource)1 XADataSource (javax.sql.XADataSource)1 ConnectionFactory (org.apache.commons.dbcp.ConnectionFactory)1 DriverManagerConnectionFactory (org.apache.commons.dbcp.DriverManagerConnectionFactory)1 PoolableConnectionFactory (org.apache.commons.dbcp.PoolableConnectionFactory)1