Interface TransactionManager
- All Known Implementing Classes:
NoTransactionManager,SpringTransactionManager
public interface TransactionManager
Interface towards a mechanism that manages transactions
Typically, this will involve opening database transactions or connecting to external systems.
- Since:
- 2.0
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidexecuteInTransaction(Runnable task) Executes the giventaskin a newTransaction.default <T> TfetchInTransaction(Supplier<T> supplier) Invokes the givensupplierin a transaction managed by the current TransactionManager.Starts a transaction.
-
Method Details
-
startTransaction
Transaction startTransaction()Starts a transaction. The return value is the started transaction that can be committed or rolled back.- Returns:
- The object representing the transaction
-
executeInTransaction
Executes the giventaskin a newTransaction. The transaction is committed when the task completes normally, and rolled back when it throws an exception.- Parameters:
task- The task to execute
-
fetchInTransaction
Invokes the givensupplierin a transaction managed by the current TransactionManager. Upon completion of the call, the transaction will be committed in the case of a regular return value, or rolled back in case an exception occurred.This method is an alternative to
executeInTransaction(Runnable)in cases where a result needs to be returned from the code to be executed transactionally.- Type Parameters:
T- The type of value to return- Parameters:
supplier- The supplier of the value to return- Returns:
- The value returned by the supplier
-