public <T> T executeTransaction(TransactionalTask<T> task) throws TransactionException {
return executeTransaction(TransactionOptions.getDefault(), task);
}
public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException {
final TransactionContext context = newTransactionContext(options);
context.beginTransaction();
try {
final T value = task.execute(context);
context.commitTransaction();
return value;
} catch (Throwable e) {
context.rollbackTransaction();
if (e instanceof TransactionException) {
throw (TransactionException) e;
}
if (e.getCause() instanceof TransactionException) {
throw (TransactionException) e.getCause();