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;
}
}
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;
}
}
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());
}
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());
}
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());
}
Aggregations