Interface TransactionManager
- All Known Implementing Classes:
EntityManagerTransactionManager,NoTransactionManager,SpringTransactionManager
- Since:
- 2.0.0
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidattachToProcessingLifecycle(ProcessingLifecycle processingLifecycle) default voidexecuteInTransaction(Runnable task) Executes the giventaskin a newTransaction.default <T> TfetchInTransaction(Supplier<T> supplier) Invokes the givensupplierin a transaction managed by the current TransactionManager.default booleanIndicates whether the tasks contained with the managed transactions must occur on the same thread.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
-
attachToProcessingLifecycle
Attaches aTransactionto the givenprocessingLifecyclein thepre-invocation phase.The attached
Transactionwill from therecommitin thecommit phaseandrollbackon error.The transaction is concluded (committed or rolled back) exactly once. This guards against a sibling handler registered in the same commit phase, or a handler in a later phase, failing after this transaction has already committed -- which would otherwise also invoke the error handler and roll back an already-committed transaction.
- Parameters:
processingLifecycle- theProcessingLifecycleto attach aTransactionto
-
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
-
requiresSameThreadInvocations
default boolean requiresSameThreadInvocations()Indicates whether the tasks contained with the managed transactions must occur on the same thread.By default, this method returns
false, meaning there are no thread affinity requirements for the transactions. Implementations can override this method if there is a specific need for tasks to be invoked on the same thread.- Returns:
trueif the handler invocations must occur on the same thread;falseotherwise
-