Search in sources :

Example 1 with DalConnectionString

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

the class PropertyFileConnectionStringProvider method getConnectionStrings.

@Override
public Map<String, DalConnectionString> getConnectionStrings(Set<String> names) throws Exception {
    if (names == null || names.isEmpty())
        return null;
    Map<String, DalConnectionString> map = new HashMap<>();
    for (String name : names) {
        StringBuilder sb = new StringBuilder();
        sb.append(properties.getProperty(name + USER_NAME));
        sb.append(COMMA);
        sb.append(properties.getProperty(name + PASSWORD));
        sb.append(COMMA);
        sb.append(properties.getProperty(name + CONNECTION_URL));
        sb.append(COMMA);
        sb.append(properties.getProperty(name + DRIVER_CLASS_NAME));
        DalConnectionString connectionString = new ConnectionString(name, sb.toString(), sb.toString());
        map.put(name, connectionString);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DalConnectionString(com.ctrip.platform.dal.dao.configure.DalConnectionString) ConnectionString(com.ctrip.platform.dal.dao.configure.ConnectionString) DalConnectionString(com.ctrip.platform.dal.dao.configure.DalConnectionString) ConnectionString(com.ctrip.platform.dal.dao.configure.ConnectionString) DalConnectionString(com.ctrip.platform.dal.dao.configure.DalConnectionString)

Example 2 with DalConnectionString

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

the class PropertyFileConnectionStringProviderTest method testPropertyFileConnectionStringProvider.

@Test
public void testPropertyFileConnectionStringProvider() throws Exception {
    PropertyFileConnectionStringProvider provider = new PropertyFileConnectionStringProvider();
    Set<String> names = new HashSet<>();
    names.add(NAME);
    Map<String, DalConnectionString> map = provider.getConnectionStrings(names);
    DalConnectionString connectionString = map.get(NAME);
    String cs = connectionString.getIPConnectionString();
    String[] array = cs.split(COMMA);
    Assert.assertEquals(array[0], "testUser");
    Assert.assertEquals(array[1], "testPassword");
    Assert.assertEquals(array[2], "jdbc:mysql://testIP:3306/testDb");
    Assert.assertEquals(array[3], "com.mysql.jdbc.Driver");
}
Also used : DalConnectionString(com.ctrip.platform.dal.dao.configure.DalConnectionString) DalConnectionString(com.ctrip.platform.dal.dao.configure.DalConnectionString) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DalConnectionString (com.ctrip.platform.dal.dao.configure.DalConnectionString)2 ConnectionString (com.ctrip.platform.dal.dao.configure.ConnectionString)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1