use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class IndexConnectionBroker method delistResourcesForTransaction.
void delistResourcesForTransaction() throws NotInTransactionException {
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
T con = txConnectionMap.get(tx);
if (con != null) {
try {
tx.delistResource(con.getXaResource(), XAResource.TMSUCCESS);
} catch (IllegalStateException e) {
throw new RuntimeException("Unable to delist lucene resource from tx", e);
} catch (SystemException e) {
throw new RuntimeException("Unable to delist lucene resource from tx", e);
}
}
}
use of javax.transaction.Transaction in project neo4j-mobile-android by neo4j-contrib.
the class IndexConnectionBroker method acquireResourceConnection.
public T acquireResourceConnection() {
T con = null;
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
con = txConnectionMap.get(tx);
if (con == null) {
try {
con = (T) newConnection();
if (!tx.enlistResource(con.getXaResource())) {
throw new RuntimeException("Unable to enlist '" + con.getXaResource() + "' in " + tx);
}
tx.registerSynchronization(new TxCommitHook(tx));
txConnectionMap.put(tx, con);
} catch (javax.transaction.RollbackException re) {
String msg = "The transaction is marked for rollback only.";
throw new RuntimeException(msg, re);
} catch (javax.transaction.SystemException se) {
String msg = "TM encountered an unexpected error condition.";
throw new RuntimeException(msg, se);
}
}
return con;
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class MasterImpl method acquireLock.
private <T extends PropertyContainer> Response<LockResult> acquireLock(SlaveContext context, LockGrabber lockGrabber, T... entities) {
Transaction otherTx = suspendOtherAndResumeThis(context);
try {
LockManager lockManager = graphDbConfig.getLockManager();
LockReleaser lockReleaser = graphDbConfig.getLockReleaser();
for (T entity : entities) {
lockGrabber.grab(lockManager, lockReleaser, entity);
}
return packResponse(context, new LockResult(LockStatus.OK_LOCKED));
} catch (DeadlockDetectedException e) {
return packResponse(context, new LockResult(e.getMessage()));
} catch (IllegalResourceException e) {
return packResponse(context, new LockResult(LockStatus.NOT_LOCKED));
} finally {
suspendThisAndResumeOther(otherTx, context);
}
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class TestKernelPanic method panicTest.
@Test
public void panicTest() throws Exception {
String path = "target/var/testdb";
AbstractNeo4jTestCase.deleteFileOrDirectory(new File(path));
EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(path);
XaDataSourceManager xaDs = graphDb.getConfig().getTxModule().getXaDataSourceManager();
IllBehavingXaDataSource noob = new IllBehavingXaDataSource();
xaDs.registerDataSource("noob", noob, UTF8.encode("554342"));
Panic panic = new Panic();
graphDb.registerKernelEventHandler(panic);
org.neo4j.graphdb.Transaction gdbTx = graphDb.beginTx();
TransactionManager txMgr = graphDb.getConfig().getTxModule().getTxManager();
Transaction tx = txMgr.getTransaction();
graphDb.createNode();
tx.enlistResource(noob.getXaConnection().getXaResource());
try {
gdbTx.success();
gdbTx.finish();
fail("Should fail");
} catch (Throwable t) {
// ok
for (int i = 0; i < 10 && panic.panic == false; i++) {
Thread.sleep(1000);
}
} finally {
graphDb.unregisterKernelEventHandler(panic);
}
assertTrue(panic.panic);
graphDb.shutdown();
}
use of javax.transaction.Transaction in project graphdb by neo4j-attic.
the class TestJtaCompliance method testNestedTransactions.
/**
* o Tests if nested transactions are supported
*
* TODO: if supported, do some testing :)
*/
@Test
public void testNestedTransactions() throws Exception {
assertTrue(tm.getTransaction() == null);
tm.begin();
Transaction txParent = tm.getTransaction();
assertTrue(txParent != null);
try {
tm.begin();
// ok supported
// some tests that might be valid for true nested support
// Transaction txChild = tm.getTransaction();
// assertTrue( txChild != txParent );
// tm.commit();
// assertTrue( txParent == tm.getTransaction() );
} catch (NotSupportedException e) {
// well no nested transactions
}
tm.commit();
assertTrue(tm.getStatus() == Status.STATUS_NO_TRANSACTION);
}
Aggregations