Search in sources :

Example 36 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project graphdb by neo4j-attic.

the class TestNode method testNodeCreateAndDelete.

@Test
public void testNodeCreateAndDelete() {
    long nodeId = -1;
    Node node = getGraphDb().createNode();
    nodeId = node.getId();
    getGraphDb().getNodeById(nodeId);
    node.delete();
    Transaction tx = getTransaction();
    tx.success();
    tx.finish();
    setTransaction(getGraphDb().beginTx());
    try {
        getGraphDb().getNodeById(nodeId);
        fail("Node[" + nodeId + "] should be deleted.");
    } catch (NotFoundException e) {
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 37 with NotFoundException

use of org.neo4j.graphdb.NotFoundException in project graphdb by neo4j-attic.

the class TestNeo4jConstrains method testDeleteReferenceNodeOrLastNodeIsOk.

@Test
public void testDeleteReferenceNodeOrLastNodeIsOk() {
    Transaction tx = getTransaction();
    for (int i = 0; i < 10; i++) {
        getGraphDb().createNode();
    }
    // empty the DB instance
    for (Node node : getGraphDb().getAllNodes()) {
        for (Relationship rel : node.getRelationships()) {
            rel.delete();
        }
        node.delete();
    }
    tx.success();
    tx.finish();
    tx = getGraphDb().beginTx();
    // the DB should be empty
    // long numNodesPost = getNodeManager().getNumberOfIdsInUse( Node.class
    // );
    // System.out.println(String.format( "pre: %d, post: %d", numNodesPre,
    // numNodesPost ));
    assertFalse(getGraphDb().getAllNodes().iterator().hasNext());
    // assertEquals( 0, numNodesPost );
    try {
        getGraphDb().getReferenceNode();
        fail();
    } catch (NotFoundException nfe) {
    // should be thrown
    }
    tx.success();
    tx.finish();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 38 with NotFoundException

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

the class BatchGraphDatabaseImpl method getNodeById.

public Node getNodeById(long id) {
    NodeBatchImpl node = nodes.get(id);
    if (node == null) {
        try {
            node = new NodeBatchImpl(id, this, batchInserter.getNodeProperties(id));
            nodes.put(id, node);
        } catch (InvalidRecordException e) {
            throw new NotFoundException(e);
        }
    }
    return node;
}
Also used : NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 39 with NotFoundException

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

the class NodeImpl method getSingleRelationship.

public Relationship getSingleRelationship(NodeManager nodeManager, RelationshipType type, Direction dir) {
    DirectionWrapper direction = RelIdArray.wrap(dir);
    RelationshipType[] types = new RelationshipType[] { type };
    Iterator<Relationship> rels = new IntArrayIterator(getAllRelationshipsOfType(nodeManager, direction, types), this, direction, nodeManager, types, !hasMoreRelationshipsToLoad());
    if (!rels.hasNext()) {
        return null;
    }
    Relationship rel = rels.next();
    if (rels.hasNext()) {
        throw new NotFoundException("More than one relationship[" + type + ", " + dir + "] found for " + this);
    }
    return rel;
}
Also used : DirectionWrapper(org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 40 with NotFoundException

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

the class BatchGraphDatabaseImpl method getRelationshipById.

public Relationship getRelationshipById(long id) {
    RelationshipBatchImpl rel = rels.get(id);
    if (rel == null) {
        try {
            SimpleRelationship simpleRel = batchInserter.getRelationshipById(id);
            Map<String, Object> props = batchInserter.getRelationshipProperties(id);
            rel = new RelationshipBatchImpl(simpleRel, this, props);
            rels.put(id, rel);
        } catch (InvalidRecordException e) {
            throw new NotFoundException(e);
        }
    }
    return rel;
}
Also used : NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

NotFoundException (org.neo4j.graphdb.NotFoundException)87 Node (org.neo4j.graphdb.Node)43 Test (org.junit.Test)36 Relationship (org.neo4j.graphdb.Relationship)24 Transaction (org.neo4j.graphdb.Transaction)24 Statement (org.neo4j.kernel.api.Statement)18 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 ReentrantLock (java.util.concurrent.locks.ReentrantLock)8 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)7 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)7 RelationshipType (org.neo4j.graphdb.RelationshipType)5 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)4 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)4 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)4 Race (org.neo4j.test.Race)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3