Search in sources :

Example 46 with Transaction

use of javax.transaction.Transaction in project wildfly by wildfly.

the class InboundBridgeResource method enlistXAResource.

@POST
@Transactional
public Response enlistXAResource() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("InboundBridgeResource.enlistXAResource()");
    }
    try {
        loggingXAResource = new LoggingXAResource();
        Transaction t = TransactionManager.transactionManager().getTransaction();
        t.enlistResource(loggingXAResource);
    } catch (Exception e) {
        LOG.warn(e.getMessage(), e);
        return Response.serverError().build();
    }
    return Response.ok().build();
}
Also used : Transaction(javax.transaction.Transaction) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Transactional(javax.transaction.Transactional)

Example 47 with Transaction

use of javax.transaction.Transaction in project wildfly by wildfly.

the class JCAOrderedLastSynchronizationList method afterCompletion.

@Override
public void afterCompletion(int status) {
    // https://github.com/jbosstm/narayana/blob/master/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java#L509
    for (int i = preJcaSyncs.size() - 1; i >= 0; --i) {
        Synchronization preJcaSync = preJcaSyncs.get(i);
        if (TransactionLogger.ROOT_LOGGER.isTraceEnabled()) {
            TransactionLogger.ROOT_LOGGER.trace("JCAOrderedLastSynchronizationList.preJcaSyncs.afterCompletion - Class: " + preJcaSync.getClass() + " HashCode: " + preJcaSync.hashCode() + " toString: " + preJcaSync);
        }
        try {
            preJcaSync.afterCompletion(status);
        } catch (Exception e) {
            // Trap these exceptions so the rest of the synchronizations get the chance to complete
            // https://github.com/jbosstm/narayana/blob/5.0.4.Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/SynchronizationImple.java#L102
            TransactionLogger.ROOT_LOGGER.preJcaSyncAfterCompletionFailed(preJcaSync, tx, e);
        }
    }
    for (int i = jcaSyncs.size() - 1; i >= 0; --i) {
        Synchronization jcaSync = jcaSyncs.get(i);
        if (TransactionLogger.ROOT_LOGGER.isTraceEnabled()) {
            TransactionLogger.ROOT_LOGGER.trace("JCAOrderedLastSynchronizationList.jcaSyncs.afterCompletion - Class: " + jcaSync.getClass() + " HashCode: " + jcaSync.hashCode() + " toString: " + jcaSync);
        }
        try {
            jcaSync.afterCompletion(status);
        } catch (Exception e) {
            // Trap these exceptions so the rest of the synchronizations get the chance to complete
            // https://github.com/jbosstm/narayana/blob/5.0.4.Final/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/SynchronizationImple.java#L102
            TransactionLogger.ROOT_LOGGER.jcaSyncAfterCompletionFailed(jcaSync, tx, e);
        }
    }
    if (jcaOrderedLastSynchronizations.remove(tx) == null) {
        // The identifier wasn't stable - scan for it - this can happen in JTS propagation when the UID needs retrieving
        // from the parent and the parent has been deactivated
        Transaction altKey = null;
        Iterator<Entry<Transaction, JCAOrderedLastSynchronizationList>> iterator = jcaOrderedLastSynchronizations.entrySet().iterator();
        while (altKey == null && iterator.hasNext()) {
            Map.Entry<Transaction, JCAOrderedLastSynchronizationList> next = iterator.next();
            if (next.getValue().equals(this)) {
                altKey = next.getKey();
                iterator.remove();
                if (TransactionLogger.ROOT_LOGGER.isTraceEnabled()) {
                    TransactionLogger.ROOT_LOGGER.tracef("Removed: %s [%s]", System.identityHashCode(tx), tx.toString());
                }
                break;
            }
        }
        if (altKey == null) {
            TransactionLogger.ROOT_LOGGER.transactionNotFound(tx);
        }
    }
}
Also used : Entry(java.util.Map.Entry) Transaction(javax.transaction.Transaction) Synchronization(javax.transaction.Synchronization) Map(java.util.Map) SystemException(javax.transaction.SystemException)

Example 48 with Transaction

use of javax.transaction.Transaction in project wildfly by wildfly.

the class TransactionSynchronizationRegistryWrapper method registerInterposedSynchronization.

@Override
public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException {
    try {
        Transaction tx = transactionManager.getTransaction();
        JCAOrderedLastSynchronizationList jcaOrderedLastSynchronization = interposedSyncs.get(tx);
        if (jcaOrderedLastSynchronization == null) {
            JCAOrderedLastSynchronizationList toPut = new JCAOrderedLastSynchronizationList((com.arjuna.ats.jta.transaction.Transaction) tx, interposedSyncs);
            jcaOrderedLastSynchronization = interposedSyncs.putIfAbsent(tx, toPut);
            if (jcaOrderedLastSynchronization == null) {
                jcaOrderedLastSynchronization = toPut;
                delegate.registerInterposedSynchronization(jcaOrderedLastSynchronization);
            }
        }
        jcaOrderedLastSynchronization.registerInterposedSynchronization(sync);
    } catch (SystemException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException)

Example 49 with Transaction

use of javax.transaction.Transaction in project wildfly by wildfly.

the class TimerServiceImpl method registerSynchronization.

private void registerSynchronization(Synchronization synchronization) {
    try {
        final Transaction tx = this.getTransaction();
        // register for lifecycle events of transaction
        tx.registerSynchronization(synchronization);
    } catch (RollbackException e) {
        throw new EJBException(e);
    } catch (SystemException e) {
        throw new EJBException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) EJBException(javax.ejb.EJBException)

Example 50 with Transaction

use of javax.transaction.Transaction in project wildfly by wildfly.

the class CMTTxInterceptor method notSupported.

protected Object notSupported(InterceptorContext invocation, final EJBComponent component) throws Exception {
    final TransactionManager tm = component.getTransactionManager();
    Transaction tx = tm.getTransaction();
    if (tx != null) {
        tm.suspend();
        try {
            return invokeInNoTx(invocation, component);
        } finally {
            tm.resume(tx);
        }
    } else {
        return invokeInNoTx(invocation, component);
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager)

Aggregations

Transaction (javax.transaction.Transaction)160 SystemException (javax.transaction.SystemException)55 Test (org.junit.Test)42 RollbackException (javax.transaction.RollbackException)26 TransactionManager (javax.transaction.TransactionManager)24 UserTransaction (javax.transaction.UserTransaction)19 NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)14 NotSupportedException (javax.transaction.NotSupportedException)13 Synchronization (javax.transaction.Synchronization)10 XAResource (javax.transaction.xa.XAResource)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)10 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)8 InvalidTransactionException (javax.transaction.InvalidTransactionException)7 TransactionContext (com.hazelcast.transaction.TransactionContext)6 RemoteException (java.rmi.RemoteException)6 ResourceException (javax.resource.ResourceException)6 ManagedConnection (javax.resource.spi.ManagedConnection)6 SQLException (java.sql.SQLException)5 HeuristicMixedException (javax.transaction.HeuristicMixedException)5 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)5