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.
ConnectionFactory#create, Connection#close, ConnectionFactoryUtils#doGetConnection, ConnectionFactoryUtils#doReleaseConnection
| Modifier and Type | Class and Description |
|---|---|
| private static class | TransactionAwareConnectionFactoryProxy.
Invocation handler that delegates close calls on R2DBC Connections to
|
| Access | Constructor and Description |
|---|---|
| public | TransactionAwareConnectionFactoryProxy(ConnectionFactory
the target targetConnectionFactory)ConnectionFactoryCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| public Mono | Returns: a transactionalConnection if any, a new one else.Overrides org. Implements io. ConnectionFactoryUtils for automatically participating
in Spring-managed transactions.
|
| protected Mono | Returns: the wrappedConnection.the targetConnectionFactory)ConnectionFactory that the Connection came fromWraps the given |
| private static Connection |
| TransactionAwareConnectionFactoryProxy | back to summary |
|---|---|
| public TransactionAwareConnectionFactoryProxy(ConnectionFactory targetConnectionFactory) Create a new
| |
| create | back to summary |
|---|---|
| public Mono Overrides org. Implements io. Delegates to
| |
| getTransactionAwareConnectionProxy | back to summary |
|---|---|
| protected Mono Wraps the given
| |
| proxyConnection | back to summary |
|---|---|
| private static Connection proxyConnection(Connection connection, ConnectionFactory targetConnectionFactory) | |
ConnectionFactoryUtils for being aware of context-bound transactions.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final Connection | |
| private final ConnectionFactory |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. |
| private String |
| closed | back to summary |
|---|---|
| private boolean closed | |
| connection | back to summary |
|---|---|
| private final Connection connection | |
| targetConnectionFactory | back to summary |
|---|---|
| private final ConnectionFactory targetConnectionFactory | |
| TransactionAwareInvocationHandler | back to summary |
|---|---|
| pack-priv TransactionAwareInvocationHandler(Connection connection, ConnectionFactory targetConnectionFactory) | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |
| proxyToString | back to summary |
|---|---|
| private String proxyToString(Object proxy) | |