@java.lang.SuppressWarnings("unused") public interface TransactionFacade
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 Params | Return Type | Name and description |
---|---|---|
|
public boolean |
begin(java.lang.Integer timeout) Begins a transaction in the current thread. |
|
public void |
commit(boolean beganTransaction) Commits the transaction in the current thread if beganTransaction is true |
|
public void |
commit() Commits the transaction in the current thread |
|
public java.sql.Connection |
enlistConnection(javax.sql.XAConnection con) |
|
public void |
enlistResource(javax.transaction.xa.XAResource resource) |
|
public void |
flushAndDisableTransactionCache() |
|
public javax.transaction.Synchronization |
getActiveSynchronization(java.lang.String syncName) |
|
public javax.transaction.xa.XAResource |
getActiveXaResource(java.lang.String resourceName) |
|
public int |
getStatus() Get the status of the current transaction |
|
public java.lang.String |
getStatusString() |
|
public javax.transaction.TransactionManager |
getTransactionManager() |
|
public javax.transaction.UserTransaction |
getUserTransaction() |
|
public void |
initTransactionCache(boolean readOnly) |
|
public boolean |
isTransactionCacheActive() |
|
public boolean |
isTransactionInPlace() |
|
public void |
putAndEnlistActiveSynchronization(java.lang.String syncName, javax.transaction.Synchronization sync) |
|
public void |
putAndEnlistActiveXaResource(java.lang.String resourceName, javax.transaction.xa.XAResource xar) |
|
public void |
registerSynchronization(javax.transaction.Synchronization sync) |
|
public void |
resume() |
|
public 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. |
|
public void |
rollback(java.lang.String causeMessage, java.lang.Throwable causeThrowable) Rollback current transaction |
|
public 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. |
|
public 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. |
|
public void |
setRollbackOnly(java.lang.String causeMessage, java.lang.Throwable causeThrowable) Mark current transaction as rollback-only (transaction can only be rolled back) |
|
public 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)