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() throws ResourceException;

Source Link

Document

Gets a connection to an EIS instance.

Usage

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

/**
 * Actually obtain a CCI Connection from the given ConnectionFactory.
 * Same as {@link #getConnection}, but throwing the original ResourceException.
 * <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).
 * <p>Directly accessed by {@link TransactionAwareConnectionFactoryProxy}.
 * @param cf the ConnectionFactory to obtain Connection from
 * @return a CCI Connection from the given ConnectionFactory
 * @throws ResourceException if thrown by CCI API methods
 * @see #doReleaseConnection/*from w  w w  .j a v a  2  s  .co  m*/
 */
public static Connection doGetConnection(ConnectionFactory cf) throws ResourceException {
    Assert.notNull(cf, "No ConnectionFactory specified");

    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(cf);
    if (conHolder != null) {
        return conHolder.getConnection();
    }

    logger.debug("Opening CCI Connection");
    Connection con = cf.getConnection();

    if (TransactionSynchronizationManager.isSynchronizationActive()) {
        logger.debug("Registering transaction synchronization for CCI Connection");
        conHolder = new ConnectionHolder(con);
        conHolder.setSynchronizedWithTransaction(true);
        TransactionSynchronizationManager.registerSynchronization(new ConnectionSynchronization(conHolder, cf));
        TransactionSynchronizationManager.bindResource(cf, conHolder);
    }

    return con;
}

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

/**
 * Create a CCI Connection via this template's ConnectionFactory.
 * @return the new CCI Connection//from w ww.  j a v  a2s.  c o  m
 * @throws javax.resource.ResourceException if thrown by CCI API methods
 */
protected Connection doCreateConnection() throws ResourceException {
    ConnectionFactory connectionFactory = getTargetConnectionFactory();
    Assert.state(connectionFactory != null, "No 'targetConnectionFactory' set");
    return connectionFactory.getConnection();
}