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 SFSB1 method createEmployeeWaitForTxTimeout.
@TransactionTimeout(value = 1, unit = TimeUnit.SECONDS)
public void createEmployeeWaitForTxTimeout(boolean registerTxSync, String name, String address, int id) {
LOGGER.trace("org.jboss.as.test.integration.jpa.mockprovider.txtimeout.createEmployeeWaitForTxTimeout " + "entered, will wait for tx time out to occur");
Employee emp = new Employee();
emp.setId(id);
emp.setAddress(address);
emp.setName(name);
entityManager.persist(emp);
boolean done = false;
if (registerTxSync) {
transactionSynchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
}
@Override
public void afterCompletion(int status) {
afterCompletionCalledByTMTimeoutThread = TxUtils.isTransactionManagerTimeoutThread();
}
});
}
while (!done) {
try {
Thread.sleep(250);
entityManager.find(Employee.class, id);
int status = transactionSynchronizationRegistry.getTransactionStatus();
switch(status) {
case Status.STATUS_COMMITTED:
throw new RuntimeException("transaction was committed.");
case Status.STATUS_ROLLEDBACK:
LOGGER.trace("tx timed out and rolled back as expected, success case reached.");
done = true;
break;
case Status.STATUS_ACTIVE:
LOGGER.trace("tx is still active, sleep for 250ms and check tx status again.");
break;
default:
LOGGER.trace("tx status = " + status + ", sleep for 250ms and check tx status again.");
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
LOGGER.trace("org.jboss.as.test.integration.jpa.mockprovider.txtimeout.createEmployeeWaitForTxTimeout waiting for tx to timeout");
}
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase 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(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase 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(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createOverlappingBatchClose.
@SuppressWarnings("resource")
@Test
public void createOverlappingBatchClose() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
TransactionBatch batch = this.batcher.createBatch();
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
reset(this.tm);
try {
assertSame(tx, batch.getTransaction());
when(this.tm.getTransaction()).thenReturn(tx);
when(tx.getStatus()).thenReturn(Status.STATUS_ACTIVE);
try (TransactionBatch innerBatch = this.batcher.createBatch()) {
verify(this.tm, never()).begin();
batch.close();
verify(tx, never()).rollback();
verify(tx, never()).commit();
}
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_COMMITTED);
}
verify(tx, never()).rollback();
verify(tx).commit();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
Aggregations