use of com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet in project dal by ctripcorp.
the class ConnectionAction method initLogEntry.
public void initLogEntry(String logicDbName, DalHints hints) {
this.entry = logger.createLogEntry();
DatabaseSet databaseSet = DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName);
if (databaseSet instanceof ClusterDatabaseSet) {
Cluster cluster = ((ClusterDatabaseSet) databaseSet).getCluster();
entry.setCluster(cluster);
entry.setClusterName(cluster.getClusterName().toLowerCase());
LocalizationConfig localizationConfig = cluster.getLocalizationConfig();
if (localizationConfig != null)
entry.setDbZone(localizationConfig.getZoneId());
}
entry.setLogicDbName(logicDbName);
entry.setDbCategory(DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName).getDatabaseCategory());
entry.setClientVersion(Version.getVersion());
entry.setClientZone(envUtils.getZone());
entry.setSensitive(hints.is(DalHintEnum.sensitive));
entry.setEvent(operation);
entry.setShardingCategory(shardingCategory);
wrapSql();
entry.setCallString(callString);
if (sqls != null)
entry.setSqls(sqls);
else
entry.setSqls(sql);
if (null != parametersList) {
String[] params = new String[parametersList.length];
for (int i = 0; i < parametersList.length; i++) {
params[i] = parametersList[i].toLogString();
}
entry.setPramemters(params);
} else if (parameters != null) {
entry.setPramemters(parameters.toLogString());
hints.setParameters(parameters);
}
}
use of com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet in project dal by ctripcorp.
the class DalTransaction method validate.
public void validate(String desiganateLogicDbName, String desiganateShard) throws SQLException {
if (desiganateLogicDbName == null || desiganateLogicDbName.length() == 0)
throw new DalException(ErrorCode.LogicDbEmpty);
if (!desiganateLogicDbName.equals(this.logicDbName))
throw new DalException(ErrorCode.TransactionDistributed, this.logicDbName, desiganateLogicDbName);
String curShard = connHolder.getShardId();
if (curShard == null)
return;
if (desiganateShard == null)
return;
try {
DalConfigure dalConfigure = DalClientFactory.getDalConfigure();
DatabaseSet databaseSet = dalConfigure.getDatabaseSet(desiganateLogicDbName);
if (databaseSet instanceof ClusterDatabaseSet && Integer.valueOf(curShard).equals(Integer.valueOf(desiganateShard)))
return;
} catch (Exception e) {
// needn't handle
}
if (!curShard.equals(desiganateShard))
throw new DalException(ErrorCode.TransactionDistributedShard, curShard, desiganateShard);
}
Aggregations