use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.
the class DataSourceUtil method getDataSource.
public static DataSource getDataSource(String allInOneName) throws SQLException {
if (isEmpty(allInOneName)) {
throw new SQLException("the param allInOneName is null. So can not get DataSourse.");
}
DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
DalGroupDB db = allDbDao.getGroupDBByDbName(allInOneName);
if (db == null) {
throw new SQLException(allInOneName + " is not exist in the table of alldbs.");
}
String address = db.getDb_address();
String port = db.getDb_port();
String userName = db.getDb_user();
String password = db.getDb_password();
String driverClass = db.getDb_providerName();
String catalog = db.getDb_catalog();
validateParam(allInOneName, address, port, catalog, userName, password, driverClass);
String key = address.trim() + catalog.trim() + port.trim() + userName.trim() + password.trim();
DataSource ds = cache2.get(key);
if (ds != null) {
return ds;
}
synchronized (DataSourceUtil.class) {
ds = cache2.get(key);
if (ds != null) {
return ds;
} else {
DataSource newDS = createDataSource(address.trim(), port.trim(), catalog.trim(), userName.trim(), password.trim(), driverClass.trim());
cache2.put(key, newDS);
return newDS;
}
}
}
Aggregations