Search in sources :

Example 1 with BoneCpMetricsReporter

use of org.platformlayer.metrics.BoneCpMetricsReporter 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)

Aggregations

BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)1 Properties (java.util.Properties)1 BoneCpMetricsReporter (org.platformlayer.metrics.BoneCpMetricsReporter)1