Search in sources :

Example 1 with Transaction

use of javax.transaction.Transaction in project hibernate-orm by hibernate.

the class XaTransactionManagerImpl method suspend.

public Transaction suspend() throws SystemException {
    Transaction suspended = currentTransaction.get();
    currentTransaction.remove();
    return suspended;
}
Also used : Transaction(javax.transaction.Transaction)

Example 2 with Transaction

use of javax.transaction.Transaction in project hibernate-orm by hibernate.

the class DualNodeJtaTransactionManagerImpl method setRollbackOnly.

public void setRollbackOnly() throws IllegalStateException, SystemException {
    Transaction tx = getCurrentTransaction();
    if (tx == null) {
        throw new IllegalStateException("no current transaction");
    }
    tx.setRollbackOnly();
}
Also used : Transaction(javax.transaction.Transaction)

Example 3 with Transaction

use of javax.transaction.Transaction in project hibernate-orm by hibernate.

the class ClusteredTimestampsRegionImpl method evictAll.

@Override
public void evictAll() throws CacheException {
    // TODO Is this a valid operation on a timestamps cache?
    final Transaction tx = suspend();
    try {
        // Invalidate the local region and then go remote
        invalidateRegion();
        Caches.broadcastEvictAll(cache);
    } finally {
        resume(tx);
    }
}
Also used : Transaction(javax.transaction.Transaction)

Example 4 with Transaction

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

the class InfinispanBatcherTestCase method resumeBatch.

@Test
public void resumeBatch() throws Exception {
    TransactionBatch batch = mock(TransactionBatch.class);
    Transaction tx = mock(Transaction.class);
    when(batch.getTransaction()).thenReturn(tx);
    try (BatchContext context = this.batcher.resumeBatch(batch)) {
        verify(this.tm, never()).suspend();
        verify(this.tm).resume(tx);
        reset(this.tm);
        assertSame(batch, InfinispanBatcher.CURRENT_BATCH.get());
    }
    verify(this.tm).suspend();
    verify(this.tm, never()).resume(any());
    assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
Also used : Transaction(javax.transaction.Transaction) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 5 with Transaction

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

the class InfinispanBatcher method resumeBatch.

@Override
public BatchContext resumeBatch(TransactionBatch batch) {
    TransactionBatch existingBatch = CURRENT_BATCH.get();
    // Trivial case - nothing to suspend/resume
    if (batch == existingBatch)
        return PASSIVE_BATCH_CONTEXT;
    Transaction tx = (batch != null) ? batch.getTransaction() : null;
    // Non-tx case, just swap thread local
    if ((batch == null) || (tx == null)) {
        CURRENT_BATCH.set(batch);
        return () -> {
            CURRENT_BATCH.set(existingBatch);
        };
    }
    try {
        if (existingBatch != null) {
            Transaction existingTx = this.tm.suspend();
            if (existingBatch.getTransaction() != existingTx) {
                throw new IllegalStateException();
            }
        }
        this.tm.resume(tx);
        CURRENT_BATCH.set(batch);
        return () -> {
            try {
                this.tm.suspend();
                if (existingBatch != null) {
                    try {
                        this.tm.resume(existingBatch.getTransaction());
                        CURRENT_BATCH.set(existingBatch);
                    } catch (InvalidTransactionException e) {
                        throw new CacheException(e);
                    }
                } else {
                    CURRENT_BATCH.remove();
                }
            } catch (SystemException e) {
                throw new CacheException(e);
            }
        };
    } catch (SystemException | InvalidTransactionException e) {
        throw new CacheException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) CacheException(org.infinispan.commons.CacheException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Aggregations

Transaction (javax.transaction.Transaction)375 Test (org.junit.Test)128 SystemException (javax.transaction.SystemException)106 TransactionManager (javax.transaction.TransactionManager)65 RollbackException (javax.transaction.RollbackException)46 XAResource (javax.transaction.xa.XAResource)43 UserTransaction (javax.transaction.UserTransaction)31 NotSupportedException (javax.transaction.NotSupportedException)29 XAException (javax.transaction.xa.XAException)29 Xid (javax.transaction.xa.Xid)27 Session (javax.jms.Session)25 Connection (javax.jms.Connection)24 MessageConsumer (javax.jms.MessageConsumer)24 MessageProducer (javax.jms.MessageProducer)24 TextMessage (javax.jms.TextMessage)24 XAConnection (javax.jms.XAConnection)24 XASession (javax.jms.XASession)24 Synchronization (javax.transaction.Synchronization)22 Uid (com.arjuna.ats.arjuna.common.Uid)18 Message (javax.jms.Message)18