Search in sources :

Example 91 with Transaction

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);
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 92 with Transaction

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;
}
Also used : Transaction(javax.transaction.Transaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) SystemException(javax.transaction.SystemException)

Example 93 with Transaction

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);
    }
}
Also used : LockManager(org.neo4j.kernel.impl.transaction.LockManager) LockReleaser(org.neo4j.kernel.impl.core.LockReleaser) Transaction(javax.transaction.Transaction) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException)

Example 94 with Transaction

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();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) File(java.io.File) Test(org.junit.Test)

Example 95 with Transaction

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);
}
Also used : Transaction(javax.transaction.Transaction) NotSupportedException(javax.transaction.NotSupportedException) Test(org.junit.Test)

Aggregations

Transaction (javax.transaction.Transaction)160 SystemException (javax.transaction.SystemException)55 Test (org.junit.Test)42 RollbackException (javax.transaction.RollbackException)26 TransactionManager (javax.transaction.TransactionManager)24 UserTransaction (javax.transaction.UserTransaction)19 NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)14 NotSupportedException (javax.transaction.NotSupportedException)13 Synchronization (javax.transaction.Synchronization)10 XAResource (javax.transaction.xa.XAResource)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)10 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)8 InvalidTransactionException (javax.transaction.InvalidTransactionException)7 TransactionContext (com.hazelcast.transaction.TransactionContext)6 RemoteException (java.rmi.RemoteException)6 ResourceException (javax.resource.ResourceException)6 ManagedConnection (javax.resource.spi.ManagedConnection)6 SQLException (java.sql.SQLException)5 HeuristicMixedException (javax.transaction.HeuristicMixedException)5 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)5