Search in sources :

Example 1 with LogContext

use of com.ctrip.platform.dal.dao.client.LogContext in project dal by ctripcorp.

the class DalRequestExecutor method internalExecute.

private <T> T internalExecute(DalHints hints, DalRequest<T> request, boolean nullable) throws SQLException {
    T result = null;
    Throwable error = null;
    LogContext logContext = logger.start(request);
    try {
        request.validate();
        if (request.isCrossShard())
            result = crossShardExecute(logContext, hints, request);
        else
            result = nonCrossShardExecute(logContext, hints, request);
        if (result == null && !nullable)
            throw new DalException(ErrorCode.AssertNull);
        request.endExecution();
    } catch (Throwable e) {
        error = e;
    }
    logger.end(logContext, error);
    handleCallback(hints, result, error);
    if (error != null)
        throw DalException.wrap(error);
    return result;
}
Also used : DalException(com.ctrip.platform.dal.exceptions.DalException) LogContext(com.ctrip.platform.dal.dao.client.LogContext)

Example 2 with LogContext

use of com.ctrip.platform.dal.dao.client.LogContext in project dal by ctripcorp.

the class DalRequestExecutor method internalExecute.

private <T> T internalExecute(DalHints hints, DalRequest<T> request, boolean nullable, final ShardExecutionCallback<T> callback) throws SQLException {
    T result = null;
    Throwable error = null;
    LogContext logContext = logger.start(request);
    long startTime = System.currentTimeMillis();
    try {
        request.validateAndPrepare();
        if (request.isCrossShard())
            result = crossShardExecute(logContext, hints, request, callback);
        else
            result = nonCrossShardExecute(logContext, hints, request, callback);
        if (result == null && !nullable)
            throw new DalException(ErrorCode.AssertNull);
        request.endExecution();
    } catch (Throwable e) {
        error = e;
    }
    logContext.setDaoExecuteTime(System.currentTimeMillis() - startTime);
    logger.end(logContext, error);
    handleCallback(hints, result, error);
    if (error != null)
        throw DalException.wrap(error);
    return result;
}
Also used : DalException(com.ctrip.platform.dal.exceptions.DalException) LogContext(com.ctrip.platform.dal.dao.client.LogContext)

Aggregations

LogContext (com.ctrip.platform.dal.dao.client.LogContext)2 DalException (com.ctrip.platform.dal.exceptions.DalException)2