Class TransactionUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The TransactionUtilException is used to wrap system style exceptions possibly occuring, but normally not of interest to application, when invokingget(UserTransaction, ThrowingSupplier)
orget(UserTransaction, ThrowingSupplier)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V, E extends Exception>
Vget(javax.transaction.UserTransaction ut, ThrowingSupplier<V,E> supplier)
Use this method to execute work in a transaction that returns a result.static <E extends Exception>
voidrun(javax.transaction.UserTransaction ut, ThrowingRunnable<E> runnable)
Use this method to execute work in a transaction that returns no result.static <V> V
Use this method to execute work in a transaction.
-
Constructor Details
-
TransactionUtil
public TransactionUtil()
-
-
Method Details
-
run
public static <V> V run(javax.transaction.UserTransaction ut, Callable<V> callable) throws ExceptionUse this method to execute work in a transaction. This is just a utility that helps implementing for example Transaction Servlet Filters that begin and end transactions at the request boundaries.If there is an ongoing transaction already, this method will not begin a new one. Any exception caught in that case will set that new transaction to rollback.
See also
ThreadUtil.confine(Callable, Class)
on how to handle checked exception cases gracefully. -
get
public static <V, E extends Exception> V get(javax.transaction.UserTransaction ut, ThrowingSupplier<V,E> supplier) throws E, TransactionUtil.TransactionUtilExceptionUse this method to execute work in a transaction that returns a result.If there is an ongoing transaction already, this method will not begin a new one. Any exception caught in that case will set that new transaction to rollback.
This method relies on
ThrowingSupplier
to give the caller control over what exceptions may be propagated.Any other checked exceptions that may be thrown by underlying transaction management methods, such as
SystemException
,NotSupportedException
will be wrapped into aTransactionUtil.TransactionUtilException
.- Parameters:
ut
- theUserTransaction
instance of the transaction management system in placesupplier
- TheThrowingSupplier
implementation that defines the work.- Returns:
- The result of the supplier invocation.
- Throws:
Exception
TransactionUtil.TransactionUtilException
-
run
public static <E extends Exception> void run(javax.transaction.UserTransaction ut, ThrowingRunnable<E> runnable) throws E, TransactionUtil.TransactionUtilExceptionUse this method to execute work in a transaction that returns no result.If there is an ongoing transaction already, this method will not begin a new one. Any exception caught in that case will set that new transaction to rollback.
This method relies on
ThrowingSupplier
to give the caller control over what exceptions may be propagated.Any other checked exceptions that may be thrown by underlying transaction management methods, such as
SystemException
,NotSupportedException
will be wrapped into aTransactionUtil.TransactionUtilException
.- Parameters:
ut
- theUserTransaction
instance of the transaction management system in placerunnable
- TheThrowingSupplier
implementation that defines the work.- Throws:
Exception
TransactionUtil.TransactionUtilException
-