Search in sources :

Example 6 with TransactionManager

use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.

the class MasterImpl method suspendOtherAndResumeThis.

Transaction suspendOtherAndResumeThis(SlaveContext txId) {
    try {
        TransactionManager txManager = graphDbConfig.getTxModule().getTxManager();
        Transaction otherTx = txManager.getTransaction();
        Transaction transaction = getTx(txId);
        if (otherTx != null && otherTx == transaction) {
            return null;
        } else {
            if (otherTx != null) {
                txManager.suspend();
            }
            if (transaction == null) {
                beginTx(txId);
            } else {
                txManager.resume(transaction);
            }
            return otherTx;
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 7 with TransactionManager

use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.

the class MasterImpl method beginTx.

private Transaction beginTx(SlaveContext txId) {
    try {
        TransactionManager txManager = graphDbConfig.getTxModule().getTxManager();
        txManager.begin();
        Transaction tx = txManager.getTransaction();
        transactions.put(txId, tx);
        return tx;
    } catch (NotSupportedException e) {
        throw new RuntimeException(e);
    } catch (SystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) NotSupportedException(javax.transaction.NotSupportedException)

Example 8 with TransactionManager

use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.

the class MasterImpl method suspendThisAndResumeOther.

void suspendThisAndResumeOther(Transaction otherTx, SlaveContext txId) {
    try {
        TransactionManager txManager = graphDbConfig.getTxModule().getTxManager();
        txManager.suspend();
        if (otherTx != null) {
            txManager.resume(otherTx);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 9 with TransactionManager

use of javax.transaction.TransactionManager in project neo4j-mobile-android by neo4j-contrib.

the class EmbeddedGraphDbImpl method beginTx.

/**
     * @throws TransactionFailureException if unable to start transaction
     */
public Transaction beginTx() {
    if (graphDbInstance.transactionRunning()) {
        if (placeboTransaction == null) {
            placeboTransaction = new PlaceboTransaction(graphDbInstance.getTransactionManager());
        }
        return placeboTransaction;
    }
    TransactionManager txManager = graphDbInstance.getTransactionManager();
    Transaction result = null;
    try {
        txManager.begin();
        result = new TopLevelTransaction(txManager, txManager.getTransaction());
    } catch (Exception e) {
        throw new TransactionFailureException("Unable to begin transaction", e);
    }
    return result;
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) TransactionManager(javax.transaction.TransactionManager) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) NotFoundException(org.neo4j.graphdb.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with TransactionManager

use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.

the class TestNeo4jCacheAndPersistence method testTxCacheLoadIsolation.

@Test
public void testTxCacheLoadIsolation() throws Exception {
    Node node = getGraphDb().createNode();
    node.setProperty("someproptest", "testing");
    Node node1 = getGraphDb().createNode();
    node1.setProperty("someotherproptest", 2);
    commit();
    EmbeddedGraphDatabase graphDb = (EmbeddedGraphDatabase) getGraphDb();
    TransactionManager txManager = graphDb.getConfig().getTxModule().getTxManager();
    NodeManager nodeManager = graphDb.getConfig().getGraphDbModule().getNodeManager();
    txManager.begin();
    node.setProperty("someotherproptest", "testing2");
    Relationship rel = node.createRelationshipTo(node1, MyRelTypes.TEST);
    javax.transaction.Transaction txA = txManager.suspend();
    txManager.begin();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    javax.transaction.Transaction txB = txManager.suspend();
    txManager.resume(txA);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    nodeManager.clearCache();
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(node.hasProperty("someotherproptest"));
    assertTrue(node.hasRelationship());
    txManager.suspend();
    txManager.resume(txB);
    assertEquals("testing", node.getProperty("someproptest"));
    assertTrue(!node.hasProperty("someotherproptest"));
    assertTrue(!node.hasRelationship());
    txManager.rollback();
    txManager.resume(txA);
    node.delete();
    node1.delete();
    rel.delete();
    txManager.commit();
    newTransaction();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) TransactionManager(javax.transaction.TransactionManager) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

TransactionManager (javax.transaction.TransactionManager)110 Test (org.junit.Test)40 Transaction (javax.transaction.Transaction)24 SystemException (javax.transaction.SystemException)22 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)15 UserTransaction (javax.transaction.UserTransaction)14 JtaTransactionCoordinatorImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)12 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)11 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)9 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)9 Method (java.lang.reflect.Method)7 EntityManager (javax.persistence.EntityManager)7 NotSupportedException (javax.transaction.NotSupportedException)7 RollbackException (javax.transaction.RollbackException)7 SynchronizationCollectorImpl (org.hibernate.test.resource.common.SynchronizationCollectorImpl)6 TestForIssue (org.hibernate.testing.TestForIssue)6 IOException (java.io.IOException)5 InitialContext (javax.naming.InitialContext)5 DataSource (javax.sql.DataSource)5 JtaPlatform (org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform)5