Search in sources :

Example 1 with SqlException

use of com.bedatadriven.rebar.sql.client.SqlException in project activityinfo by bedatadriven.

the class LocalDispatcher method executeOffline.

/**
 * Begins a new transaction, initializes a new ExecutionContext, and
 * executes the root command.
 *
 * @param command
 * @param callback
 */
private <R extends CommandResult> void executeOffline(final Command<R> command, final AsyncCallback<R> callback) {
    Log.debug("Executing command " + command + " OFFLINE.");
    try {
        final Collector<R> commandResult = Collector.newCollector();
        database.transaction(new SqlTransactionCallback() {

            @Override
            public void begin(SqlTransaction tx) {
                LocalExecutionContext context = new LocalExecutionContext(auth, tx, registry, commandQueue);
                context.execute(command, commandResult);
            }

            @Override
            public void onError(SqlException e) {
                Log.error("OFFLINE EXECUTION FAILED: " + command, e);
                callback.onFailure(e);
            }

            @Override
            public void onSuccess() {
                callback.onSuccess(commandResult.getResult());
            }
        });
    } catch (Exception e) {
        callback.onFailure(e);
    }
}
Also used : SqlTransactionCallback(com.bedatadriven.rebar.sql.client.SqlTransactionCallback) SqlException(com.bedatadriven.rebar.sql.client.SqlException) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlException(com.bedatadriven.rebar.sql.client.SqlException)

Aggregations

SqlException (com.bedatadriven.rebar.sql.client.SqlException)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1