Search in sources :

Example 1 with ClusterDatabaseSet

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);
    }
}
Also used : ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet) DatabaseSet(com.ctrip.platform.dal.dao.configure.DatabaseSet) LocalizationConfig(com.ctrip.framework.dal.cluster.client.config.LocalizationConfig) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet)

Example 2 with ClusterDatabaseSet

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);
}
Also used : ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet) DatabaseSet(com.ctrip.platform.dal.dao.configure.DatabaseSet) DalException(com.ctrip.platform.dal.exceptions.DalException) DalConfigure(com.ctrip.platform.dal.dao.configure.DalConfigure) ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet) DalException(com.ctrip.platform.dal.exceptions.DalException) SQLException(java.sql.SQLException) DalTransactionConflictException(com.ctrip.platform.dal.exceptions.DalTransactionConflictException) TransactionSystemException(com.ctrip.platform.dal.exceptions.TransactionSystemException)

Aggregations

ClusterDatabaseSet (com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet)2 DatabaseSet (com.ctrip.platform.dal.dao.configure.DatabaseSet)2 Cluster (com.ctrip.framework.dal.cluster.client.Cluster)1 LocalizationConfig (com.ctrip.framework.dal.cluster.client.config.LocalizationConfig)1 DalConfigure (com.ctrip.platform.dal.dao.configure.DalConfigure)1 DalException (com.ctrip.platform.dal.exceptions.DalException)1 DalTransactionConflictException (com.ctrip.platform.dal.exceptions.DalTransactionConflictException)1 TransactionSystemException (com.ctrip.platform.dal.exceptions.TransactionSystemException)1 SQLException (java.sql.SQLException)1