List of usage examples for javax.resource.cci ConnectionFactory getConnection
public Connection getConnection() throws ResourceException;
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(); }