use of com.alibaba.druid.pool.DruidDataSource in project spring-boot-quick by vector4wang.
the class DataSourcePrimaryConfig method testDataSource.
@Bean(name = "primaryDataSource", initMethod = "init", destroyMethod = "close")
@Primary
public DataSource testDataSource() throws SQLException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(druidConfigPrimaryProperties.getDriverClassName());
druidDataSource.setUrl(druidConfigPrimaryProperties.getUrl());
druidDataSource.setUsername(druidConfigPrimaryProperties.getUsername());
druidDataSource.setPassword(druidConfigPrimaryProperties.getPassword());
druidDataSource.setInitialSize(druidConfigPrimaryProperties.getMinIdle());
druidDataSource.setMinIdle(druidConfigPrimaryProperties.getMinIdle());
druidDataSource.setMaxActive(druidConfigPrimaryProperties.getMaxActive());
druidDataSource.setMaxWait(druidConfigPrimaryProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(druidConfigPrimaryProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(druidConfigPrimaryProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(druidConfigPrimaryProperties.getValidationQuery());
druidDataSource.setTestWhileIdle(druidConfigPrimaryProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(druidConfigPrimaryProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(druidConfigPrimaryProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(druidConfigPrimaryProperties.getPoolPreparedStatements());
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(druidConfigPrimaryProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(druidConfigPrimaryProperties.getFilters());
return druidDataSource;
}
use of com.alibaba.druid.pool.DruidDataSource in project spring-boot-quick by vector4wang.
the class DataSourceSecondaryConfig method testDataSource.
@Bean(name = "secondaryDataSource", initMethod = "init", destroyMethod = "close")
public DataSource testDataSource() throws SQLException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(druidConfigSecondaryProperties.getDriverClassName());
druidDataSource.setUrl(druidConfigSecondaryProperties.getUrl());
druidDataSource.setUsername(druidConfigSecondaryProperties.getUsername());
druidDataSource.setPassword(druidConfigSecondaryProperties.getPassword());
druidDataSource.setInitialSize(druidConfigSecondaryProperties.getMinIdle());
druidDataSource.setMinIdle(druidConfigSecondaryProperties.getMinIdle());
druidDataSource.setMaxActive(druidConfigSecondaryProperties.getMaxActive());
druidDataSource.setMaxWait(druidConfigSecondaryProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(druidConfigSecondaryProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(druidConfigSecondaryProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(druidConfigSecondaryProperties.getValidationQuery());
druidDataSource.setTestWhileIdle(druidConfigSecondaryProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(druidConfigSecondaryProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(druidConfigSecondaryProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(druidConfigSecondaryProperties.getPoolPreparedStatements());
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(druidConfigSecondaryProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(druidConfigSecondaryProperties.getFilters());
return druidDataSource;
}
use of com.alibaba.druid.pool.DruidDataSource in project cloud-sea-towerman by huadahuang1983.
the class DataSourceConfig method druidDataSource.
@Bean
@Primary
public DataSource druidDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
logger.error("druid configuration initialization filter", e);
}
return datasource;
}
use of com.alibaba.druid.pool.DruidDataSource in project jfinal by jfinal.
the class DruidPlugin method start.
public boolean start() {
if (isStarted)
return true;
ds = new DruidDataSource();
if (this.name != null) {
ds.setName(this.name);
}
ds.setUrl(url);
ds.setUsername(username);
ds.setPassword(password);
if (driverClass != null)
ds.setDriverClassName(driverClass);
ds.setInitialSize(initialSize);
ds.setMinIdle(minIdle);
ds.setMaxActive(maxActive);
ds.setMaxWait(maxWait);
ds.setTimeBetweenConnectErrorMillis(timeBetweenConnectErrorMillis);
ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
ds.setValidationQuery(validationQuery);
if (StrKit.notBlank(connectionInitSql)) {
List<String> connectionInitSqls = new ArrayList<String>();
connectionInitSqls.add(this.connectionInitSql);
ds.setConnectionInitSqls(connectionInitSqls);
}
ds.setTestWhileIdle(testWhileIdle);
ds.setTestOnBorrow(testOnBorrow);
ds.setTestOnReturn(testOnReturn);
ds.setRemoveAbandoned(removeAbandoned);
ds.setRemoveAbandonedTimeoutMillis(removeAbandonedTimeoutMillis);
ds.setLogAbandoned(logAbandoned);
// 只要maxPoolPreparedStatementPerConnectionSize>0,poolPreparedStatements就会被自动设定为true,参照druid的源码
ds.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
if (defaultTransactionIsolation != null) {
ds.setDefaultTransactionIsolation(defaultTransactionIsolation);
}
if (validationQueryTimeout != null) {
ds.setValidationQueryTimeout(validationQueryTimeout);
}
if (timeBetweenLogStatsMillis != null) {
ds.setTimeBetweenLogStatsMillis(timeBetweenLogStatsMillis);
}
if (keepAlive != null) {
ds.setKeepAlive(keepAlive);
}
boolean hasSetConnectionProperties = false;
if (StrKit.notBlank(filters)) {
try {
ds.setFilters(filters);
// 支持加解密数据库
if (filters.contains("config")) {
// 判断是否设定了公钥
if (StrKit.isBlank(this.publicKey)) {
throw new RuntimeException("Druid连接池的filter设定了config时,必须设定publicKey");
}
String decryptStr = "config.decrypt=true;config.decrypt.key=" + this.publicKey;
String cp = this.connectionProperties;
if (StrKit.isBlank(cp)) {
cp = decryptStr;
} else {
cp = cp + ";" + decryptStr;
}
ds.setConnectionProperties(cp);
hasSetConnectionProperties = true;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
// 确保setConnectionProperties被调用过一次
if (!hasSetConnectionProperties && StrKit.notBlank(this.connectionProperties)) {
ds.setConnectionProperties(this.connectionProperties);
}
addFilterList(ds);
isStarted = true;
return true;
}
use of com.alibaba.druid.pool.DruidDataSource in project Mybatis-PageHelper by pagehelper.
the class DataSourceNegotiationAutoDialectTest method getDriud.
private DruidDataSource getDriud() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(DRUID);
dataSource.setUsername("root");
dataSource.setPassword("password");
return dataSource;
}
Aggregations