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
Connection
s 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 Summary
ConstructorDescriptionTransactionAwareConnectionFactoryProxy
(ConnectionFactory targetConnectionFactory) Create a newTransactionAwareConnectionFactoryProxy
. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Connection>
create()
Delegates toConnectionFactoryUtils
for automatically participating in Spring-managed transactions.protected reactor.core.publisher.Mono<Connection>
getTransactionAwareConnectionProxy
(ConnectionFactory targetConnectionFactory) Wraps the givenConnection
with a proxy that delegates every method call to it but delegatesclose()
calls toConnectionFactoryUtils
.Methods inherited from class org.springframework.r2dbc.connection.DelegatingConnectionFactory
getMetadata, getTargetConnectionFactory, unwrap
-
Constructor Details
-
TransactionAwareConnectionFactoryProxy
Create a newTransactionAwareConnectionFactoryProxy
.- Parameters:
targetConnectionFactory
- the targetConnectionFactory
-
-
Method Details
-
create
Delegates toConnectionFactoryUtils
for automatically participating in Spring-managed transactions.- Specified by:
create
in interfaceConnectionFactory
- Overrides:
create
in classDelegatingConnectionFactory
- Returns:
- a transactional
Connection
if any, a new one else. - See Also:
-
getTransactionAwareConnectionProxy
protected reactor.core.publisher.Mono<Connection> getTransactionAwareConnectionProxy(ConnectionFactory targetConnectionFactory) Wraps the givenConnection
with a proxy that delegates every method call to it but delegatesclose()
calls toConnectionFactoryUtils
.- Parameters:
targetConnectionFactory
- theConnectionFactory
that theConnection
came from- Returns:
- the wrapped
Connection
. - See Also:
-