Class SpringTransactionManager
java.lang.Object
org.axonframework.extension.spring.messaging.unitofwork.SpringTransactionManager
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionSpringTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) Constructs a new instance.SpringTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager, EntityManagerProvider entityManagerProvider, ConnectionProvider connectionProvider) Initializes the SpringTransactionManager with the giventransactionManagerand the default transaction definition.SpringTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager, EntityManagerProvider entityManagerProvider, ConnectionProvider connectionProvider, org.springframework.transaction.TransactionDefinition transactionDefinition) Constructs a new instance.SpringTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager, org.springframework.transaction.TransactionDefinition transactionDefinition) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidattachToProcessingLifecycle(ProcessingLifecycle processingLifecycle) protected voidcommitTransaction(org.springframework.transaction.TransactionStatus status) Commits the transaction with givenstatusif the transaction is new and not completed.booleanIndicates whether the tasks contained with the managed transactions must occur on the same thread.protected voidrollbackTransaction(org.springframework.transaction.TransactionStatus status) Rolls back the transaction with givenstatusif the transaction is new and not completed.Starts a transaction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.unitofwork.transaction.TransactionManager
executeInTransaction, fetchInTransaction
-
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 giventransactionManagerand 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
Description copied from interface:TransactionManagerAttaches aTransactionto the givenprocessingLifecyclein thepre-invocation phase.The attached
Transactionwill from therecommitin thecommit phaseandrollbackon error.- Specified by:
attachToProcessingLifecyclein interfaceTransactionManager- Parameters:
processingLifecycle- theProcessingLifecycleto attach aTransactionto
-
startTransaction
Description copied from interface:TransactionManagerStarts a transaction.The return value is the started transaction that can be committed or rolled back.
- Specified by:
startTransactionin interfaceTransactionManager- Returns:
- the object representing the transaction
-
requiresSameThreadInvocations
public boolean requiresSameThreadInvocations()Description copied from interface:TransactionManagerIndicates 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:
requiresSameThreadInvocationsin interfaceTransactionManager- Returns:
trueif the handler invocations must occur on the same thread;falseotherwise
-
commitTransaction
protected void commitTransaction(org.springframework.transaction.TransactionStatus status) Commits the transaction with givenstatusif 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 givenstatusif the transaction is new and not completed.- Parameters:
status- The status of the transaction to roll back
-