public class SingleConnectionConnectionFactory extends DelegatingConnectionFactory implements SmartConnectionFactory, DisposableBean
SmartConnectionFactory 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 SmartDataSource-aware (e.g. uses
ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.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. For example, it enables easy testing outside an application server, for code
that expects to work on a ConnectionFactory.
create(),
Connection.close(),
ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.Connection, ConnectionFactory)| Constructor and Description |
|---|
SingleConnectionConnectionFactory(Connection target,
ConnectionFactoryMetadata metadata,
boolean suppressClose)
Create a new
SingleConnectionConnectionFactory with a given Connection and
ConnectionFactoryMetadata. |
SingleConnectionConnectionFactory(ConnectionFactory targetConnectionFactory)
Constructor for bean-style configuration.
|
SingleConnectionConnectionFactory(String url,
boolean suppressClose)
Create a new
SingleConnectionConnectionFactory using a R2DBC connection URL. |
| Modifier and Type | Method and Description |
|---|---|
reactor.core.publisher.Mono<? extends Connection> |
create() |
void |
destroy()
Close the underlying
Connection. |
protected Boolean |
getAutoCommitValue()
Return whether the returned
Connection's "autoCommit" setting should be overridden. |
protected Connection |
getCloseSuppressingConnectionProxy(Connection target)
Wrap the given
Connection with a proxy that delegates every method call to it but suppresses close calls. |
protected boolean |
isSuppressClose()
Return whether the returned
Connection will be a close-suppressing proxy or the physical
Connection. |
protected reactor.core.publisher.Mono<Connection> |
prepareConnection(Connection connection)
Prepare the
Connection before using it. |
reactor.core.publisher.Mono<Void> |
resetConnection()
Reset the underlying shared Connection, to be reinitialized on next access.
|
void |
setAutoCommit(boolean autoCommit)
Set whether the returned
Connection's "autoCommit" setting should be overridden. |
void |
setSuppressClose(boolean suppressClose)
Set whether the returned
Connection should be a close-suppressing proxy or the physical Connection. |
boolean |
shouldClose(Connection con)
This is a single Connection: Do not close it when returning to the "pool".
|
getMetadata, getTargetConnectionFactory, obtainTargetConnectionFactory, unwrapclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetMetadatapublic SingleConnectionConnectionFactory(ConnectionFactory targetConnectionFactory)
public SingleConnectionConnectionFactory(String url, boolean suppressClose)
SingleConnectionConnectionFactory using a R2DBC connection URL.url - the R2DBC URL to use for accessing ConnectionFactory discovery.suppressClose - if the returned Connection should be a close-suppressing proxy or the physical
Connection.ConnectionFactories.get(String)public SingleConnectionConnectionFactory(Connection target, ConnectionFactoryMetadata metadata, boolean suppressClose)
SingleConnectionConnectionFactory with a given Connection and
ConnectionFactoryMetadata.target - underlying target Connection.metadata - ConnectionFactory metadata to be associated with this ConnectionFactory.suppressClose - 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 but do not know our SmartConnectionFactory interface).public void setSuppressClose(boolean suppressClose)
Connection should be a close-suppressing proxy or the physical Connection.protected boolean isSuppressClose()
Connection will be a close-suppressing proxy or the physical
Connection.public void setAutoCommit(boolean autoCommit)
Connection's "autoCommit" setting should be overridden.@Nullable protected Boolean getAutoCommitValue()
Connection's "autoCommit" setting should be overridden.null if none to be appliedpublic reactor.core.publisher.Mono<? extends Connection> create()
create in interface ConnectionFactorycreate in class DelegatingConnectionFactorypublic boolean shouldClose(Connection con)
shouldClose in interface SmartConnectionFactorycon - the Connection to check.Connection should be closed.Connection.close()public void destroy()
Connection. The provider of this ConnectionFactory needs to care for proper
shutdown.
As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its
cached singletons.
destroy in interface DisposableBeanpublic reactor.core.publisher.Mono<Void> resetConnection()
protected reactor.core.publisher.Mono<Connection> prepareConnection(Connection connection)
Connection before using it. Applies auto-commit settings if
configured.connection - the requested Connection.Connection.protected Connection getCloseSuppressingConnectionProxy(Connection target)
Connection with a proxy that delegates every method call to it but suppresses close calls.target - the original Connection to wrap.Copyright © 2018–2020 Pivotal Software, Inc.. All rights reserved.