Search in sources :

Example 1 with XianConnection

use of info.xiancloud.dao.core.connection.XianConnection in project xian by happyyangyuan.

the class AbstractSqlAction method execute.

@Override
public final Single<UnitResponse> execute(Unit daoUnit, Map<String, Object> map, XianConnection connection, String msgId) {
    // /Not needed anymore until/unless we have make all sql execution on xian thread pool managed thread pool
    // set msgId in order make sure compatibility of synchronous and asynchronous dao.
    boolean msgIdWritten = MsgIdHolder.set(msgId);
    try {
        this.msgId = msgId;
        this.map = map;
        this.connection = connection;
        this.daoUnit = (DaoUnit) daoUnit;
        sqlDriver = getSqlDriver();
        if (ignore()) {
            return Single.just(UnitResponse.createSuccess(String.format("This sql action '%s.%s' is ignored for execution.", this.daoUnit.getName(), getClass().getSimpleName())));
        } else {
            UnitResponse response = check();
            if (!response.succeeded()) {
                return Single.just(response);
            }
        }
        if (XianConfig.getBoolean(CONFIG_LOG_DETAILED_SQL, true)) {
            logSql(map);
        }
        final long before = System.nanoTime();
        return executeSql().flatMap(sqlExecutionResult -> Single.just(UnitResponse.createSuccess(sqlExecutionResult))).doOnSuccess(unitResponse -> after(before)).onErrorReturn(error -> {
            LOG.error(error);
            return getSqlDriver().handleException(error, this);
        });
    } finally {
        if (msgIdWritten) {
            MsgIdHolder.clear();
        }
    }
}
Also used : XianConnection(info.xiancloud.dao.core.connection.XianConnection) MapFormat(info.xiancloud.dao.core.utils.MapFormat) DaoUnit(info.xiancloud.dao.core.units.DaoUnit) Unit(info.xiancloud.core.Unit) Collection(java.util.Collection) UnitResponse(info.xiancloud.core.message.UnitResponse) Single(io.reactivex.Single) ArrayUtil(info.xiancloud.core.util.ArrayUtil) BaseSqlDriver(info.xiancloud.dao.core.sql.BaseSqlDriver) Matcher(java.util.regex.Matcher) SqlUtils(info.xiancloud.dao.core.utils.SqlUtils) SqlExecutionResult(info.xiancloud.dao.core.model.sqlresult.SqlExecutionResult) XianSqlDriver(info.xiancloud.dao.core.sql.XianSqlDriver) Map(java.util.Map) MsgIdHolder(info.xiancloud.core.util.thread.MsgIdHolder) JSONObject(com.alibaba.fastjson.JSONObject) XianConfig(info.xiancloud.core.conf.XianConfig) LOG(info.xiancloud.core.util.LOG) Pattern(java.util.regex.Pattern) JdbcPatternUtil(info.xiancloud.dao.core.utils.JdbcPatternUtil) UnitResponse(info.xiancloud.core.message.UnitResponse)

Example 2 with XianConnection

use of info.xiancloud.dao.core.connection.XianConnection in project xian by happyyangyuan.

the class DaoUnit method logSql.

/**
 * 打印sql语句,它不会将sql执行,只是打印sql语句。
 * 仅供内部测试使用
 *
 * @param daoUnitClass unit class
 * @param map          parameter map
 */
public static void logSql(Class daoUnitClass, Map<String, Object> map) {
    XianConnection connection = PoolFactory.getPool().getMasterDatasource().getConnection().blockingGet();
    DaoUnit daoUnit;
    try {
        daoUnit = (DaoUnit) daoUnitClass.newInstance();
        for (SqlAction action : daoUnit.getActions()) {
            ((AbstractSqlAction) action).setConnection(connection);
            ((AbstractSqlAction) action).setMap(map);
            action.logSql(map);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }
    PoolFactory.getPool().destroyPoolIfNot();
}
Also used : AbstractSqlAction(info.xiancloud.dao.core.action.AbstractSqlAction) XianConnection(info.xiancloud.dao.core.connection.XianConnection) AbstractSqlAction(info.xiancloud.dao.core.action.AbstractSqlAction) SqlAction(info.xiancloud.dao.core.action.SqlAction)

Aggregations

XianConnection (info.xiancloud.dao.core.connection.XianConnection)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Unit (info.xiancloud.core.Unit)1 XianConfig (info.xiancloud.core.conf.XianConfig)1 UnitResponse (info.xiancloud.core.message.UnitResponse)1 ArrayUtil (info.xiancloud.core.util.ArrayUtil)1 LOG (info.xiancloud.core.util.LOG)1 MsgIdHolder (info.xiancloud.core.util.thread.MsgIdHolder)1 AbstractSqlAction (info.xiancloud.dao.core.action.AbstractSqlAction)1 SqlAction (info.xiancloud.dao.core.action.SqlAction)1 SqlExecutionResult (info.xiancloud.dao.core.model.sqlresult.SqlExecutionResult)1 BaseSqlDriver (info.xiancloud.dao.core.sql.BaseSqlDriver)1 XianSqlDriver (info.xiancloud.dao.core.sql.XianSqlDriver)1 DaoUnit (info.xiancloud.dao.core.units.DaoUnit)1 JdbcPatternUtil (info.xiancloud.dao.core.utils.JdbcPatternUtil)1 MapFormat (info.xiancloud.dao.core.utils.MapFormat)1 SqlUtils (info.xiancloud.dao.core.utils.SqlUtils)1 Single (io.reactivex.Single)1 Collection (java.util.Collection)1 Map (java.util.Map)1