mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix c3p0 bug
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.db.ds.c3p0;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.ds.AbstractDSFactory;
|
||||
@@ -12,13 +13,13 @@ import java.beans.PropertyVetoException;
|
||||
|
||||
/**
|
||||
* Druid数据源工厂类
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class C3p0DSFactory extends AbstractDSFactory {
|
||||
private static final long serialVersionUID = -6090788225842047281L;
|
||||
|
||||
|
||||
public static final String DS_NAME = "C3P0";
|
||||
|
||||
/**
|
||||
@@ -30,24 +31,16 @@ public class C3p0DSFactory extends AbstractDSFactory {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param setting 配置
|
||||
*/
|
||||
public C3p0DSFactory(Setting setting) {
|
||||
super(DS_NAME, ComboPooledDataSource.class, setting);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
|
||||
final ComboPooledDataSource ds = new ComboPooledDataSource();
|
||||
ds.setJdbcUrl(jdbcUrl);
|
||||
try {
|
||||
ds.setDriverClass(driver);
|
||||
} catch (PropertyVetoException e) {
|
||||
throw new DbRuntimeException(e);
|
||||
}
|
||||
ds.setUser(user);
|
||||
ds.setPassword(pass);
|
||||
|
||||
// remarks等特殊配置,since 5.3.8
|
||||
final Props connProps = new Props();
|
||||
@@ -58,7 +51,18 @@ public class C3p0DSFactory extends AbstractDSFactory {
|
||||
connProps.setProperty(key, connValue);
|
||||
}
|
||||
}
|
||||
ds.setProperties(connProps);
|
||||
if(MapUtil.isNotEmpty(connProps)){
|
||||
ds.setProperties(connProps);
|
||||
}
|
||||
|
||||
ds.setJdbcUrl(jdbcUrl);
|
||||
try {
|
||||
ds.setDriverClass(driver);
|
||||
} catch (PropertyVetoException e) {
|
||||
throw new DbRuntimeException(e);
|
||||
}
|
||||
ds.setUser(user);
|
||||
ds.setPassword(pass);
|
||||
|
||||
// 注入属性
|
||||
poolSetting.toBean(ds);
|
||||
|
Reference in New Issue
Block a user