public class SingleConnectionFactory extends DelegatingConnectionFactory implements DisposableBean
getConnection calls, and ignores calls to
Connection.close().
Useful for testing and standalone environments, to keep using the same Connection for multiple CciTemplate calls, without having a pooling ConnectionFactory, also spanning any number of transactions.
You can either pass in a CCI Connection directly, or let this factory lazily create a Connection via a given target ConnectionFactory.
getConnection(),
Connection.close(),
CciTemplate,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
SingleConnectionFactory()
Create a new SingleConnectionFactory for bean-style usage.
|
SingleConnectionFactory(javax.resource.cci.Connection target)
Create a new SingleConnectionFactory that always returns the
given Connection.
|
SingleConnectionFactory(javax.resource.cci.ConnectionFactory targetConnectionFactory)
Create a new SingleConnectionFactory that always returns a single
Connection which it will lazily create via the given target
ConnectionFactory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Make sure a Connection or ConnectionFactory has been set.
|
protected void |
closeConnection(javax.resource.cci.Connection con)
Close the given Connection.
|
void |
destroy()
Close the underlying Connection.
|
protected javax.resource.cci.Connection |
doCreateConnection()
Create a CCI Connection via this template's ConnectionFactory.
|
protected javax.resource.cci.Connection |
getCloseSuppressingConnectionProxy(javax.resource.cci.Connection target)
Wrap the given Connection with a proxy that delegates every method call to it
but suppresses close calls.
|
javax.resource.cci.Connection |
getConnection() |
javax.resource.cci.Connection |
getConnection(javax.resource.cci.ConnectionSpec connectionSpec) |
void |
initConnection()
Initialize the single underlying Connection.
|
protected void |
prepareConnection(javax.resource.cci.Connection con)
Prepare the given Connection before it is exposed.
|
void |
resetConnection()
Reset the underlying shared Connection, to be reinitialized on next access.
|
getMetaData, getRecordFactory, getReference, getTargetConnectionFactory, setReference, setTargetConnectionFactorypublic SingleConnectionFactory()
public SingleConnectionFactory(javax.resource.cci.Connection target)
target - the single Connectionpublic SingleConnectionFactory(javax.resource.cci.ConnectionFactory targetConnectionFactory)
targetConnectionFactory - the target ConnectionFactorypublic void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class DelegatingConnectionFactorypublic javax.resource.cci.Connection getConnection()
throws javax.resource.ResourceException
getConnection in interface javax.resource.cci.ConnectionFactorygetConnection in class DelegatingConnectionFactoryjavax.resource.ResourceExceptionpublic javax.resource.cci.Connection getConnection(javax.resource.cci.ConnectionSpec connectionSpec)
throws javax.resource.ResourceException
getConnection in interface javax.resource.cci.ConnectionFactorygetConnection in class DelegatingConnectionFactoryjavax.resource.ResourceExceptionpublic void destroy()
As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its cached singletons.
destroy in interface DisposableBeanpublic void initConnection()
throws javax.resource.ResourceException
Closes and reinitializes the Connection if an underlying Connection is present already.
javax.resource.ResourceException - if thrown by CCI API methodspublic void resetConnection()
protected javax.resource.cci.Connection doCreateConnection()
throws javax.resource.ResourceException
javax.resource.ResourceException - if thrown by CCI API methodsprotected void prepareConnection(javax.resource.cci.Connection con)
throws javax.resource.ResourceException
The default implementation is empty. Can be overridden in subclasses.
con - the Connection to preparejavax.resource.ResourceExceptionprotected void closeConnection(javax.resource.cci.Connection con)
con - the Connection to closeprotected javax.resource.cci.Connection getCloseSuppressingConnectionProxy(javax.resource.cci.Connection target)
target - the original Connection to wrapCopyright © 2015. All rights reserved.