use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class LockReleaser method dumpLocks.
// non thread safe but let exception be thrown instead of risking deadlock
public void dumpLocks() {
System.out.print("Locks held: ");
java.util.Iterator<?> itr = lockMap.keySet().iterator();
if (!itr.hasNext()) {
System.out.println("NONE");
} else {
System.out.println();
}
while (itr.hasNext()) {
Transaction transaction = (Transaction) itr.next();
System.out.println("" + transaction + "->" + lockMap.get(transaction).size());
}
}
use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class LockReleaser method rollback.
public void rollback() {
Transaction tx = getTransaction();
// propertyIndex
propertyIndexManager.rollback(tx);
releaseCows(tx, Status.STATUS_ROLLEDBACK);
releaseLocks(tx);
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class TestJtaCompliance method testSuspendResume.
/**
* o Tests that suspend temporarily suspends the transaction associated with
* the calling thread. o Tests that resume reinstate the transaction with
* the calling thread. o Tests that an invalid transaction passed to resume
* won't be associated with the calling thread. o Tests that XAResource.end
* is invoked with TMSUSPEND when transaction is suspended. o Tests that
* XAResource.start is invoked with TMRESUME when transaction is resumed.
*
* TODO: o Test that resume throws an exception if the transaction is
* already associated with another thread. o Test if a suspended thread may
* be resumed by another thread.
*/
@Test
public void testSuspendResume() throws Exception {
tm.begin();
Transaction tx = tm.getTransaction();
FakeXAResource res = new FakeXAResource("XAResource1");
tx.enlistResource(res);
// suspend
assertTrue(tm.suspend() == tx);
tx.delistResource(res, XAResource.TMSUSPEND);
MethodCall[] calls = res.getAndRemoveMethodCalls();
assertEquals(2, calls.length);
assertEquals("start", calls[0].getMethodName());
Object[] args = calls[0].getArgs();
assertEquals(XAResource.TMNOFLAGS, ((Integer) args[1]).intValue());
assertEquals("end", calls[1].getMethodName());
args = calls[1].getArgs();
assertEquals(XAResource.TMSUSPEND, ((Integer) args[1]).intValue());
// resume
tm.resume(tx);
tx.enlistResource(res);
calls = res.getAndRemoveMethodCalls();
assertEquals(1, calls.length);
assertEquals("start", calls[0].getMethodName());
args = calls[0].getArgs();
assertEquals(XAResource.TMRESUME, ((Integer) args[1]).intValue());
assertTrue(tm.getTransaction() == tx);
tx.delistResource(res, XAResource.TMSUCCESS);
tm.commit();
tm.resume(tx);
assertTrue(tm.getStatus() == Status.STATUS_NO_TRANSACTION);
assertTrue(tm.getTransaction() == null);
// tm.resume( my fake implementation of transaction );
// assertTrue( tm.getStatus() == Status.STATUS_NO_TRANSACTION );
// assertTrue( tm.getTransaction() == null );
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class TestJtaCompliance method testTransactionHook.
/**
* o Tests that beforeCompletion and afterCompletion are invoked. o Tests
* that the call is made in the same transaction context. o Tests status in
* before and after methods depending on commit/rollback.
*
* NOTE: Not sure if the check of Status is correct according to
* specification.
*/
@Test
public void testTransactionHook() throws Exception {
// test for commit
tm.begin();
Transaction tx = tm.getTransaction();
TxHook txHook = new TxHook();
tx.registerSynchronization(txHook);
assertEquals(false, txHook.gotBefore);
assertEquals(false, txHook.gotAfter);
tm.commit();
assertEquals(true, txHook.gotBefore);
assertEquals(true, txHook.gotAfter);
assertTrue(tx == txHook.txBefore);
assertTrue(tx == txHook.txAfter);
assertEquals(Status.STATUS_ACTIVE, txHook.statusBefore);
assertEquals(Status.STATUS_COMMITTED, txHook.statusAfter);
// test for rollback
tm.begin();
tx = tm.getTransaction();
txHook = new TxHook();
tx.registerSynchronization(txHook);
assertEquals(false, txHook.gotBefore);
assertEquals(false, txHook.gotAfter);
tm.rollback();
assertEquals(true, txHook.gotBefore);
assertEquals(true, txHook.gotAfter);
assertTrue(tx == txHook.txBefore);
assertTrue(tx == txHook.txAfter);
assertEquals(Status.STATUS_MARKED_ROLLBACK, txHook.statusBefore);
assertEquals(Status.STATUS_ROLLEDBACK, txHook.statusAfter);
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class PropertyIndexManager method createPropertyIndex.
// concurent transactions may create duplicate keys, oh well
PropertyIndex createPropertyIndex(String key) {
Transaction tx = getTransaction();
if (tx == null) {
throw new NotInTransactionException("Unable to create property index for " + key);
}
TxCommitHook hook = txCommitHooks.get(tx);
if (hook == null) {
hook = new TxCommitHook();
txCommitHooks.put(tx, hook);
}
PropertyIndex index = hook.getIndex(key);
if (index != null) {
return index;
}
int id = (int) idGenerator.nextId(PropertyIndex.class);
index = new PropertyIndex(key, id);
hook.addIndex(index);
persistenceManager.createPropertyIndex(key, id);
return index;
}
Aggregations