use of com.bedatadriven.rebar.sql.client.SqlTransactionCallback in project activityinfo by bedatadriven.
the class CommandQueueTest method testUpdateSite.
@Test
public void testUpdateSite() {
Map<String, Object> changes = new HashMap<String, Object>();
changes.put("anInt", 34);
changes.put("aString", "testing");
final UpdateSite cmd = new UpdateSite(99, changes);
db.transaction(new SqlTransactionCallback() {
@Override
public void begin(SqlTransaction tx) {
queue.queue(tx, cmd);
}
});
Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
queue.peek(reread);
assertThat(reread.getResult(), not(nullValue()));
assertThat(cmd, equalTo(reread.getResult().getCommand()));
}
use of com.bedatadriven.rebar.sql.client.SqlTransactionCallback in project activityinfo by bedatadriven.
the class CommandQueueTest method testCreateSite.
@Test
public void testCreateSite() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("anInt", 34);
properties.put("aString", "testing");
properties.put("aDouble", 3.0);
properties.put("aBoolean", true);
properties.put("anotherBoolean", false);
properties.put("aTime", new Date());
properties.put("aDate", new LocalDate(2011, 3, 15));
final CreateSite cmd = new CreateSite(properties);
db.transaction(new SqlTransactionCallback() {
@Override
public void begin(SqlTransaction tx) {
queue.queue(tx, cmd);
}
});
Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
queue.peek(reread);
assertThat(reread.getResult(), not(nullValue()));
assertThat(cmd, equalTo(reread.getResult().getCommand()));
Collector<Void> deleted = Collector.newCollector();
queue.remove(reread.getResult(), deleted);
Collector<CommandQueue.QueueEntry> entry2 = Collector.newCollector();
queue.peek(entry2);
assertThat(entry2.getResult(), is(nullValue()));
}
use of com.bedatadriven.rebar.sql.client.SqlTransactionCallback 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);
}
}
Aggregations