Search in sources :

Example 1 with DalGroupDB

use of com.ctrip.platform.dal.daogen.entity.DalGroupDB in project dal by ctripcorp.

the class DalGroupDBDao method deleteDalGroupDB.

public int deleteDalGroupDB(int id) throws SQLException {
    DalGroupDB groupDb = new DalGroupDB();
    groupDb.setId(id);
    DalHints hints = DalHints.createIfAbsent(null);
    return client.delete(hints, groupDb);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB)

Example 2 with DalGroupDB

use of com.ctrip.platform.dal.daogen.entity.DalGroupDB in project dal by ctripcorp.

the class DalConfigHost method getDatabaseSetEntryMap.

public Map<String, DatabaseSetEntry> getDatabaseSetEntryMap() throws SQLException {
    Map<String, DatabaseSetEntry> map = null;
    if (databaseSetEntryMap != null && databaseSetEntryMap.size() > 0) {
        map = new HashMap<>();
        Set<String> set = new HashSet<>();
        for (Map.Entry<Integer, DatabaseSetEntry> entry : databaseSetEntryMap.entrySet()) {
            set.add(entry.getValue().getConnectionString());
        }
        List<DalGroupDB> dbs = BeanGetter.getDaoOfDalGroupDB().getGroupDbsByDbNames(set);
        if (dbs != null && dbs.size() > 0) {
            for (DalGroupDB db : dbs) {
                DatabaseSetEntry e = new DatabaseSetEntry();
                e.setConnectionString(db.getDbname());
                e.setProviderName(db.getDb_providerName());
                e.setDbAddress(db.getDb_address());
                e.setDbPort(db.getDb_port());
                e.setUserName(db.getDb_user());
                e.setPassword(db.getDb_password());
                e.setDbCatalog(db.getDb_catalog());
                map.put(e.getConnectionString(), e);
            }
        }
    }
    return map;
}
Also used : DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 3 with DalGroupDB

use of com.ctrip.platform.dal.daogen.entity.DalGroupDB in project dal by ctripcorp.

the class AllInOneConfigParser method parseDotNetDBConnString.

private DalGroupDB parseDotNetDBConnString(String connStr) {
    DalGroupDB db = new DalGroupDB();
    try {
        String dbhost = null;
        Matcher matcher = dbnamePattern.matcher(connStr);
        if (matcher.find()) {
            db.setDb_catalog(matcher.group(2));
        }
        matcher = dburlPattern.matcher(connStr);
        if (matcher.find()) {
            String[] dburls = matcher.group(2).split(",");
            dbhost = dburls[0];
            if (dburls.length == 2) {
                db.setDb_address(dbhost);
                db.setDb_port(dburls[1]);
                db.setDb_providerName(DatabaseType.SQLServer.getValue());
            } else {
                matcher = dbportPattern.matcher(connStr);
                if (matcher.find()) {
                    db.setDb_address(dbhost);
                    db.setDb_port(matcher.group(2));
                } else {
                    db.setDb_address(dbhost);
                    db.setDb_port("3306");
                }
                db.setDb_providerName(DatabaseType.MySQL.getValue());
            }
        }
        matcher = dbuserPattern.matcher(connStr);
        if (matcher.find()) {
            db.setDb_user(matcher.group(2));
        }
        matcher = dbpasswdPattern.matcher(connStr);
        if (matcher.find()) {
            db.setDb_password(matcher.group(2));
        }
    } catch (Throwable e) {
        throw e;
    }
    return db;
}
Also used : Matcher(java.util.regex.Matcher) DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB)

Example 4 with DalGroupDB

use of com.ctrip.platform.dal.daogen.entity.DalGroupDB in project dal by ctripcorp.

the class DataSourceUtil method getDataSource.

public static DataSource getDataSource(String allInOneName) throws Exception {
    if (isEmpty(allInOneName))
        throw new SQLException("the param allInOneName is null. So can not get DataSourse.");
    DalGroupDBDao allDbDao = BeanGetter.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)

Example 5 with DalGroupDB

use of com.ctrip.platform.dal.daogen.entity.DalGroupDB in project dal by ctripcorp.

the class DalGroupDBDao method getGroupDBByDbName.

public DalGroupDB getGroupDBByDbName(String dbname) throws SQLException {
    FreeSelectSqlBuilder<DalGroupDB> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, dbname, comment,dal_group_id, db_address, db_port, db_user, db_password, db_catalog, db_providerName FROM alldbs WHERE dbname=?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "dbname", Types.VARCHAR, dbname);
    builder.mapWith(dalGroupDBRowMapper).requireFirst().nullable();
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    return queryDao.query(builder, parameters, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalGroupDB(com.ctrip.platform.dal.daogen.entity.DalGroupDB)

Aggregations

DalGroupDB (com.ctrip.platform.dal.daogen.entity.DalGroupDB)5 DalHints (com.ctrip.platform.dal.dao.DalHints)2 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)1 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)1 DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)1 DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)1 SQLException (java.sql.SQLException)1 Matcher (java.util.regex.Matcher)1 DataSource (javax.sql.DataSource)1