Search in sources :

Example 61 with NotFoundException

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

the class NodeImpl method getSingleRelationship.

public Relationship getSingleRelationship(NodeManager nodeManager, RelationshipType type, Direction dir) {
    RelationshipType[] types = new RelationshipType[] { type };
    Iterator<Relationship> rels = new IntArrayIterator(getAllRelationshipsOfType(nodeManager, types), this, dir, nodeManager, types);
    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 : Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 62 with NotFoundException

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

the class NodeManager method getRelationshipById.

public Relationship getRelationshipById(long relId) throws NotFoundException {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return new RelationshipProxy(relId, this);
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return new RelationshipProxy(relId, this);
        }
        RelationshipData data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "]");
        }
        int typeId = data.relationshipType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        final long startNodeId = data.firstNode();
        final long endNodeId = data.secondNode();
        relationship = new RelationshipImpl(relId, startNodeId, endNodeId, type, false);
        relCache.put(relId, relationship);
        return new RelationshipProxy(relId, this);
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 63 with NotFoundException

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

the class NodeManager method getNodeById.

public Node getNodeById(long nodeId) throws NotFoundException {
    NodeImpl node = nodeCache.get(nodeId);
    if (node != null) {
        return new NodeProxy(nodeId, this);
    }
    ReentrantLock loadLock = lockId(nodeId);
    try {
        if (nodeCache.get(nodeId) != null) {
            return new NodeProxy(nodeId, this);
        }
        if (!persistenceManager.loadLightNode(nodeId)) {
            throw new NotFoundException("Node[" + nodeId + "]");
        }
        node = new NodeImpl(nodeId);
        nodeCache.put(nodeId, node);
        return new NodeProxy(nodeId, this);
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 64 with NotFoundException

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

the class TestRelationship method testRelationshipRemoveProperty.

@Test
public void testRelationshipRemoveProperty() {
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string1 = new String("1");
    String string2 = new String("2");
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
    // verify that we can rely on PL to reomve non existing properties
    try {
        if (rel1.removeProperty(key1) != null) {
            fail("Remove of non existing property should return null");
        }
    } catch (NotFoundException e) {
    }
    try {
        rel1.removeProperty(null);
        fail("Remove null property should throw exception.");
    } catch (IllegalArgumentException e) {
    }
    rel1.setProperty(key1, int1);
    rel2.setProperty(key1, string1);
    rel1.setProperty(key2, string2);
    rel2.setProperty(key2, int2);
    try {
        rel1.removeProperty(null);
        fail("Null argument should result in exception.");
    } catch (IllegalArgumentException e) {
    }
    // test remove property
    assertEquals(int1, rel1.removeProperty(key1));
    assertEquals(string1, rel2.removeProperty(key1));
    // test remove of non exsisting property
    try {
        if (rel2.removeProperty(key1) != null) {
            fail("Remove of non existing property should return null");
        }
    } catch (NotFoundException e) {
        // have to set rollback only here
        getTransaction().failure();
    }
    rel1.delete();
    rel2.delete();
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 65 with NotFoundException

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

the class TestRelationship method testRelationshipChangeProperty.

@Test
public void testRelationshipChangeProperty() {
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string1 = new String("1");
    String string2 = new String("2");
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
    rel1.setProperty(key1, int1);
    rel2.setProperty(key1, string1);
    rel1.setProperty(key2, string2);
    rel2.setProperty(key2, int2);
    try {
        rel1.setProperty(null, null);
        fail("Null argument should result in exception.");
    } catch (IllegalArgumentException e) {
    } catch (NotFoundException e) {
        fail("wrong exception");
    }
    // test type change of exsisting property
    // cannot test this for now because of exceptions in PL
    rel2.setProperty(key1, int1);
    rel1.delete();
    rel2.delete();
    node2.delete();
    node1.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

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