Search in sources :

Example 1 with NotInTransactionException

use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.

the class ProcedureGDBFacadeSPI method currentTransaction.

@Override
public KernelTransaction currentTransaction() {
    availability.assertDatabaseAvailable();
    KernelTransaction tx = sourceModule.threadToTransactionBridge.getKernelTransactionBoundToThisThread(false);
    if (tx == null) {
        throw new NotInTransactionException();
    }
    return tx;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 2 with NotInTransactionException

use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.

the class TransactionConstraintsIT method writeOperationOnSlaveHasToBePerformedWithinTransaction.

@Test
public void writeOperationOnSlaveHasToBePerformedWithinTransaction() throws Exception {
    // GIVEN
    HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
    // WHEN
    try {
        aSlave.createNode();
        fail("Shouldn't be able to do a write operation outside a transaction");
    } catch (NotInTransactionException e) {
    // THEN
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) Test(org.junit.Test)

Example 3 with NotInTransactionException

use of org.neo4j.graphdb.NotInTransactionException in project neo4j by neo4j.

the class TransactionConstraintsIT method writeOperationOnMasterHasToBePerformedWithinTransaction.

@Test
public void writeOperationOnMasterHasToBePerformedWithinTransaction() throws Exception {
    // GIVEN
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    // WHEN
    try {
        master.createNode();
        fail("Shouldn't be able to do a write operation outside a transaction");
    } catch (NotInTransactionException e) {
    // THEN
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) Test(org.junit.Test)

Example 4 with NotInTransactionException

use of org.neo4j.graphdb.NotInTransactionException in project neo4j-mobile-android by neo4j-contrib.

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

Example 5 with NotInTransactionException

use of org.neo4j.graphdb.NotInTransactionException in project neo4j-mobile-android by neo4j-contrib.

the class PersistenceManager method getResource.

private NeoStoreTransaction getResource(boolean registerEventHooks) {
    NeoStoreTransaction con = null;
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    con = txConnectionMap.get(tx);
    if (con == null) {
        try {
            XaConnection xaConnection = persistenceSource.getXaDataSource().getXaConnection();
            XAResource xaResource = xaConnection.getXaResource();
            if (!tx.enlistResource(xaResource)) {
                throw new ResourceAcquisitionFailedException("Unable to enlist '" + xaResource + "' in " + "transaction");
            }
            con = persistenceSource.createTransaction(xaConnection);
            tx.registerSynchronization(new TxCommitHook(tx));
            if (registerEventHooks)
                registerTransactionEventHookIfNeeded();
            txConnectionMap.put(tx, con);
        } catch (javax.transaction.RollbackException re) {
            String msg = "The transaction is marked for rollback only.";
            throw new ResourceAcquisitionFailedException(msg, re);
        } catch (javax.transaction.SystemException se) {
            String msg = "TM encountered an unexpected error condition.";
            throw new ResourceAcquisitionFailedException(msg, se);
        }
    }
    return con;
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) XaConnection(org.neo4j.kernel.impl.transaction.xaframework.XaConnection)

Aggregations

NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)23 Transaction (javax.transaction.Transaction)14 SystemException (javax.transaction.SystemException)10 Test (org.junit.Test)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4 Node (org.neo4j.graphdb.Node)3 Vertex (com.tinkerpop.blueprints.Vertex)2 RollbackException (javax.transaction.RollbackException)2 Relationship (org.neo4j.graphdb.Relationship)2 Transaction (org.neo4j.graphdb.Transaction)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)2 Edge (com.tinkerpop.blueprints.Edge)1 LinkedList (java.util.LinkedList)1 XAResource (javax.transaction.xa.XAResource)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Label (org.neo4j.graphdb.Label)1 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)1 XaConnection (org.neo4j.kernel.impl.transaction.xaframework.XaConnection)1