Search in sources :

Example 1 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project pinpoint by naver.

the class DataSourceConstructorInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (!InterceptorUtils.isSuccess(throwable)) {
        return;
    }
    if ((target instanceof DataSourceMonitorAccessor) && (target instanceof BasicDataSource)) {
        Dbcp2DataSourceMonitor dbcpDataSourceMonitor = new Dbcp2DataSourceMonitor((BasicDataSource) target);
        dataSourceMonitorRegistry.register(dbcpDataSourceMonitor);
        ((DataSourceMonitorAccessor) target)._$PINPOINT$_setDataSourceMonitor(dbcpDataSourceMonitor);
    }
}
Also used : Dbcp2DataSourceMonitor(com.navercorp.pinpoint.plugin.commons.dbcp2.Dbcp2DataSourceMonitor) DataSourceMonitorAccessor(com.navercorp.pinpoint.plugin.commons.dbcp2.DataSourceMonitorAccessor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource)

Example 2 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project KeyBox by skavanagh.

the class DSPool method registerDataSource.

/**
     * register the data source for H2 DB
     *
     * @return pooling database object
     */
private static BasicDataSource registerDataSource() {
    System.setProperty("h2.baseDir", BASE_DIR);
    // create a database connection
    String user = AppConfig.getProperty("dbUser");
    String password = AppConfig.decryptProperty("dbPassword");
    String connectionURL = AppConfig.getProperty("dbConnectionURL");
    if (connectionURL != null && connectionURL.contains("CIPHER=")) {
        password = "filepwd " + password;
    }
    String validationQuery = "select 1";
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(DB_DRIVER);
    dataSource.setMaxTotal(MAX_ACTIVE);
    dataSource.setTestOnBorrow(TEST_ON_BORROW);
    dataSource.setMinIdle(MIN_IDLE);
    dataSource.setMaxWaitMillis(MAX_WAIT);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setUrl(connectionURL);
    return dataSource;
}
Also used : BasicDataSource(org.apache.commons.dbcp2.BasicDataSource)

Example 3 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project spring-boot by spring-projects.

the class DataSourceAutoConfigurationTests method commonsDbcp2ValidatesConnectionByDefault.

@Test
public void commonsDbcp2ValidatesConnectionByDefault() throws Exception {
    org.apache.commons.dbcp2.BasicDataSource dataSource = autoConfigureDataSource(org.apache.commons.dbcp2.BasicDataSource.class, "org.apache.tomcat", "com.zaxxer.hikari");
    assertThat(dataSource.getTestOnBorrow()).isEqualTo(true);
    // Use Connection#isValid()
    assertThat(dataSource.getValidationQuery()).isNull();
}
Also used : BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) Test(org.junit.Test)

Example 4 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project spring-boot by spring-projects.

the class JdbcTemplateAutoConfigurationTests method testJdbcTemplateExistsWithCustomDataSource.

@Test
public void testJdbcTemplateExistsWithCustomDataSource() throws Exception {
    this.context.register(TestDataSourceConfiguration.class, DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
    assertThat(jdbcTemplate).isNotNull();
    assertThat(jdbcTemplate.getDataSource() instanceof BasicDataSource).isTrue();
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) Test(org.junit.Test)

Example 5 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project spring-boot by spring-projects.

the class CommonsDbcp2DataSourcePoolMetadataTests method getValidationQuery.

@Override
public void getValidationQuery() {
    BasicDataSource dataSource = createDataSource();
    dataSource.setValidationQuery("SELECT FROM FOO");
    assertThat(new CommonsDbcp2DataSourcePoolMetadata(dataSource).getValidationQuery()).isEqualTo("SELECT FROM FOO");
}
Also used : BasicDataSource(org.apache.commons.dbcp2.BasicDataSource)

Aggregations

BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)20 Test (org.junit.Test)10 DataSource (javax.sql.DataSource)3 SQLException (java.sql.SQLException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 DataSourceMonitorAccessor (com.navercorp.pinpoint.plugin.commons.dbcp2.DataSourceMonitorAccessor)1 Dbcp2DataSourceMonitor (com.navercorp.pinpoint.plugin.commons.dbcp2.Dbcp2DataSourceMonitor)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 InitialContext (javax.naming.InitialContext)1 ManagedConnection (org.apache.commons.dbcp2.managed.ManagedConnection)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1 JDBCDataSource (org.hsqldb.jdbc.JDBCDataSource)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 MBeanExporter (org.springframework.jmx.export.MBeanExporter)1