Search in sources :

Example 81 with Synchronization

use of javax.transaction.Synchronization in project neo4j-mobile-android by neo4j-contrib.

the class ReadOnlyTransactionImpl method doBeforeCompletion.

synchronized void doBeforeCompletion() {
    beforeCompletionRunning = true;
    try {
        for (Synchronization s : syncHooks) {
            try {
                s.beforeCompletion();
            } catch (Throwable t) {
                log.warning("Caught exception from tx syncronization[" + s + "] beforeCompletion()");
            }
        }
        // execute any hooks added since we entered doBeforeCompletion
        while (!syncHooksAdded.isEmpty()) {
            List<Synchronization> addedHooks = syncHooksAdded;
            syncHooksAdded = new ArrayList<Synchronization>();
            for (Synchronization s : addedHooks) {
                s.beforeCompletion();
                syncHooks.add(s);
            }
        }
    } finally {
        beforeCompletionRunning = false;
    }
}
Also used : Synchronization(javax.transaction.Synchronization)

Example 82 with Synchronization

use of javax.transaction.Synchronization in project neo4j-mobile-android by neo4j-contrib.

the class TransactionImpl method doBeforeCompletion.

synchronized void doBeforeCompletion() {
    beforeCompletionRunning = true;
    try {
        for (Synchronization s : syncHooks) {
            try {
                s.beforeCompletion();
            } catch (Throwable t) {
                log.log(Level.WARNING, "Caught exception from tx syncronization[" + s + "] beforeCompletion()", t);
            }
        }
        // execute any hooks added since we entered doBeforeCompletion
        while (!syncHooksAdded.isEmpty()) {
            List<Synchronization> addedHooks = syncHooksAdded;
            syncHooksAdded = new ArrayList<Synchronization>();
            for (Synchronization s : addedHooks) {
                s.beforeCompletion();
                syncHooks.add(s);
            }
        }
    } finally {
        beforeCompletionRunning = false;
    }
}
Also used : Synchronization(javax.transaction.Synchronization)

Example 83 with Synchronization

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

the class TransactionalBatcherTestCase method createBatchClose.

@Test
public void createBatchClose() throws Exception {
    Transaction tx = mock(Transaction.class);
    ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
    when(this.tm.getTransaction()).thenReturn(tx);
    try (TransactionBatch batch = this.batcher.createBatch()) {
        verify(this.tm).begin();
        verify(tx).registerSynchronization(capturedSync.capture());
        assertSame(tx, batch.getTransaction());
    } finally {
        capturedSync.getValue().afterCompletion(Status.STATUS_COMMITTED);
    }
    verify(tx).commit();
    assertNull(TransactionalBatcher.getCurrentBatch());
}
Also used : Transaction(javax.transaction.Transaction) Synchronization(javax.transaction.Synchronization) Test(org.junit.Test)

Example 84 with Synchronization

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

the class TransactionalBatcherTestCase method createBatchDiscard.

@Test
public void createBatchDiscard() throws Exception {
    Transaction tx = mock(Transaction.class);
    ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
    when(this.tm.getTransaction()).thenReturn(tx);
    try (TransactionBatch batch = this.batcher.createBatch()) {
        verify(this.tm).begin();
        verify(tx).registerSynchronization(capturedSync.capture());
        assertSame(tx, batch.getTransaction());
        batch.discard();
    } finally {
        capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
    }
    verify(tx, never()).commit();
    verify(tx).rollback();
    assertNull(TransactionalBatcher.getCurrentBatch());
}
Also used : Transaction(javax.transaction.Transaction) Synchronization(javax.transaction.Synchronization) Test(org.junit.Test)

Example 85 with Synchronization

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

the class TransactionalBatcherTestCase method createNestedBatchClose.

@Test
public void createNestedBatchClose() throws Exception {
    Transaction tx = mock(Transaction.class);
    ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
    when(this.tm.getTransaction()).thenReturn(tx);
    try (TransactionBatch outerBatch = this.batcher.createBatch()) {
        verify(this.tm).begin();
        verify(tx).registerSynchronization(capturedSync.capture());
        reset(this.tm);
        assertSame(tx, outerBatch.getTransaction());
        when(this.tm.getTransaction()).thenReturn(tx);
        try (TransactionBatch innerBatch = this.batcher.createBatch()) {
            verify(this.tm, never()).begin();
            verify(this.tm, never()).suspend();
        }
        verify(tx, never()).rollback();
        verify(tx, never()).commit();
    } finally {
        capturedSync.getValue().afterCompletion(Status.STATUS_COMMITTED);
    }
    verify(tx, never()).rollback();
    verify(tx).commit();
    assertNull(TransactionalBatcher.getCurrentBatch());
}
Also used : Transaction(javax.transaction.Transaction) Synchronization(javax.transaction.Synchronization) Test(org.junit.Test)

Aggregations

Synchronization (javax.transaction.Synchronization)87 Test (org.junit.Test)42 Transaction (javax.transaction.Transaction)23 SystemException (javax.transaction.SystemException)21 RollbackException (javax.transaction.RollbackException)14 SQLException (java.sql.SQLException)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)7 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 UserTransaction (javax.transaction.UserTransaction)5 XAResource (javax.transaction.xa.XAResource)5 EJBException (javax.ejb.EJBException)4 HeuristicMixedException (javax.transaction.HeuristicMixedException)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)3 List (java.util.List)3 Xid (javax.transaction.xa.Xid)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3