Search in sources :

Example 1 with TomcatJdbcPoolMetricsReporter

use of org.platformlayer.metrics.TomcatJdbcPoolMetricsReporter in project platformlayer by platformlayer.

the class TomcatJdbcPoolDataSourceBuilder method buildDataSource.

@Override
public DataSource buildDataSource(String key, JdbcConfiguration jdbcConfig) {
    PoolProperties p = new PoolProperties();
    if (jdbcConfig.driverClassName != null) {
        p.setDriverClassName(jdbcConfig.driverClassName);
    }
    log.warn("Building data source for " + jdbcConfig.jdbcUrl);
    p.setUrl(jdbcConfig.jdbcUrl);
    p.setUsername(jdbcConfig.username);
    p.setPassword(jdbcConfig.password);
    String sqlDebug = null;
    if (jdbcConfig.extraProperties != null) {
        sqlDebug = jdbcConfig.extraProperties.get("sql.debug");
    }
    Properties jdbcProperties = buildDbProperties(jdbcConfig);
    if (!jdbcProperties.isEmpty()) {
        try {
            p.setDbProperties(jdbcProperties);
        } catch (Exception e) {
            throw new IllegalStateException("Unable to set JDBC properties", e);
        }
    }
    if (!Strings.isNullOrEmpty(sqlDebug)) {
        throw new UnsupportedOperationException();
    // pooledDataSource.setLogStatementsEnabled(Boolean.parseBoolean(sqlDebug));
    }
    p.setMinIdle(1);
    p.setInitialSize(1);
    List<String> interceptors = Lists.newArrayList();
    interceptors.add("org.apache.tomcat.jdbc.pool.interceptor.StatementCache");
    if (!interceptors.isEmpty()) {
        p.setJdbcInterceptors(Joiner.on(';').join(interceptors));
    }
    // p.setJmxEnabled(true);
    // p.setTestWhileIdle(false);
    // p.setTestOnBorrow(true);
    // p.setValidationQuery("SELECT 1");
    // p.setTestOnReturn(true);
    // p.setValidationInterval(30000);
    // p.setTimeBetweenEvictionRunsMillis(30000);
    // p.setMaxActive(100);
    // p.setInitialSize(10);
    // p.setMaxWait(10000);
    // p.setRemoveAbandonedTimeout(60);
    // p.setMinEvictableIdleTimeMillis(30000);
    // p.setMinIdle(10);
    // p.setLogAbandoned(true);
    // p.setRemoveAbandoned(true);
    // p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
    // + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    org.apache.tomcat.jdbc.pool.DataSource pooledDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
    pooledDataSource.setPoolProperties(p);
    databaseStatistics.register(key, pooledDataSource, new TomcatJdbcPoolMetricsReporter(databaseStatistics.getMetricKey(key), pooledDataSource));
    return pooledDataSource;
}
Also used : Properties(java.util.Properties) PoolProperties(org.apache.tomcat.jdbc.pool.PoolProperties) TomcatJdbcPoolMetricsReporter(org.platformlayer.metrics.TomcatJdbcPoolMetricsReporter) PoolProperties(org.apache.tomcat.jdbc.pool.PoolProperties) DataSource(javax.sql.DataSource)

Aggregations

Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 PoolProperties (org.apache.tomcat.jdbc.pool.PoolProperties)1 TomcatJdbcPoolMetricsReporter (org.platformlayer.metrics.TomcatJdbcPoolMetricsReporter)1