Search in sources :

Example 1 with Props

use of cn.hutool.setting.dialect.Props in project hutool by looly.

the class PropsTest method propTest.

@Test
public void propTest() {
    Props props = new Props("test.properties");
    String user = props.getProperty("user");
    Assert.assertEquals(user, "root");
    String driver = props.getStr("driver");
    Assert.assertEquals(driver, "com.mysql.jdbc.Driver");
}
Also used : Props(cn.hutool.setting.dialect.Props) Test(org.junit.Test)

Example 2 with Props

use of cn.hutool.setting.dialect.Props in project hutool by looly.

the class PropsTest method propTestForAbsPAth.

@Test
@Ignore
public void propTestForAbsPAth() {
    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");
}
Also used : Props(cn.hutool.setting.dialect.Props) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Props

use of cn.hutool.setting.dialect.Props in project hutool by looly.

the class Setting method getProps.

/**
 * 获取group分组下所有配置键值对,组成新的{@link Props}
 *
 * @param group 分组
 * @return Props对象
 * @since 4.1.21
 */
public Props getProps(String group) {
    final Props props = new Props();
    props.putAll(getMap(group));
    return props;
}
Also used : Props(cn.hutool.setting.dialect.Props)

Example 4 with Props

use of cn.hutool.setting.dialect.Props in project hutool by looly.

the class PropsTest method toBeanWithNullPrefixTest.

@Test
public void toBeanWithNullPrefixTest() {
    Props configProp = new Props();
    configProp.setProperty("createTime", Objects.requireNonNull(DateUtil.parse("2020-01-01")));
    configProp.setProperty("isInit", true);
    configProp.setProperty("stairPlan", 1);
    configProp.setProperty("stageNum", 2);
    configProp.setProperty("version", 3);
    SystemConfig systemConfig = configProp.toBean(SystemConfig.class);
    Assert.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime());
    Assert.assertEquals(true, systemConfig.getIsInit());
    Assert.assertEquals("1", systemConfig.getStairPlan());
    Assert.assertEquals(new Integer(2), systemConfig.getStageNum());
    Assert.assertEquals("3", systemConfig.getVersion());
}
Also used : Props(cn.hutool.setting.dialect.Props) Test(org.junit.Test)

Example 5 with Props

use of cn.hutool.setting.dialect.Props in project hutool by looly.

the class C3p0DSFactory method createDataSource.

@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
    final ComboPooledDataSource ds = new ComboPooledDataSource();
    // 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);
        }
    }
    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);
    return ds;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) Props(cn.hutool.setting.dialect.Props) DbRuntimeException(cn.hutool.db.DbRuntimeException)

Aggregations

Props (cn.hutool.setting.dialect.Props)12 Test (org.junit.Test)6 Ignore (org.junit.Ignore)2 DbRuntimeException (cn.hutool.db.DbRuntimeException)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1 Properties (java.util.Properties)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1 PoolProperties (org.apache.tomcat.jdbc.pool.PoolProperties)1