Search in sources :

Example 6 with DalGroupDBDao

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;
        }
    }
}
Also used : SQLException(java.sql.SQLException) DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao) DataSource(javax.sql.DataSource)

Aggregations

DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)6 Status (com.ctrip.platform.dal.daogen.domain.Status)5 DalGroupDB (com.ctrip.platform.dal.daogen.entity.DalGroupDB)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1