Search in sources :

Example 1 with SqlExecutionResult

use of info.xiancloud.dao.core.model.sqlresult.SqlExecutionResult 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)

Aggregations

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 XianConnection (info.xiancloud.dao.core.connection.XianConnection)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 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1