Search in sources :

Example 1 with DataSourceConfigure

use of com.ctrip.platform.dal.dao.configure.DataSourceConfigure in project dal by ctripcorp.

the class DatabasePoolConfigParserTest method test4.

@Test
public void test4() {
    DataSourceConfigure config = DataSourceConfigureLocator.getInstance().getUserDataSourceConfigure("dao_test_select");
    Assert.assertEquals("dao_test_select", config.getName());
    Assert.assertEquals(1000, config.getIntProperty(DataSourceConfigureConstants.MAXWAIT, 0));
    Assert.assertEquals("rewriteBatchedStatements=true;allowMultiQueries=true", config.getProperty(DataSourceConfigureConstants.CONNECTIONPROPERTIES));
}
Also used : DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure) Test(org.junit.Test)

Example 2 with DataSourceConfigure

use of com.ctrip.platform.dal.dao.configure.DataSourceConfigure in project dal by ctripcorp.

the class DatabasePoolConfigParserTest method test1.

@Test
public void test1() {
    DataSourceConfigure config = DataSourceConfigureLocator.getInstance().getUserDataSourceConfigure("dao_test");
    Assert.assertEquals("dao_test", config.getName());
    Assert.assertEquals(10000, config.getIntProperty(DataSourceConfigureConstants.MAXWAIT, 0));
    Assert.assertEquals("sendTimeAsDateTime=false;sendStringParametersAsUnicode=false;rewriteBatchedStatements=true;allowMultiQueries=true;useUnicode=true;characterEncoding=UTF-8", config.getProperty(DataSourceConfigureConstants.OPTION));
}
Also used : DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure) Test(org.junit.Test)

Example 3 with DataSourceConfigure

use of com.ctrip.platform.dal.dao.configure.DataSourceConfigure in project dal by ctripcorp.

the class PropertyFileConnectionStringProvider method getConnectionStrings.

@Override
public Map<String, DataSourceConfigure> getConnectionStrings(Set<String> dbNames) throws Exception {
    if (dbNames == null || dbNames.isEmpty())
        return null;
    Map<String, DataSourceConfigure> map = new HashMap<>();
    for (String name : dbNames) {
        DataSourceConfigure configure = new DataSourceConfigure();
        configure.setUserName(properties.getProperty(name + USER_NAME));
        configure.setPassword(properties.getProperty(name + PASSWORD));
        configure.setConnectionUrl(properties.getProperty(name + CONNECTION_URL));
        configure.setDriverClass(properties.getProperty(name + DRIVER_CLASS_NAME));
        map.put(name, configure);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure)

Example 4 with DataSourceConfigure

use of com.ctrip.platform.dal.dao.configure.DataSourceConfigure in project dal by ctripcorp.

the class DataSourceLocator method createDataSource.

private DataSource createDataSource(String name) throws SQLException {
    DataSourceConfigure config = provider.getDataSourceConfigure(name);
    if (config == null) {
        throw new SQLException("Can not find connection configure for " + name);
    }
    RefreshableDataSource rds = new RefreshableDataSource(name, config);
    provider.register(name, rds);
    return rds;
}
Also used : SQLException(java.sql.SQLException) DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure)

Example 5 with DataSourceConfigure

use of com.ctrip.platform.dal.dao.configure.DataSourceConfigure in project dal by ctripcorp.

the class DatabasePoolConfigParserTest method test3.

@Test
public void test3() {
    DataSourceConfigure config = DataSourceConfigureLocator.getInstance().getUserDataSourceConfigure("dal_test_new");
    Assert.assertEquals("dal_test_new", config.getName());
    Assert.assertEquals(10000, config.getIntProperty(DataSourceConfigureConstants.MAXWAIT, 0));
    Assert.assertEquals("sendTimeAsDateTime=false", config.getProperty(DataSourceConfigureConstants.OPTION));
    // Test default settings,now default value is zero
    Assert.assertEquals(0, config.getIntProperty(DataSourceConfigureConstants.MAX_AGE, 0));
}
Also used : DataSourceConfigure(com.ctrip.platform.dal.dao.configure.DataSourceConfigure) Test(org.junit.Test)

Aggregations

DataSourceConfigure (com.ctrip.platform.dal.dao.configure.DataSourceConfigure)8 Test (org.junit.Test)5 PropertyFileConnectionStringProvider (com.ctrip.platform.dal.dao.configure.file.PropertyFileConnectionStringProvider)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1