This base class provides the following workflow handling:
Subclasses have to implement specific template methods for specific states of a transaction, e.g.: begin, suspend, resume, commit, rollback. The most important of them are abstract and must be provided by a concrete implementation; for the rest, defaults are provided, so overriding is optional.
Transaction synchronization is a generic mechanism for registering callbacks that get invoked at transaction completion time. This is mainly used internally by the data access support classes for R2DBC, MongoDB, etc. The same mechanism can also be leveraged for custom synchronization needs in an application.
The state of this class is serializable, to allow for serializing the
transaction strategy along with proxies that carry a transaction interceptor.
It is up to subclasses if they wish to make their state to be serializable too.
They should implement the java.io.Serializable marker interface in
that case, and potentially a private readObject() method (according
to Java serialization rules) if they need to restore any transient state.
TransactionSynchronizationManager
| Modifier and Type | Class and Description |
|---|---|
| private static enum | AbstractReactiveTransactionManager.ErrorPredicates
Predicates for exception types that transactional error handling applies to. |
| protected static class | AbstractReactiveTransactionManager.SuspendedResourcesHolder
Holder for suspended resources. |
| Modifier and Type | Field and Description |
|---|---|
| protected transient Log | |
| private Collection |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private Mono | cleanupAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Clean up after completion, clearing synchronization if necessary, and invoking doCleanupAfterCompletion. |
| public final Mono | commit(ReactiveTransaction
object returned by the transaction)getTransaction methodImplements org. |
| protected abstract Mono | doBegin(TransactionSynchronizationManager
the synchronization manager bound to the new transaction synchronizationManager, Object the transaction object returned by transaction, TransactionDefinition doGetTransactiona TransactionDefinition instance, describing propagation
behavior, isolation level, read-only flag, timeout, and transaction name definition)Begin a new transaction with semantics according to the given transaction definition. |
| protected Mono | doCleanupAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction)doGetTransactionCleanup resources after transaction completion. |
| protected abstract Mono | doCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Perform an actual commit of the given transaction. |
| protected abstract Object | Returns: the current transaction objectthe synchronization manager bound to the current transaction synchronizationManager)Return a transaction object for the current transaction state. |
| protected Mono | doResume(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction, Object doGetTransactionthe object that holds suspended resources,
as returned by doSuspend suspendedResources)Resume the resources of the current transaction. |
| private Mono | doResumeSynchronization(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, List<TransactionSynchronization> a List of TransactionSynchronization objects suspendedSynchronizations)Reactivate transaction synchronization for the current transaction context and resume all given synchronizations. |
| protected abstract Mono | doRollback(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Perform an actual rollback of the given transaction. |
| private Mono | doRollbackOnCommitException(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status, Throwable the thrown application exception or error ex)Invoke |
| protected Mono | doSetRollbackOnly(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Set the given transaction rollback-only. |
| protected Mono | Returns: an object that holds suspended resources (will be kept unexamined for passing it into doResume)the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction)doGetTransactionSuspend the resources of the current transaction. |
| private Mono | Returns: the List of suspended TransactionSynchronization objectsthe synchronization manager bound to the current transaction synchronizationManager)Suspend all current synchronizations and deactivate transaction synchronization for the current transaction context. |
| public final Mono | getReactiveTransaction(TransactionDefinition
the TransactionDefinition instance,
describing propagation behavior, isolation level, timeout etc. definition)Implements org. |
| public final Collection | getTransactionExecutionListeners()
Implements org. |
| private Mono | handleExistingTransaction(TransactionSynchronizationManager synchronizationManager, TransactionDefinition definition, Object transaction, boolean debugEnabled)
Create a ReactiveTransaction for an existing transaction. |
| private Mono | invokeAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, List<TransactionSynchronization> a List of TransactionSynchronization objects synchronizations, int the completion status according to the
constants in the TransactionSynchronization interface completionStatus)Actually invoke the |
| protected boolean | Returns: if there is an existing transactionthe transaction object returned by doGetTransaction transaction)Check if the given transaction object indicates an existing transaction (that is, a transaction which has already started). |
| private GenericReactiveTransaction | newReactiveTransaction(TransactionSynchronizationManager synchronizationManager, TransactionDefinition definition, Object transaction, boolean newTransaction, boolean nested, boolean debug, Object suspendedResources)
Create a ReactiveTransaction instance for the given arguments. |
| protected Mono | prepareForCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Make preparations for commit, to be performed before the
|
| private GenericReactiveTransaction | prepareReactiveTransaction(TransactionSynchronizationManager synchronizationManager, TransactionDefinition definition, Object transaction, boolean newTransaction, boolean debug, Object suspendedResources)
Create a new ReactiveTransaction for the given arguments, also initializing transaction synchronization as appropriate. |
| private void | prepareSynchronization(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status, TransactionDefinition definition)
Initialize transaction synchronization as appropriate. |
| private Mono | processCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Process an actual commit. |
| private Mono | processRollback(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Process an actual rollback. |
| private void | |
| protected Mono | registerAfterCompletionWithExistingTransaction(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction, List<TransactionSynchronization> doGetTransactiona List of TransactionSynchronization objects synchronizations)Register the given list of transaction synchronizations with the existing transaction. |
| private Mono | resume(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the current transaction object transaction, AbstractReactiveTransactionManager.the object that holds suspended resources,
as returned by resourcesHoldersuspend (or null to just
resume synchronizations, if any)Resume the given transaction. |
| private Mono | resumeAfterBeginException(TransactionSynchronizationManager synchronizationManager, Object transaction, AbstractReactiveTransactionManager.
Resume outer transaction after inner transaction begin failed. |
| public final Mono | rollback(ReactiveTransaction
object returned by the transaction)getTransaction methodImplements org. |
| public final void | setTransactionExecutionListeners(Collection<TransactionExecutionListener> listeners)
Implements org. |
| private Mono | Returns: an object that holds suspended resources (ornull if neither transaction nor synchronization active)the synchronization manager bound to the current transaction synchronizationManager, Object the current transaction object
(or transaction)null to just suspend active synchronizations, if any)Suspend the given transaction. |
| private Mono | triggerAfterCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Trigger |
| private Mono | triggerAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status, int completion status according to TransactionSynchronization constants completionStatus)Trigger |
| private Mono | triggerBeforeCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Trigger |
| private Mono | triggerBeforeCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction object representing the transaction status)Trigger |