Class R2dbcTransactionManager

java.lang.Object
org.springframework.transaction.reactive.AbstractReactiveTransactionManager
org.springframework.r2dbc.connection.R2dbcTransactionManager
All Implemented Interfaces:
Serializable, InitializingBean, ReactiveTransactionManager, TransactionManager

public class R2dbcTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean
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 may come from a pool (the typical case), but the ConnectionFactory must not return scoped scoped Connections or the like. This transaction manager will associate Connection with context-bound transactions itself, 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 standard R2DBC lookup pattern ConnectionFactory.create(), for example for code that is not aware of Spring at all. 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.

This transaction manager triggers flush callbacks on registered transaction synchronizations (if synchronization is generally active), assuming resources operating on the underlying R2DBC Connection.

Since:
5.3
Author:
Mark Paluch
See Also: