cn.hutool.db.ds.pooled.PooledDSFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.db.ds.pooled;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.ds.AbstractDSFactory;
import cn.hutool.setting.Setting;
import javax.sql.DataSource;
/**
* Hutool自身实现的池化数据源工厂类
*
* @author Looly
*
*/
public class PooledDSFactory extends AbstractDSFactory {
private static final long serialVersionUID = 8093886210895248277L;
public static final String DS_NAME = "Hutool-Pooled-DataSource";
public PooledDSFactory() {
this(null);
}
public PooledDSFactory(Setting setting) {
super(DS_NAME, PooledDataSource.class, setting);
}
@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
final DbConfig dbConfig = new DbConfig();
dbConfig.setUrl(jdbcUrl);
dbConfig.setDriver(driver);
dbConfig.setUser(user);
dbConfig.setPass(pass);
// 连接池相关信息
dbConfig.setInitialSize(poolSetting.getInt("initialSize", 0));
dbConfig.setMinIdle(poolSetting.getInt("minIdle", 0));
dbConfig.setMaxActive(poolSetting.getInt("maxActive", 8));
dbConfig.setMaxWait(poolSetting.getLong("maxWait", 6000L));
// remarks等特殊配置,since 5.3.8
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.get(key);
if(StrUtil.isNotBlank(connValue)){
dbConfig.addConnProps(key, connValue);
}
}
return new PooledDataSource(dbConfig);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy