org.springframework.jca.cci.connection
Class ConnectionFactoryUtils

java.lang.Object
  extended by org.springframework.jca.cci.connection.ConnectionFactoryUtils

public abstract class ConnectionFactoryUtils
extends Object

Helper class that provides static methods to obtain CCI Connections from a ConnectionFactory, and to close Connections if necessary. Has special support for Spring-managed connections, e.g. for use with CciLocalTransactionManager.

Used internally by CciTemplate, CCI operation objects and the CciLocalTransactionManager. Can also be used directly in application code.

Since:
1.2
Author:
Thierry Templier, Juergen Hoeller
See Also:
getConnection(javax.resource.cci.ConnectionFactory), releaseConnection(javax.resource.cci.Connection, javax.resource.cci.ConnectionFactory), CciLocalTransactionManager, CciTemplate, MappingRecordOperation

Constructor Summary
ConnectionFactoryUtils()
           
 
Method Summary
static Connection doGetConnection(ConnectionFactory cf)
          Actually get a CCI Connection for the given ConnectionFactory.
static void doReleaseConnection(Connection con, ConnectionFactory cf)
          Actually close a JCA CCI Connection for the given DataSource.
static Connection getConnection(ConnectionFactory cf)
          Get a Connection from the given DataSource.
static void releaseConnection(Connection con, ConnectionFactory cf)
          Close the given Connection if necessary, i.e. if it is not bound to the thread and it is not created by a SmartDataSource returning shouldClose=false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactoryUtils

public ConnectionFactoryUtils()
Method Detail

getConnection

public static Connection getConnection(ConnectionFactory cf)
                                throws CannotGetCciConnectionException
Get a Connection from the given DataSource. Changes any CCI exception into the Spring hierarchy of unchecked generic data access exceptions, simplifying calling code and making any exception that is thrown more meaningful.

Is aware of a corresponding Connection bound to the current thread, for example when using CciLocalTransactionManager. Will bind a Connection to the thread if transaction synchronization is active (e.g. if in a JTA transaction).

Parameters:
cf - ConnectionFactory to get Connection from
Returns:
a CCI Connection from the given ConnectionFactory
Throws:
CannotGetCciConnectionException - if the attempt to get a Connection failed
See Also:
TransactionSynchronizationManager, CciLocalTransactionManager

doGetConnection

public static Connection doGetConnection(ConnectionFactory cf)
                                  throws ResourceException
Actually get a CCI Connection for the given ConnectionFactory. Same as getConnection, but throwing the original ResourceException.

Is aware of a corresponding Connection bound to the current thread, for example when using DataSourceTransactionManager. Will bind a Connection to the thread if transaction synchronization is active (e.g. if in a JTA transaction).

Directly accessed by TransactionAwareDataSourceProxy.

Parameters:
cf - ConnectionFactory to get Connection from
Returns:
a CCI Connection from the given ConnectionFactory
Throws:
ResourceException - if thrown by CCI API methods
See Also:
getConnection(ConnectionFactory), TransactionAwareConnectionFactoryProxy

releaseConnection

public static void releaseConnection(Connection con,
                                     ConnectionFactory cf)
Close the given Connection if necessary, i.e. if it is not bound to the thread and it is not created by a SmartDataSource returning shouldClose=false.

Parameters:
con - Connection to close if necessary (if this is null, the call will be ignored)
cf - ConnectionFactory that the Connection came from

doReleaseConnection

public static void doReleaseConnection(Connection con,
                                       ConnectionFactory cf)
                                throws ResourceException
Actually close a JCA CCI Connection for the given DataSource. Same as releaseConnection, but throwing the original ResourceException.

Directly accessed by TransactionAwareConnectionFactoryProxy.

Throws:
ResourceException - if thrown by JCA CCI methods
See Also:
releaseConnection(javax.resource.cci.Connection, javax.resource.cci.ConnectionFactory)


Copyright (c) 2002-2005 The Spring Framework Project.