DelegatingConnectionFactory that wraps a
single R2DBC Connection which is not closed after use.
Obviously, this is not multi-threading capable.
Note that at shutdown, someone should close the underlying
Connection via the close() method. Client code will
never call close on the Connection handle if it is
SmartConnectionFactory-aware (e.g. uses
ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory)).
If client code will call Connection#close() in the
assumption of a pooled Connection, like when using persistence tools,
set "suppressClose" to true. This will return a close-suppressing
proxy instead of the physical Connection.
This is primarily intended for testing and pipelining usage of connections.
For example, it enables easy testing outside an application server for code
that expects to work on a ConnectionFactory.
Note that this implementation does not act as a connection pool-like utility.
Connection pooling requires a pooling ConnectionFactory such as one from
r2dbc-pool.
create(), Connection#close(), ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory)
| Modifier and Type | Class and Description |
|---|---|
| private static class | SingleConnectionFactory.
Invocation handler that suppresses close calls on R2DBC Connections. |
| Modifier and Type | Field and Description |
|---|---|
| private Boolean | autoCommit
Override auto-commit state?. |
| private Connection | connection
Proxy Connection. |
| private final Mono | |
| private boolean | suppressClose
Create a close-suppressing proxy?. |
| private final AtomicReference | target
Wrapped Connection. |
| Access | Constructor and Description |
|---|---|
| public | SingleConnectionFactory(ConnectionFactory targetConnectionFactory)
Constructor for bean-style configuration. |
| public | SingleConnectionFactory(String
the R2DBC URL to use for accessing url, boolean ConnectionFactory discoveryif the returned suppressClose)Connection should be a
close-suppressing proxy or the physical ConnectionCreate a new |
| public | SingleConnectionFactory(Connection
underlying target target, ConnectionFactoryMetadata ConnectionConnectionFactory metadata to be associated with
this ConnectionFactorytrue if the Connection should be wrapped
with a Connection that suppresses close() calls (to allow
for normal close() usage in applications that expect a pooled
Connection)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public Mono | create()
Overrides org. Implements io. Creates a new |
| public void | destroy()
Implements org. Close the underlying |
| protected Boolean | Returns: the "autoCommit" value, ornull if none to be appliedReturn whether the returned |
| protected Connection | Returns: the wrapped Connectionthe original target)Connection to wrapWrap the given |
| protected boolean | isSuppressClose()
Return whether the returned |
| protected Mono | Returns: the preparedConnectionthe requested connection)ConnectionPrepare the |
| public Mono | |
| public void | setAutoCommit(boolean autoCommit)
Set whether the returned |
| public void | setSuppressClose(boolean suppressClose)
Set whether the returned |
| autoCommit | back to summary |
|---|---|
| private Boolean autoCommit Override auto-commit state?. | |
| connection | back to summary |
|---|---|
| private Connection connection Proxy Connection. | |
| connectionEmitter | back to summary |
|---|---|
| private final Mono<? extends Connection> connectionEmitter | |
| suppressClose | back to summary |
|---|---|
| private boolean suppressClose Create a close-suppressing proxy?. | |
| target | back to summary |
|---|---|
| private final AtomicReference<Connection> target Wrapped Connection. | |
| SingleConnectionFactory | back to summary |
|---|---|
| public SingleConnectionFactory(ConnectionFactory targetConnectionFactory) Constructor for bean-style configuration. | |
| SingleConnectionFactory | back to summary |
|---|---|
| public SingleConnectionFactory(String url, boolean suppressClose) Create a new
| |
| SingleConnectionFactory | back to summary |
|---|---|
| public SingleConnectionFactory(Connection target, ConnectionFactoryMetadata metadata, boolean suppressClose) Create a new
| |
| create | back to summary |
|---|---|
| public Mono Overrides org. Implements io. Doc from io. Creates a new
| |
| destroy | back to summary |
|---|---|
| public void destroy() Implements org. Close the underlying As this bean implements
| |
| getAutoCommitValue | back to summary |
|---|---|
| protected Boolean getAutoCommitValue() Return whether the returned | |
| getCloseSuppressingConnectionProxy | back to summary |
|---|---|
| protected Connection getCloseSuppressingConnectionProxy(Connection target) Wrap the given
| |
| isSuppressClose | back to summary |
|---|---|
| protected boolean isSuppressClose() Return whether the returned | |
| prepareConnection | back to summary |
|---|---|
| protected Mono Prepare the
| |
| resetConnection | back to summary |
|---|---|
| public Mono Reset the underlying shared Connection, to be reinitialized on next access. | |
| setAutoCommit | back to summary |
|---|---|
| public void setAutoCommit(boolean autoCommit) Set whether the returned | |
| setSuppressClose | back to summary |
|---|---|
| public void setSuppressClose(boolean suppressClose) Set whether the returned | |
Connection#close()
| Modifier and Type | Field and Description |
|---|---|
| private final Connection |
| 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. Processes a method invocation on a proxy instance and returns the result. |
| target | back to summary |
|---|---|
| private final Connection target | |
| CloseSuppressingInvocationHandler | back to summary |
|---|---|
| pack-priv CloseSuppressingInvocationHandler(Connection target) | |
| 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.
| |