TransactionAwareConnectionFactoryProxy
instead.@Deprecated public class TransactionAwareConnectionFactoryProxy extends DelegatingConnectionFactory
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 (which implement the
ConnectionProxy
interface) in order to handle close calls properly. Use Wrapped.unwrap()
to retrieve
the native R2DBC Connection.
ConnectionFactory.create()
,
Connection.close()
,
ConnectionFactoryUtils.doGetConnection(io.r2dbc.spi.ConnectionFactory)
,
ConnectionFactoryUtils.doReleaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)
Constructor and Description |
---|
TransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory)
Deprecated.
Create a new
TransactionAwareConnectionFactoryProxy . |
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Mono<Connection> |
create()
Deprecated.
Delegates to
ConnectionFactoryUtils for automatically participating in Spring-managed transactions. |
protected reactor.core.publisher.Mono<Connection> |
getTransactionAwareConnectionProxy(ConnectionFactory targetConnectionFactory)
Deprecated.
Wraps the given
Connection with a proxy that delegates every method call to it but delegates
close() calls to ConnectionFactoryUtils . |
getMetadata, getTargetConnectionFactory, obtainTargetConnectionFactory, unwrap
public TransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory)
TransactionAwareConnectionFactoryProxy
.targetConnectionFactory
- the target ConnectionFactory
.IllegalArgumentException
- if given ConnectionFactory
is null.public reactor.core.publisher.Mono<Connection> create()
ConnectionFactoryUtils
for automatically participating in Spring-managed transactions.
The returned ConnectionFactory
handle implements the ConnectionProxy
interface, allowing to
retrieve the underlying target Connection
.
create
in interface ConnectionFactory
create
in class DelegatingConnectionFactory
Connection
if any, a new one else.ConnectionFactoryUtils.doGetConnection(io.r2dbc.spi.ConnectionFactory)
,
ConnectionProxy.getTargetConnection()
protected reactor.core.publisher.Mono<Connection> getTransactionAwareConnectionProxy(ConnectionFactory targetConnectionFactory)
Connection
with a proxy that delegates every method call to it but delegates
close()
calls to ConnectionFactoryUtils
.targetConnectionFactory
- the ConnectionFactory
that the Connection
came from.Connection
.Connection.close()
,
ConnectionFactoryUtils.doReleaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)
Copyright © 2018–2022 Pivotal Software, Inc.. All rights reserved.