Top Description Inners Fields Constructors Methods
org.springframework.transaction.reactive

public abstract Class AbstractReactiveTransactionManager

extends Object
implements ReactiveTransactionManager, ConfigurableTransactionManager, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.transaction.ConfigurableTransactionManager, org.springframework.transaction.TransactionManager, org.springframework.transaction.ReactiveTransactionManager
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .ObjectInputStream, .Serializable, java.util.ArrayList, .Collection, .List, .Optional, java.util.concurrent.atomic.AtomicBoolean, java.util.function.Predicate, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Flux, .Mono, org.springframework.lang.Nullable, org.springframework.transaction.ConfigurableTransactionManager, .IllegalTransactionStateException, .InvalidTimeoutException, .ReactiveTransaction, .ReactiveTransactionManager, .TransactionDefinition, .TransactionException, .TransactionExecutionListener, .TransactionSuspensionNotSupportedException, .UnexpectedRollbackException

Abstract base class that implements Spring's standard reactive transaction workflow, serving as basis for concrete platform transaction managers.

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.

Authors
Mark Paluch, Juergen Hoeller
Since
5.2
See Also
TransactionSynchronizationManager

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
AbstractReactiveTransactionManager.ErrorPredicates

Predicates for exception types that transactional error handling applies to.

protected static class

Field Summary

Modifier and TypeField and Description
protected transient Log
private Collection<TransactionExecutionListener>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private Mono<Void>
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<Void>
commit(ReactiveTransaction
object returned by the getTransaction method
transaction
)

Implements org.springframework.transaction.ReactiveTransactionManager.commit.

This implementation of commit handles participating in existing transactions and programmatic rollback requests.
protected abstract Mono<Void>
doBegin(TransactionSynchronizationManager
the synchronization manager bound to the new transaction
synchronizationManager
,
Object
the transaction object returned by doGetTransaction
transaction
,
TransactionDefinition
a 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<Void>
doCleanupAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the transaction object returned by doGetTransaction
transaction
)

Cleanup resources after transaction completion.

protected abstract Mono<Void>
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 object
doGetTransaction
(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
)

Return a transaction object for the current transaction state.

protected Mono<Void>
doResume(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the transaction object returned by doGetTransaction
transaction
,
Object
the object that holds suspended resources, as returned by doSuspend
suspendedResources
)

Resume the resources of the current transaction.

private Mono<Void>
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<Void>
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<Void>
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 doRollback, handling rollback exceptions properly.

protected Mono<Void>
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<Object>

Returns:

an object that holds suspended resources (will be kept unexamined for passing it into doResume)
doSuspend
(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the transaction object returned by doGetTransaction
transaction
)

Suspend the resources of the current transaction.

private Mono<List<TransactionSynchronization>>

Returns:

the List of suspended TransactionSynchronization objects
doSuspendSynchronization
(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
)

Suspend all current synchronizations and deactivate transaction synchronization for the current transaction context.

public final Mono<ReactiveTransaction>
getReactiveTransaction(TransactionDefinition
the TransactionDefinition instance, describing propagation behavior, isolation level, timeout etc.
definition
)

Implements org.springframework.transaction.ReactiveTransactionManager.getReactiveTransaction.

This implementation handles propagation behavior.
public final Collection<TransactionExecutionListener>
getTransactionExecutionListeners()

Implements org.springframework.transaction.ConfigurableTransactionManager.getTransactionExecutionListeners.

Return the registered transaction execution listeners for this transaction manager.
private Mono<ReactiveTransaction>
handleExistingTransaction(TransactionSynchronizationManager synchronizationManager, TransactionDefinition definition, Object transaction, boolean debugEnabled)

Create a ReactiveTransaction for an existing transaction.

private Mono<Void>
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 afterCompletion methods of the given TransactionSynchronization objects.

protected boolean

Returns:

if there is an existing transaction
isExistingTransaction
(Object
the 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<Void>
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 beforeCommit synchronization callbacks occur.

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<Void>
processCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
GenericReactiveTransaction
object representing the transaction
status
)

Process an actual commit.

private Mono<Void>
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<Void>
registerAfterCompletionWithExistingTransaction(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the transaction object returned by doGetTransaction
transaction
,
List<TransactionSynchronization>
a List of TransactionSynchronization objects
synchronizations
)

Register the given list of transaction synchronizations with the existing transaction.

private Mono<Void>
resume(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the current transaction object
transaction
,
AbstractReactiveTransactionManager.SuspendedResourcesHolder
the object that holds suspended resources, as returned by suspend (or null to just resume synchronizations, if any)
resourcesHolder
)

Resume the given transaction.

private Mono<Void>
resumeAfterBeginException(TransactionSynchronizationManager synchronizationManager, Object transaction, AbstractReactiveTransactionManager.SuspendedResourcesHolder suspendedResources, Throwable beginEx)

Resume outer transaction after inner transaction begin failed.

public final Mono<Void>
rollback(ReactiveTransaction
object returned by the getTransaction method
transaction
)

Implements org.springframework.transaction.ReactiveTransactionManager.rollback.

This implementation of rollback handles participating in existing transactions.
public final void
setTransactionExecutionListeners(Collection<TransactionExecutionListener> listeners)

Implements org.springframework.transaction.ConfigurableTransactionManager.setTransactionExecutionListeners.

Set the transaction execution listeners for begin/commit/rollback callbacks from this transaction manager.
private Mono<AbstractReactiveTransactionManager.SuspendedResourcesHolder>

Returns:

an object that holds suspended resources (or null if neither transaction nor synchronization active)
suspend
(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
Object
the current transaction object (or null to just suspend active synchronizations, if any)
transaction
)

Suspend the given transaction.

private Mono<Void>
triggerAfterCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
GenericReactiveTransaction
object representing the transaction
status
)

Trigger afterCommit callbacks.

private Mono<Void>
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 afterCompletion callbacks.

private Mono<Void>
triggerBeforeCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
GenericReactiveTransaction
object representing the transaction
status
)

Trigger beforeCommit callbacks.

private Mono<Void>
triggerBeforeCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction
synchronizationManager
,
GenericReactiveTransaction
object representing the transaction
status
)

Trigger beforeCompletion callbacks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait