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);
}
}
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;
}
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();
}
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();
}
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");
}
Aggregations