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();
}
}
}
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();
}
Aggregations