public class TransactionHelper extends Object
Modifier and Type | Method and Description |
---|---|
static void |
checkTransactionTimeout()
Checks if the current User Transaction has already timed out, i.e., whether a commit would immediately abort with
a timeout exception.
|
static void |
commitOrRollbackTransaction()
Commits or rolls back the User Transaction depending on the transaction status.
|
protected static List<Exception> |
getSuppressedExceptions()
Gets the suppressed exceptions, and stops remembering.
|
static int |
getTransactionStatus()
Gets the transaction status.
|
static String |
getUserTransactionJNDIName()
Returns the UserTransaction JNDI binding name.
|
static boolean |
isNoTransaction()
Checks if there is no transaction
|
static boolean |
isTransactionActive()
Checks if the current User Transaction is active.
|
static boolean |
isTransactionActiveOrMarkedRollback()
Checks if the current User Transaction is active or marked rollback only.
|
static boolean |
isTransactionActiveOrPreparing()
Checks if the current User Transaction is active or preparing.
|
static boolean |
isTransactionMarkedRollback()
Checks if the current User Transaction is marked rollback only.
|
static boolean |
isTransactionTimedOut()
Checks if the current User Transaction has already timed out, i.e., whether a commit would immediately abort with
a timeout exception.
|
static TransactionSynchronizationRegistry |
lookupSynchronizationRegistry()
Looks up the TransactionSynchronizationRegistry in JNDI.
|
static TransactionManager |
lookupTransactionManager()
Looks up the TransactionManager in JNDI.
|
static UserTransaction |
lookupUserTransaction()
Looks up the User Transaction in JNDI.
|
static void |
noteSuppressedException(Exception e)
Remembers the exception if it happens during the processing of a commit, so that it can be surfaced as a
suppressed exception at the end of the commit.
|
protected static void |
noteSuppressedExceptions()
After this, some exceptions during transaction commit may be suppressed and remembered.
|
static void |
registerSynchronization(Synchronization handler) |
static Transaction |
requireNewTransaction()
Suspend the current transaction if active and start a new transaction
|
static void |
resumeTransaction(Transaction tx)
Commit the current transaction if active and resume the principal transaction
|
static void |
runInNewTransaction(Runnable runnable)
Runs the given
Runnable in a new transactional context. |
static <R> R |
runInNewTransaction(Supplier<R> supplier)
Calls the given
Supplier in a new transactional context. |
static void |
runInTransaction(Runnable runnable)
Runs the given
Runnable in a transactional context. |
static <R> R |
runInTransaction(Supplier<R> supplier)
Calls the given
Supplier in a transactional context. |
static void |
runWithoutTransaction(Runnable runnable)
Runs the given
Runnable without a transactional context. |
static <R> R |
runWithoutTransaction(Supplier<R> supplier)
Calls the given
Supplier without a transactional context. |
static boolean |
setTransactionRollbackOnly()
Sets the current User Transaction as rollback only.
|
static boolean |
setTransactionRollbackOnlyIfTimedOut()
Sets the current User Transaction as rollback only if it has timed out.
|
static boolean |
startTransaction()
Starts a new User Transaction.
|
static boolean |
startTransaction(int timeout)
Starts a new User Transaction with the specified timeout.
|
static Transaction |
suspendTransaction() |
public static UserTransaction lookupUserTransaction() throws NamingException
NamingException
- if not foundpublic static int getTransactionStatus()
public static String getUserTransactionJNDIName()
Assumes lookupUserTransaction()
has been called once before.
public static TransactionManager lookupTransactionManager() throws NamingException
NamingException
- if not foundpublic static TransactionSynchronizationRegistry lookupSynchronizationRegistry() throws NamingException
NamingException
- if not foundpublic static boolean isNoTransaction()
public static boolean isTransactionActive()
public static boolean isTransactionMarkedRollback()
public static boolean isTransactionActiveOrMarkedRollback()
public static boolean isTransactionActiveOrPreparing()
public static boolean isTransactionTimedOut()
true
if there is a current transaction that has timed out, false
otherwisepublic static void checkTransactionTimeout() throws TransactionRuntimeException
Throws if the transaction has timed out.
TransactionRuntimeException
- if the transaction has timed outpublic static boolean startTransaction()
true
if the transaction was successfully started, false
otherwisepublic static Transaction requireNewTransaction()
TransactionRuntimeException
public static Transaction suspendTransaction()
public static void resumeTransaction(Transaction tx)
tx
- public static boolean startTransaction(int timeout)
timeout
- the timeout in seconds, <= 0 for the defaulttrue
if the transaction was successfully started, false
otherwisepublic static void commitOrRollbackTransaction()
protected static void noteSuppressedExceptions()
public static void noteSuppressedException(Exception e)
protected static List<Exception> getSuppressedExceptions()
public static boolean setTransactionRollbackOnly()
true
if the transaction was successfully marked rollback only, false
otherwisepublic static boolean setTransactionRollbackOnlyIfTimedOut()
true
if the transaction was successfully marked rollback only, false
otherwisepublic static void registerSynchronization(Synchronization handler)
public static void runWithoutTransaction(Runnable runnable)
Runnable
without a transactional context. Will suspend and restore the transaction if one already
exists.runnable
- the Runnable
public static <R> R runWithoutTransaction(Supplier<R> supplier)
Supplier
without a transactional context. Will suspend and restore the transaction if one already
exists.supplier
- the Supplier
public static void runInNewTransaction(Runnable runnable)
Runnable
in a new transactional context. Will suspend and restore the transaction if one already
exists.runnable
- the Runnable
public static <R> R runInNewTransaction(Supplier<R> supplier)
Supplier
in a new transactional context. Will suspend and restore the transaction if one already
exists.supplier
- the Supplier
public static void runInTransaction(Runnable runnable)
Runnable
in a transactional context. Will not start a new transaction if one already
exists.runnable
- the Runnable
public static <R> R runInTransaction(Supplier<R> supplier)
Supplier
in a transactional context. Will not start a new transaction if one already
exists.supplier
- the Supplier
Copyright © 2018 Nuxeo. All rights reserved.