Search in sources :

Example 11 with NotInTransactionException

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

the class PersistenceManager method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    NeoStoreTransaction con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
        } catch (SystemException e) {
            throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 12 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 13 with NotInTransactionException

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

the class Neo4j2GraphSpecificTestSuite method testAutoStartTxOnVertexIterables.

public void testAutoStartTxOnVertexIterables() throws Exception {
    Neo4j2Graph graph = (Neo4j2Graph) graphTest.generateGraph();
    Vertex a = graph.addVertex(null);
    Vertex b = graph.addVertex(null);
    graph.addEdge(null, a, b, "testEdge");
    Iterable<Vertex> graphIterable = graph.getVertices();
    Iterable<Vertex> vertexIterable = a.getVertices(Direction.BOTH);
    graph.commit();
    try {
        try {
            assertTrue(graphIterable.iterator().hasNext());
            assertNotNull(graphIterable.iterator().next());
        } catch (NotInTransactionException e) {
            fail("Iterating graph vertex iterable does not auto-start transaction");
        }
        try {
            assertTrue(vertexIterable.iterator().hasNext());
            assertNotNull(vertexIterable.iterator().next());
        } catch (NotInTransactionException e) {
            fail("Iterating vertex iterable does not auto-start transaction");
        }
    } finally {
        graph.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 14 with NotInTransactionException

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

the class Neo4j2GraphSpecificTestSuite method testAutoStartTxOnEdgeIterables.

public void testAutoStartTxOnEdgeIterables() throws Exception {
    Neo4j2Graph graph = (Neo4j2Graph) graphTest.generateGraph();
    Vertex a = graph.addVertex(null);
    Vertex b = graph.addVertex(null);
    Neo4j2Edge edge = graph.addEdge(null, a, b, "testEdge");
    edge.setProperty("foo", "bar");
    Iterable<Edge> iterable = graph.getEdges();
    graph.commit();
    try {
        assertTrue(iterable.iterator().hasNext());
        assertNotNull(iterable.iterator().next());
        assertNotNull(graph.getEdges("foo", "bar").iterator().hasNext());
    } catch (NotInTransactionException e) {
        fail("Iterating edge iterable does not auto-start transaction");
    } finally {
        graph.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) Edge(com.tinkerpop.blueprints.Edge)

Example 15 with NotInTransactionException

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

the class LockReleaser method addLockToTransaction.

/**
     * Invoking this method with no transaction running will cause the lock to
     * be released right away.
     *
     * @param resource
     *            the resource on which the lock is taken
     * @param type
     *            type of lock (READ or WRITE)
     * @throws NotInTransactionException
     */
public void addLockToTransaction(Object resource, LockType type) throws NotInTransactionException {
    Transaction tx = getTransaction();
    List<LockElement> lockElements = lockMap.get(tx);
    if (lockElements != null) {
        lockElements.add(new LockElement(resource, type));
    } else {
        if (tx == null) {
            // no transaction we release lock right away
            if (type == LockType.WRITE) {
                lockManager.releaseWriteLock(resource, null);
            } else if (type == LockType.READ) {
                lockManager.releaseReadLock(resource, null);
            }
            return;
        }
        lockElements = new ArrayList<LockElement>();
        lockMap.put(tx, lockElements);
        lockElements.add(new LockElement(resource, type));
        // tx was read only
        try {
            tx.registerSynchronization(new ReadOnlyTxReleaser(tx));
        } catch (Exception e) {
            throw new TransactionFailureException("Failed to register lock release synchronization hook", e);
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(javax.transaction.Transaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Aggregations

NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)24 Transaction (javax.transaction.Transaction)14 SystemException (javax.transaction.SystemException)10 Test (org.junit.Test)6 Node (org.neo4j.graphdb.Node)4 Relationship (org.neo4j.graphdb.Relationship)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4 Vertex (com.tinkerpop.blueprints.Vertex)2 RollbackException (javax.transaction.RollbackException)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)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 XAResource (javax.transaction.xa.XAResource)1 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)1 XaConnection (org.neo4j.kernel.impl.transaction.xaframework.XaConnection)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1