Class SingleConnectionFactory
- All Implemented Interfaces:
- ConnectionFactory,- Wrapped<ConnectionFactory>,- DisposableBean
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.
- Since:
- 5.3
- Author:
- Mark Paluch
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionSingleConnectionFactory(ConnectionFactory targetConnectionFactory) Constructor for bean-style configuration.SingleConnectionFactory(Connection target, ConnectionFactoryMetadata metadata, boolean suppressClose) SingleConnectionFactory(String url, boolean suppressClose) Create a newSingleConnectionFactoryusing an R2DBC connection URL.
- 
Method SummaryModifier and TypeMethodDescriptionreactor.core.publisher.Mono<? extends Connection>create()voiddestroy()Close the underlyingConnection.protected BooleanReturn whether the returnedConnection's "autoCommit" setting should be overridden.protected ConnectionWrap the givenConnectionwith a proxy that delegates every method call to it but suppresses close calls.protected booleanReturn whether the returnedConnectionwill be a close-suppressing proxy or the physicalConnection.protected reactor.core.publisher.Mono<Connection>prepareConnection(Connection connection) Prepare theConnectionbefore using it.reactor.core.publisher.Mono<Void>Reset the underlying shared Connection, to be reinitialized on next access.voidsetAutoCommit(boolean autoCommit) Set whether the returnedConnection's "autoCommit" setting should be overridden.voidsetSuppressClose(boolean suppressClose) Set whether the returnedConnectionshould be a close-suppressing proxy or the physicalConnection.Methods inherited from class org.springframework.r2dbc.connection.DelegatingConnectionFactorygetMetadata, getTargetConnectionFactory, unwrap
- 
Constructor Details- 
SingleConnectionFactoryConstructor for bean-style configuration.
- 
SingleConnectionFactoryCreate a newSingleConnectionFactoryusing an R2DBC connection URL.- Parameters:
- url- the R2DBC URL to use for accessing- ConnectionFactorydiscovery
- suppressClose- if the returned- Connectionshould be a close-suppressing proxy or the physical- Connection
- See Also:
 
- 
SingleConnectionFactorypublic SingleConnectionFactory(Connection target, ConnectionFactoryMetadata metadata, boolean suppressClose) - Parameters:
- target- underlying target- Connection
- metadata-- ConnectionFactorymetadata to be associated with this- ConnectionFactory
- suppressClose-- trueif the- Connectionshould be wrapped with a- Connectionthat suppresses- close()calls (to allow for normal- close()usage in applications that expect a pooled- Connection)
 
 
- 
- 
Method Details- 
setSuppressClosepublic void setSuppressClose(boolean suppressClose) Set whether the returnedConnectionshould be a close-suppressing proxy or the physicalConnection.
- 
isSuppressCloseprotected boolean isSuppressClose()Return whether the returnedConnectionwill be a close-suppressing proxy or the physicalConnection.
- 
setAutoCommitpublic void setAutoCommit(boolean autoCommit) Set whether the returnedConnection's "autoCommit" setting should be overridden.
- 
getAutoCommitValueReturn whether the returnedConnection's "autoCommit" setting should be overridden.- Returns:
- the "autoCommit" value, or nullif none to be applied
 
- 
create- Specified by:
- createin interface- ConnectionFactory
- Overrides:
- createin class- DelegatingConnectionFactory
 
- 
destroypublic void destroy()Close the underlyingConnection. The provider of thisConnectionFactoryneeds to care for proper shutdown.As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its cached singletons.- Specified by:
- destroyin interface- DisposableBean
 
- 
resetConnectionReset the underlying shared Connection, to be reinitialized on next access.
- 
prepareConnectionPrepare theConnectionbefore using it. Applies auto-commit settings if configured.- Parameters:
- connection- the requested- Connection
- Returns:
- the prepared Connection
 
- 
getCloseSuppressingConnectionProxyWrap the givenConnectionwith a proxy that delegates every method call to it but suppresses close calls.- Parameters:
- target- the original- Connectionto wrap
- Returns:
- the wrapped Connection
 
 
-