public <T> T execute(GlobalTransactionCallback<T> action) throws TException { final GlobalTransactionService service = GlobalTransactionFactory.getGlobalTransactionService(); final TransactionContext context = TransactionContext.Factory.getCurrentInstance(); boolean success = false; TGlobalTransaction globalTransaction = null; try { globalTransaction = new TGlobalTransaction(); globalTransaction.setCreatedAt(new Date()); globalTransaction.setCreatedBy(0); globalTransaction.setCurrSequence(0); globalTransaction.setStatus(TGlobalTransactionsStatus.New); globalTransaction = service.create(globalTransaction); context.setCurrentTransactionSequence(0); context.setCurrentTransactionId(globalTransaction.getId()); T result = action.doInTransaction(); success = true; return result; } finally { if (globalTransaction.getId() != null) { service.update(globalTransaction.getId(), context.getCurrentTransactionSequence(), success ? TGlobalTransactionsStatus.Success : TGlobalTransactionsStatus.Fail); } } }
public <T> T execute(GlobalTransactionCallback<T> action) throws TException { final GlobalTransactionService service = GlobalTransactionFactory.getGlobalTransactionService(); final TransactionContext context = TransactionContext.Factory.getCurrentInstance(); boolean success = false; TGlobalTransaction globalTransaction = null; try { globalTransaction = new TGlobalTransaction(); globalTransaction.setCreatedAt(new Date()); globalTransaction.setCreatedBy(0); globalTransaction.setCurrSequence(0); globalTransaction.setStatus(TGlobalTransactionsStatus.New); globalTransaction = service.create(globalTransaction); context.setCurrentTransactionSequence(0); context.setCurrentTransactionId(globalTransaction.getId()); T result = action.doInTransaction(); success = true; return result; } finally { if (globalTransaction.getId() != null) { service.update(globalTransaction.getId(), context.getCurrentTransactionSequence(), success ? TGlobalTransactionsStatus.Success : TGlobalTransactionsStatus.Fail); } } }