Class TransactionAwareConnectionFactoryProxy
- All Implemented Interfaces:
- ConnectionFactory, Wrapped<ConnectionFactory>
ConnectionFactory, adding awareness
of Spring-managed transactions.
Data access code that should remain unaware of Spring's data access
support can work with this proxy to seamlessly participate in
Spring-managed transactions.
Note that the transaction manager, for example R2dbcTransactionManager,
still needs to work with the underlying ConnectionFactory,
not with this proxy.
Make sure that TransactionAwareConnectionFactoryProxy is the outermost
ConnectionFactory of a chain of ConnectionFactory proxies/adapters.
TransactionAwareConnectionFactoryProxy can delegate either directly to the
target connection pool or to some intermediary proxy/adapter.
Delegates to ConnectionFactoryUtils for automatically participating
in thread-bound transactions, for example managed by R2dbcTransactionManager.
create() calls and close calls on returned Connection
will behave properly within a transaction, i.e. always operate on the
transactional Connection. If not within a transaction, normal ConnectionFactory
behavior applies.
 This proxy allows data access code to work with the plain R2DBC API. However,
if possible, use Spring's ConnectionFactoryUtils or DatabaseClient
to get transaction participation even without a proxy for the target
ConnectionFactory, avoiding the need to define such a proxy in the first place.
NOTE: This ConnectionFactory proxy needs to return wrapped
Connections in order to handle close calls properly.
Use Wrapped.unwrap() to retrieve the native R2DBC Connection.
- Since:
- 5.3
- Author:
- Mark Paluch, Christoph Strobl
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionTransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory) Create a newTransactionAwareConnectionFactoryProxy.
- 
Method SummaryModifier and TypeMethodDescriptionreactor.core.publisher.Mono<Connection> create()Delegates toConnectionFactoryUtilsfor automatically participating in Spring-managed transactions.protected reactor.core.publisher.Mono<Connection> getTransactionAwareConnectionProxy(ConnectionFactory targetConnectionFactory) Wraps the givenConnectionwith a proxy that delegates every method call to it but delegatesclose()calls toConnectionFactoryUtils.Methods inherited from class DelegatingConnectionFactorygetMetadata, getTargetConnectionFactory, unwrap
- 
Constructor Details- 
TransactionAwareConnectionFactoryProxyCreate a newTransactionAwareConnectionFactoryProxy.- Parameters:
- targetConnectionFactory- the target- ConnectionFactory
 
 
- 
- 
Method Details- 
createDelegates toConnectionFactoryUtilsfor automatically participating in Spring-managed transactions.- Specified by:
- createin interface- ConnectionFactory
- Overrides:
- createin class- DelegatingConnectionFactory
- Returns:
- a transactional Connectionif any, a new one else.
- See Also:
 
- 
getTransactionAwareConnectionProxyprotected reactor.core.publisher.Mono<Connection> getTransactionAwareConnectionProxy(ConnectionFactory targetConnectionFactory) Wraps the givenConnectionwith a proxy that delegates every method call to it but delegatesclose()calls toConnectionFactoryUtils.- Parameters:
- targetConnectionFactory- the- ConnectionFactorythat the- Connectioncame from
- Returns:
- the wrapped Connection.
- See Also:
 
 
-