use of info.xiancloud.dao.core.units.DaoUnit 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();
}
}
}
Aggregations