org.springframework.transaction.ReactiveTransactionManager implementation
for a single R2DBC ConnectionFactory. This class is capable of working
in any environment with any R2DBC driver, as long as the setup uses a
ConnectionFactory as its Connection factory mechanism.
Binds a R2DBC Connection from the specified ConnectionFactory
to the current subscriber context, potentially allowing for one context-bound
Connection per ConnectionFactory.
Note: The ConnectionFactory that this transaction manager operates
on needs to return independent Connections. The Connections
typically come from a connection pool but the ConnectionFactory must not
return specifically scoped or constrained Connections. This transaction
manager will associate Connection with context-bound transactions,
according to the specified propagation behavior. It assumes that a separate,
independent Connection can be obtained even during an ongoing transaction.
Application code is required to retrieve the R2DBC Connection via
ConnectionFactoryUtils#getConnection(ConnectionFactory)
instead of a standard R2DBC-style ConnectionFactory#create() call.
Spring classes such as DatabaseClient use this strategy implicitly.
If not used in combination with this transaction manager, the
ConnectionFactoryUtils lookup strategy behaves exactly like the native
ConnectionFactory lookup; it can thus be used in a portable fashion.
Alternatively, you can allow application code to work with the lookup pattern
ConnectionFactory#create(), for example for code not aware of Spring.
In that case, define a TransactionAwareConnectionFactoryProxy for your
target ConnectionFactory, and pass that proxy ConnectionFactory
to your DAOs which will automatically participate in Spring-managed transactions
when accessing it.
Spring's TransactionDefinition attributes are carried forward to
R2DBC drivers using extensible R2DBC io..
Subclasses may override createTransactionDefinition(TransactionDefinition)
to customize transaction definitions for vendor-specific attributes. As of 6.0.10,
this transaction manager supports nested transactions via R2DBC savepoints as well.
ConnectionFactoryUtils#getConnection(ConnectionFactory), ConnectionFactoryUtils#releaseConnection, TransactionAwareConnectionFactoryProxy
| Modifier and Type | Class and Description |
|---|---|
| private static class | R2dbcTransactionManager.
ConnectionFactory transaction object, representing a ConnectionHolder. |
| private static record | R2dbcTransactionManager.
Extended R2DBC transaction definition object providing transaction attributes to R2DBC drivers when starting a transaction. |
| Modifier and Type | Field and Description |
|---|---|
| private ConnectionFactory | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | R2dbcTransactionManager(ConnectionFactory
the R2DBC ConnectionFactory to manage transactions for connectionFactory)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected TransactionDefinition | Returns: the actual transaction definition to usethe transaction definition definition)Determine the transaction definition from our |
| protected Duration | Returns: the actual timeout to usethe transaction definition definition)Determine the actual timeout to use for the given definition. |
| protected 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)Implements abstract org. |
| private Mono | doBegin(Connection con, R2dbcTransactionManager.
|
| protected Mono | doCleanupAfterCompletion(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction)doGetTransactionOverrides org. |
| protected Mono | doCommit(TransactionSynchronizationManager
the synchronization manager bound to the current transaction TransactionSynchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Implements abstract org. |
| protected Object | doGetTransaction(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager)Implements abstract org. |
| 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)Overrides org. |
| protected Mono | doRollback(TransactionSynchronizationManager
the synchronization manager bound to the current transaction TransactionSynchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Implements abstract org. |
| protected Mono | doSetRollbackOnly(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, GenericReactiveTransaction the status representation of the transaction status)Overrides org. |
| protected Mono | doSuspend(TransactionSynchronizationManager
the synchronization manager bound to the current transaction synchronizationManager, Object the transaction object returned by transaction)doGetTransactionOverrides org. |
| public ConnectionFactory | getConnectionFactory()
Return the R2DBC |
| public boolean | isEnforceReadOnly()
Return whether to enforce the read-only nature of a transaction through an explicit statement on the transactional connection. |
| protected boolean | isExistingTransaction(Object
the transaction object returned by doGetTransaction transaction)Overrides org. |
| protected ConnectionFactory | Returns: theConnectionFactory (never null)Obtain the |
| protected Mono | prepareTransactionalConnection(Connection
the transactional R2DBC Connection con, TransactionDefinition the current transaction definition definition)Prepare the transactional |
| protected IsolationLevel | Returns: the resolved isolation level. Can benull if not resolvable or the isolation level
should remain default.the isolation level to translate. isolationLevel)Resolve the isolation level constant to a R2DBC
|
| public void | setConnectionFactory(ConnectionFactory connectionFactory)
Set the R2DBC |
| public void | setEnforceReadOnly(boolean enforceReadOnly)
Specify whether to enforce the read-only nature of a transaction (as indicated by
|
| protected RuntimeException | Returns: the translated exception to emitthe task description (commit or rollback). task, R2dbcException the SQLException thrown from commit/rollback. ex)Translate the given R2DBC commit/rollback exception to a common Spring exception to propagate
from the |