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);
}
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;
}
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;
}
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;
}
}
}
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);
}
Aggregations