Search in sources :

Example 1 with Connection

use of javax.resource.cci.Connection in project spring-framework by spring-projects.

the class CciLocalTransactionManager method doCleanupAfterCompletion.

@Override
protected void doCleanupAfterCompletion(Object transaction) {
    CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
    // Remove the connection holder from the thread.
    TransactionSynchronizationManager.unbindResource(getConnectionFactory());
    txObject.getConnectionHolder().clear();
    Connection con = txObject.getConnectionHolder().getConnection();
    if (logger.isDebugEnabled()) {
        logger.debug("Releasing CCI Connection [" + con + "] after transaction");
    }
    ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
}
Also used : Connection(javax.resource.cci.Connection)

Example 2 with Connection

use of javax.resource.cci.Connection in project spring-framework by spring-projects.

the class CciLocalTransactionManager method doCommit.

@Override
protected void doCommit(DefaultTransactionStatus status) {
    CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction();
    Connection con = txObject.getConnectionHolder().getConnection();
    if (status.isDebug()) {
        logger.debug("Committing CCI local transaction on Connection [" + con + "]");
    }
    try {
        con.getLocalTransaction().commit();
    } catch (LocalTransactionException ex) {
        throw new TransactionSystemException("Could not commit CCI local transaction", ex);
    } catch (ResourceException ex) {
        throw new TransactionSystemException("Unexpected failure on commit of CCI local transaction", ex);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) Connection(javax.resource.cci.Connection) ResourceException(javax.resource.ResourceException) TransactionSystemException(org.springframework.transaction.TransactionSystemException)

Example 3 with Connection

use of javax.resource.cci.Connection in project spring-framework by spring-projects.

the class CciLocalTransactionManager method doRollback.

@Override
protected void doRollback(DefaultTransactionStatus status) {
    CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction();
    Connection con = txObject.getConnectionHolder().getConnection();
    if (status.isDebug()) {
        logger.debug("Rolling back CCI local transaction on Connection [" + con + "]");
    }
    try {
        con.getLocalTransaction().rollback();
    } catch (LocalTransactionException ex) {
        throw new TransactionSystemException("Could not roll back CCI local transaction", ex);
    } catch (ResourceException ex) {
        throw new TransactionSystemException("Unexpected failure on rollback of CCI local transaction", ex);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) Connection(javax.resource.cci.Connection) ResourceException(javax.resource.ResourceException) TransactionSystemException(org.springframework.transaction.TransactionSystemException)

Example 4 with Connection

use of javax.resource.cci.Connection in project spring-framework by spring-projects.

the class ConnectionFactoryUtils method doGetConnection.

/**
	 * 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
	 */
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;
}
Also used : Connection(javax.resource.cci.Connection)

Example 5 with Connection

use of javax.resource.cci.Connection in project spring-framework by spring-projects.

the class CciTemplate method execute.

@Override
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
    Assert.notNull(action, "Callback object must not be null");
    Connection con = ConnectionFactoryUtils.getConnection(getConnectionFactory(), getConnectionSpec());
    try {
        return action.doInConnection(con, getConnectionFactory());
    } catch (NotSupportedException ex) {
        throw new CciOperationNotSupportedException("CCI operation not supported by connector", ex);
    } catch (ResourceException ex) {
        throw new DataAccessResourceFailureException("CCI operation failed", ex);
    } catch (SQLException ex) {
        throw new InvalidResultSetAccessException("Parsing of CCI ResultSet failed", ex);
    } finally {
        ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
    }
}
Also used : CciOperationNotSupportedException(org.springframework.jca.cci.CciOperationNotSupportedException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) SQLException(java.sql.SQLException) Connection(javax.resource.cci.Connection) ResourceException(javax.resource.ResourceException) InvalidResultSetAccessException(org.springframework.jca.cci.InvalidResultSetAccessException) RecordTypeNotSupportedException(org.springframework.jca.cci.RecordTypeNotSupportedException) NotSupportedException(javax.resource.NotSupportedException) CciOperationNotSupportedException(org.springframework.jca.cci.CciOperationNotSupportedException)

Aggregations

Connection (javax.resource.cci.Connection)36 Test (org.junit.Test)28 ConnectionFactory (javax.resource.cci.ConnectionFactory)25 Interaction (javax.resource.cci.Interaction)23 InteractionSpec (javax.resource.cci.InteractionSpec)22 Record (javax.resource.cci.Record)22 CciTemplate (org.springframework.jca.cci.core.CciTemplate)19 IndexedRecord (javax.resource.cci.IndexedRecord)15 MappedRecord (javax.resource.cci.MappedRecord)15 RecordFactory (javax.resource.cci.RecordFactory)10 RecordCreator (org.springframework.jca.cci.core.RecordCreator)10 NotSupportedRecordFactory (org.springframework.jca.cci.connection.NotSupportedRecordFactory)8 ResourceException (javax.resource.ResourceException)4 NotSupportedException (javax.resource.NotSupportedException)3 LocalTransactionException (javax.resource.spi.LocalTransactionException)3 SimpleRecordOperation (org.springframework.jca.cci.object.SimpleRecordOperation)3 TransactionSystemException (org.springframework.transaction.TransactionSystemException)3 LocalTransaction (javax.resource.cci.LocalTransaction)2 ManagedConnection (javax.resource.spi.ManagedConnection)2 ContainerSystem (org.apache.openejb.spi.ContainerSystem)2