Use this interface to do transaction demarcation and related operations. This should be used instead of using the JTA UserTransaction and TransactionManager interfaces. When you do transaction demarcation yourself use something like:
boolean beganTransaction = transactionFacade.begin(timeout);
try {
...
} catch (Throwable t) {
transactionFacade.rollback(beganTransaction, "...", t);
throw t;
} finally {
if (transactionFacade.isTransactionInPlace()) transactionFacade.commit(beganTransaction);
}
This code will use a transaction if one is already in place (including setRollbackOnly instead of rollbackon
error), or begin a new one if not.
When you want to suspend the current transaction and create a new one use something like:
boolean suspendedTransaction = false;
try {
if (transactionFacade.isTransactionInPlace()) suspendedTransaction = transactionFacade.suspend();
boolean beganTransaction = transactionFacade.begin(timeout);
try {
...
} catch (Throwable t) {
transactionFacade.rollback(beganTransaction, "...", t);
throw t;
} finally {
if (transactionFacade.isTransactionInPlace()) transactionFacade.commit(beganTransaction);
}
} catch (TransactionException e) {
...
} finally {
if (suspendedTransaction) transactionFacade.resume();
}
| Type | Name and description |
|---|---|
boolean |
begin(java.lang.Integer timeout)Begins a transaction in the current thread. |
void |
commit(boolean beganTransaction)Commits the transaction in the current thread if beganTransaction is true |
void |
commit()Commits the transaction in the current thread |
java.sql.Connection |
enlistConnection(javax.sql.XAConnection con) |
void |
enlistResource(javax.transaction.xa.XAResource resource) |
void |
flushAndDisableTransactionCache() |
javax.transaction.Synchronization |
getActiveSynchronization(java.lang.String syncName) |
javax.transaction.xa.XAResource |
getActiveXaResource(java.lang.String resourceName) |
int |
getStatus()Get the status of the current transaction |
java.lang.String |
getStatusString() |
javax.transaction.TransactionManager |
getTransactionManager() |
javax.transaction.UserTransaction |
getUserTransaction() |
void |
initTransactionCache() |
boolean |
isTransactionCacheActive() |
boolean |
isTransactionInPlace() |
void |
putAndEnlistActiveSynchronization(java.lang.String syncName, javax.transaction.Synchronization sync) |
void |
putAndEnlistActiveXaResource(java.lang.String resourceName, javax.transaction.xa.XAResource xar) |
void |
registerSynchronization(javax.transaction.Synchronization sync) |
void |
resume() |
void |
rollback(boolean beganTransaction, java.lang.String causeMessage, java.lang.Throwable causeThrowable)Rollback current transaction if beganTransaction is true, otherwise setRollbackOnly is called to mark current transaction as rollback only. |
void |
rollback(java.lang.String causeMessage, java.lang.Throwable causeThrowable)Rollback current transaction |
java.lang.Object |
runRequireNew(java.lang.Integer timeout, java.lang.String rollbackMessage, groovy.lang.Closure closure)Run in a separate transaction, even if one is in place. |
java.lang.Object |
runUseOrBegin(java.lang.Integer timeout, java.lang.String rollbackMessage, groovy.lang.Closure closure)Run in current transaction if one is in place, begin and commit/rollback if none is. |
void |
setRollbackOnly(java.lang.String causeMessage, java.lang.Throwable causeThrowable)Mark current transaction as rollback-only (transaction can only be rolled back) |
boolean |
suspend() |
Begins a transaction in the current thread. Only tries if the current transaction status is not ACTIVE, if ACTIVE it returns false since no transaction was begun.
timeout - Optional Integer for the timeout. If null the default configured will be used.Commits the transaction in the current thread if beganTransaction is true
Commits the transaction in the current thread
Get the status of the current transaction
Rollback current transaction if beganTransaction is true, otherwise setRollbackOnly is called to mark current transaction as rollback only.
Rollback current transaction
Run in a separate transaction, even if one is in place.
Run in current transaction if one is in place, begin and commit/rollback if none is.
Mark current transaction as rollback-only (transaction can only be rolled back)