Search in sources :

Example 11 with XAResource

use of javax.transaction.xa.XAResource in project spring-boot by spring-projects.

the class DataSourceXAResourceRecoveryHelperTests method shouldFailToCreateConnectionAndNotGetXAResource.

@Test
public void shouldFailToCreateConnectionAndNotGetXAResource() throws SQLException {
    given(this.xaDataSource.getXAConnection()).willThrow(new SQLException("Test exception"));
    XAResource[] xaResources = this.recoveryHelper.getXAResources();
    assertThat(xaResources.length).isEqualTo(0);
    verify(this.xaDataSource, times(1)).getXAConnection();
    verify(this.xaConnection, times(0)).getXAResource();
}
Also used : XAResource(javax.transaction.xa.XAResource) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 12 with XAResource

use of javax.transaction.xa.XAResource in project hazelcast by hazelcast.

the class HazelcastXATest method close.

private void close(boolean error, XAResource... xaResource) throws Exception {
    int flag = XAResource.TMSUCCESS;
    // get the current tx
    Transaction tx = tm.getTransaction();
    // closeConnection
    if (error)
        flag = XAResource.TMFAIL;
    for (XAResource resource : xaResource) {
        tx.delistResource(resource, flag);
    }
    if (error)
        tm.rollback();
    else
        tm.commit();
}
Also used : XAResource(javax.transaction.xa.XAResource) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource) Transaction(javax.transaction.Transaction)

Example 13 with XAResource

use of javax.transaction.xa.XAResource in project aries by apache.

the class TransactionContextImpl method finish.

@Override
public void finish() {
    if (!resources.isEmpty()) {
        XAResource localResource = new LocalXAResourceImpl();
        try {
            currentTransaction.enlistResource(localResource);
        } catch (Exception e) {
            safeSetRollbackOnly();
            recordFailure(e);
            try {
                localResource.rollback(null);
            } catch (XAException e1) {
                recordFailure(e1);
            }
        }
    }
    try {
        TxListener listener = new TxListener();
        try {
            transactionManager.registerInterposedSynchronization(listener);
            if (getRollbackOnly()) {
                // GERONIMO-4449 says that we get no beforeCompletion 
                // callback for rollback :(
                listener.beforeCompletion();
                transactionManager.rollback();
            } else {
                transactionManager.commit();
            }
        } catch (Exception e) {
            recordFailure(e);
        }
    } finally {
        try {
            transactionManager.resume(oldTran);
        } catch (Exception e) {
            recordFailure(e);
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) TransactionException(org.osgi.service.transaction.control.TransactionException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException)

Example 14 with XAResource

use of javax.transaction.xa.XAResource in project geode by apache.

the class JCAConnectionManagerImpl method allocateConnection.

/*
   * allocates a ManagedConnection from the ConnectionPool or creates a new
   * ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
   * 
   * @param javax.resource.spi.ConnectionRequestInfo
   * 
   * @throws ResourceException
   */
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
    if (!isActive) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
    }
    ManagedConnection conn = null;
    try {
        conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
    } catch (PoolException ex) {
        // ex.printStackTrace();
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    // Transaction Manager.
    try {
        synchronized (this) {
            if (transManager == null) {
                transManager = JNDIInvoker.getTransactionManager();
            }
        }
        Transaction txn = transManager.getTransaction();
        if (txn != null) {
            // Check if Data Source provides XATransaction
            // if(configs.getTransactionType = "XATransaction")
            XAResource xar = conn.getXAResource();
            txn.enlistResource(xar);
            // Asif :Add in the Map after successful registration of XAResource
            xaResourcesMap.put(conn, xar);
        // else throw a resource exception
        }
    } catch (RollbackException ex) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_TRANSACTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    } catch (SystemException ex) {
        throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    return conn.getConnection(subject, reqInfo);
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) ResourceException(javax.resource.ResourceException) ManagedConnection(javax.resource.spi.ManagedConnection) RollbackException(javax.transaction.RollbackException)

Example 15 with XAResource

use of javax.transaction.xa.XAResource in project jackrabbit by apache.

the class UserTransactionImpl method rollback.

/**
     * @see javax.transaction.UserTransaction#rollback
     */
public void rollback() throws IllegalStateException, SecurityException, SystemException {
    if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
        throw new IllegalStateException("Transaction not active");
    }
    try {
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.end(xid, XAResource.TMFAIL);
        }
        status = Status.STATUS_ROLLING_BACK;
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.rollback(xid);
        }
        status = Status.STATUS_ROLLEDBACK;
    } catch (XAException e) {
        SystemException se = new SystemException("Unable to rollback transaction: XA_ERR=" + e.errorCode);
        se.initCause(e.getCause());
        throw se;
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) Iterator(java.util.Iterator)

Aggregations

XAResource (javax.transaction.xa.XAResource)37 Xid (javax.transaction.xa.Xid)13 Test (org.junit.Test)13 SystemException (javax.transaction.SystemException)10 Transaction (javax.transaction.Transaction)10 XidImpl (org.neo4j.kernel.impl.transaction.XidImpl)9 XAException (javax.transaction.xa.XAException)8 RollbackException (javax.transaction.RollbackException)7 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 HashMap (java.util.HashMap)5 RelationshipType (org.neo4j.graphdb.RelationshipType)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 ResourceException (javax.resource.ResourceException)4 ManagedConnection (javax.resource.spi.ManagedConnection)4 XAConnection (javax.sql.XAConnection)4 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)3 Iterator (java.util.Iterator)3