Class SpringTransactionManager

java.lang.Object
org.axonframework.extension.spring.messaging.unitofwork.SpringTransactionManager
All Implemented Interfaces:
TransactionManager

public class SpringTransactionManager extends Object implements TransactionManager
TransactionManager implementation that uses a PlatformTransactionManager as underlying transaction manager. This implementation provides a ConnectionExecutor and/or EntityManagerExecutor when attached to a processing lifecycle, if available.
Since:
2.0
Author:
Allard Buijze
  • Constructor Details

    • SpringTransactionManager

      public SpringTransactionManager(@Nonnull org.springframework.transaction.PlatformTransactionManager transactionManager, @Nullable EntityManagerProvider entityManagerProvider, @Nullable ConnectionProvider connectionProvider, @Nullable org.springframework.transaction.TransactionDefinition transactionDefinition)
      Constructs a new instance.
      Parameters:
      transactionManager - The transaction manager to use.
      entityManagerProvider - The optional entity manager provider to use.
      connectionProvider - The optional connection provider to use.
      transactionDefinition - The optional definition for transactions to create.
    • SpringTransactionManager

      public SpringTransactionManager(@Nonnull org.springframework.transaction.PlatformTransactionManager transactionManager, @Nullable org.springframework.transaction.TransactionDefinition transactionDefinition)
      Constructs a new instance.
      Parameters:
      transactionManager - The transaction manager to use.
      transactionDefinition - The optional definition for transactions to create.
    • SpringTransactionManager

      public SpringTransactionManager(@Nonnull org.springframework.transaction.PlatformTransactionManager transactionManager, @Nullable EntityManagerProvider entityManagerProvider, @Nullable ConnectionProvider connectionProvider)
      Initializes the SpringTransactionManager with the given transactionManager and the default transaction definition.
      Parameters:
      transactionManager - the transaction manager to use.
      entityManagerProvider - The optional entity manager provider to use.
      connectionProvider - The optional connection provider to use.
    • SpringTransactionManager

      public SpringTransactionManager(@Nonnull org.springframework.transaction.PlatformTransactionManager transactionManager)
      Constructs a new instance.
      Parameters:
      transactionManager - The transaction manager to use.
  • Method Details

    • attachToProcessingLifecycle

      public void attachToProcessingLifecycle(@Nonnull ProcessingLifecycle processingLifecycle)
      Description copied from interface: TransactionManager
      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.

      Specified by:
      attachToProcessingLifecycle in interface TransactionManager
      Parameters:
      processingLifecycle - the ProcessingLifecycle to attach a Transaction to
    • startTransaction

      @Nonnull public Transaction startTransaction()
      Description copied from interface: TransactionManager
      Starts a transaction.

      The return value is the started transaction that can be committed or rolled back.

      Specified by:
      startTransaction in interface TransactionManager
      Returns:
      the object representing the transaction
    • requiresSameThreadInvocations

      public boolean requiresSameThreadInvocations()
      Description copied from interface: TransactionManager
      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.

      Specified by:
      requiresSameThreadInvocations in interface TransactionManager
      Returns:
      true if the handler invocations must occur on the same thread; false otherwise
    • commitTransaction

      protected void commitTransaction(org.springframework.transaction.TransactionStatus status)
      Commits the transaction with given status if the transaction is new and not completed.
      Parameters:
      status - The status of the transaction to commit
    • rollbackTransaction

      protected void rollbackTransaction(org.springframework.transaction.TransactionStatus status)
      Rolls back the transaction with given status if the transaction is new and not completed.
      Parameters:
      status - The status of the transaction to roll back