use of io.syndesis.common.util.TransactedEventBus in project syndesis by syndesisio.
the class SqlJsonDB method withGlobalTransaction.
@Override
public void withGlobalTransaction(final Consumer<JsonDB> handler) {
final String checkpoint = UUID.randomUUID().toString();
try (Handle handle = dbi.open()) {
handle.begin();
handle.checkpoint(checkpoint);
try (Connection connection = handle.getConnection();
Connection transacted = withoutTransactionControl(connection)) {
final TransactedEventBus transactedBus = new TransactedEventBus(bus);
final SqlJsonDB checkpointed = new SqlJsonDB(new DBI(() -> transacted), transactedBus);
boolean committed = false;
try {
handler.accept(checkpointed);
handle.commit();
committed = true;
transactedBus.commit();
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final RuntimeException e) {
if (!committed) {
// if event bus blows up we can't rollback as the transaction has already been committed
handle.rollback(checkpoint);
}
throw SyndesisServerException.launderThrowable(e);
}
} catch (SQLException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
}
Aggregations