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 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

      default void executeInTransaction(Runnable task)
      Executes the given task in a new Transaction. The transaction is committed when the task completes normally, and rolled back when it throws an exception.
      Parameters:
      task - The task to execute
    • fetchInTransaction

      default <T> T fetchInTransaction(Supplier<T> supplier)
      Invokes the given supplier in 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