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.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
    • attachToProcessingLifecycle

      default void attachToProcessingLifecycle(@Nonnull ProcessingLifecycle processingLifecycle)
      Attaches a Transaction to the given processingLifecycle in the pre-invocation phase.

      The attached Transaction will from there commit in the commit phase and rollback on error.

      Parameters:
      processingLifecycle - the ProcessingLifecycle to attach a Transaction to
    • 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
    • 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:
      true if the handler invocations must occur on the same thread; false otherwise