use of cn.hutool.setting.dialect.Props in project hutool by looly.
the class DruidDSFactory method createDataSource.
@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
final DruidDataSource ds = new DruidDataSource();
// 基本信息
ds.setUrl(jdbcUrl);
ds.setDriverClassName(driver);
ds.setUsername(user);
ds.setPassword(pass);
// remarks等特殊配置,since 5.3.8
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.getAndRemoveStr(key);
if (StrUtil.isNotBlank(connValue)) {
ds.addConnectionProperty(key, connValue);
}
}
// Druid连接池配置信息,规范化属性名
final Props druidProps = new Props();
poolSetting.forEach((key, value) -> druidProps.put(StrUtil.addPrefixIfNot(key, "druid."), value));
ds.configFromPropety(druidProps);
// 检查关联配置,在用户未设置某项配置时,
if (null == ds.getValidationQuery()) {
// 在validationQuery未设置的情况下,以下三项设置都将无效
ds.setTestOnBorrow(false);
ds.setTestOnReturn(false);
ds.setTestWhileIdle(false);
}
return ds;
}
use of cn.hutool.setting.dialect.Props in project hutool by looly.
the class HikariDSFactory method createDataSource.
@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
// remarks等特殊配置,since 5.3.8
final Props connProps = new Props();
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.getAndRemoveStr(key);
if (StrUtil.isNotBlank(connValue)) {
connProps.setProperty(key, connValue);
}
}
final Props config = new Props();
config.putAll(poolSetting);
config.put("jdbcUrl", jdbcUrl);
if (null != driver) {
config.put("driverClassName", driver);
}
if (null != user) {
config.put("username", user);
}
if (null != pass) {
config.put("password", pass);
}
final HikariConfig hikariConfig = new HikariConfig(config);
hikariConfig.setDataSourceProperties(connProps);
return new HikariDataSource(hikariConfig);
}
use of cn.hutool.setting.dialect.Props in project hutool by looly.
the class TomcatDSFactory method createDataSource.
@Override
protected javax.sql.DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
final PoolProperties poolProps = new PoolProperties();
poolProps.setUrl(jdbcUrl);
poolProps.setDriverClassName(driver);
poolProps.setUsername(user);
poolProps.setPassword(pass);
// remarks等特殊配置,since 5.3.8
final Props connProps = new Props();
String connValue;
for (String key : KEY_CONN_PROPS) {
connValue = poolSetting.getAndRemoveStr(key);
if (StrUtil.isNotBlank(connValue)) {
connProps.setProperty(key, connValue);
}
}
poolProps.setDbProperties(connProps);
// 连接池相关参数
poolSetting.toBean(poolProps);
return new DataSource(poolProps);
}
use of cn.hutool.setting.dialect.Props in project hutool by looly.
the class SimpleDataSource method getConnection.
// -------------------------------------------------------------------- Getters and Setters end
@Override
public Connection getConnection() throws SQLException {
final Props info = new Props();
if (this.user != null) {
info.setProperty("user", this.user);
}
if (this.pass != null) {
info.setProperty("password", this.pass);
}
// 其它参数
final Properties connProps = this.connProps;
if (MapUtil.isNotEmpty(connProps)) {
info.putAll(connProps);
}
return DriverManager.getConnection(this.url, info);
}
use of cn.hutool.setting.dialect.Props in project hutool by looly.
the class PropsTest method propTestForAbsPAth.
@Test
@Ignore
public void propTestForAbsPAth() {
// noinspection MismatchedQueryAndUpdateOfCollection
Props props = new Props("d:/test.properties");
String user = props.getProperty("user");
Assert.assertEquals(user, "root");
String driver = props.getStr("driver");
Assert.assertEquals(driver, "com.mysql.jdbc.Driver");
}
Aggregations