Example usage for javax.resource.cci ConnectionFactory getConnection

List of usage examples for javax.resource.cci ConnectionFactory getConnection

Introduction

In this page you can find the example usage for javax.resource.cci ConnectionFactory getConnection.

Prototype

public Connection getConnection(ConnectionSpec properties) throws ResourceException;

Source Link

Document

Gets a connection to an EIS instance.

Usage

From source file:org.springframework.jca.cci.connection.ConnectionFactoryUtils.java

/**
 * Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
 * into the Spring hierarchy of unchecked generic data access exceptions, simplifying
 * calling code and making any exception that is thrown more meaningful.
 * <p>Is aware of a corresponding Connection bound to the current thread, for example
 * when using {@link CciLocalTransactionManager}. Will bind a Connection to the thread
 * if transaction synchronization is active (e.g. if in a JTA transaction).
 * @param cf the ConnectionFactory to obtain Connection from
 * @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
 * Note: If this is specified, a new Connection will be obtained for every call,
 * without participating in a shared transactional Connection.
 * @return a CCI Connection from the given ConnectionFactory
 * @throws org.springframework.jca.cci.CannotGetCciConnectionException
 * if the attempt to get a Connection failed
 * @see #releaseConnection/* w  w  w  . jav a 2  s  .  c om*/
 */
public static Connection getConnection(ConnectionFactory cf, @Nullable ConnectionSpec spec)
        throws CannotGetCciConnectionException {
    try {
        if (spec != null) {
            Assert.notNull(cf, "No ConnectionFactory specified");
            return cf.getConnection(spec);
        } else {
            return doGetConnection(cf);
        }
    } catch (ResourceException ex) {
        throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
    }
}