add params

This commit is contained in:
Looly 2022-03-26 00:52:34 +08:00
parent 38c450f6db
commit 75f4ca356d
2 changed files with 25 additions and 4 deletions

View File

@ -44,6 +44,7 @@
* 【poi 】 ExcelReader增加构造pr#2213@Github
* 【core 】 MapUtil提供change函数EnumUtil提供getBy函数通过lambda进行枚举字段映射pr#583@Gitee
* 【core 】 CompareUtil增加comparingIndexedpr#585@Gitee
* 【db 】 DruidDataSource构建时支持自定义参数issue#I4ZKCW@Gitee
### 🐞Bug修复
* 【core 】 修复ObjectUtil.hasNull传入null返回true的问题pr#555@Gitee

View File

@ -10,13 +10,13 @@ import javax.sql.DataSource;
/**
* Druid数据源工厂类
*
*
* @author Looly
*
*/
public class DruidDSFactory extends AbstractDSFactory {
private static final long serialVersionUID = 4680621702534433222L;
public static final String DS_NAME = "Druid";
/**
@ -28,7 +28,7 @@ public class DruidDSFactory extends AbstractDSFactory {
/**
* 构造
*
*
* @param setting 数据库配置
*/
public DruidDSFactory(Setting setting) {
@ -46,6 +46,7 @@ public class DruidDSFactory extends AbstractDSFactory {
ds.setPassword(pass);
// remarks等特殊配置since 5.3.8
// Druid中也可以通过 druid.connectProperties 属性设置
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.getAndRemoveStr(key);
@ -59,7 +60,26 @@ public class DruidDSFactory extends AbstractDSFactory {
poolSetting.forEach((key, value)-> druidProps.put(StrUtil.addPrefixIfNot(key, "druid."), value));
ds.configFromPropety(druidProps);
// 检查关联配置在用户未设置某项配置时
//issue#I4ZKCW 某些非属性设置单独设置
String[] specialKeys = {"druid.connectionErrorRetryAttempts", "druid.breakAfterAcquireFailure"};
// connectionErrorRetryAttempts
final String connectionErrorRetryAttemptsKey = "druid.connectionErrorRetryAttempts";
if(druidProps.containsKey(connectionErrorRetryAttemptsKey)){
ds.setConnectionErrorRetryAttempts(druidProps.getInt(connectionErrorRetryAttemptsKey));
}
// timeBetweenConnectErrorMillis
final String timeBetweenConnectErrorMillisKey = "druid.timeBetweenConnectErrorMillis";
if(druidProps.containsKey(timeBetweenConnectErrorMillisKey)){
ds.setTimeBetweenConnectErrorMillis(druidProps.getInt(timeBetweenConnectErrorMillisKey));
}
// breakAfterAcquireFailure
final String breakAfterAcquireFailureKey = "druid.breakAfterAcquireFailure";
if(druidProps.containsKey(breakAfterAcquireFailureKey)){
ds.setBreakAfterAcquireFailure(druidProps.getBool(breakAfterAcquireFailureKey));
}
// 检查关联配置在用户未设置某项配置时设置默认值
if (null == ds.getValidationQuery()) {
// 在validationQuery未设置的情况下以下三项设置都将无效
ds.setTestOnBorrow(false);