Search in sources :

Example 31 with NotFoundException

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

the class ValueNode method pack.

public static void pack(Neo4jPack.Packer packer, Node node) throws IOException {
    //TODO: We should mark deleted nodes properly but that requires updates to protocol and
    //clients. Until that we merely don't fail and return a node with neither labels nor properties
    packer.packStructHeader(STRUCT_FIELD_COUNT, Neo4jPack.NODE);
    packer.pack(node.getId());
    try {
        //read labels and properties, will fail if node has been deleted
        Collection<Label> collectedLabels = Iterables.asList(node.getLabels());
        Map<String, Object> props = node.getAllProperties();
        packer.packListHeader(collectedLabels.size());
        for (Label label : collectedLabels) {
            packer.pack(label.name());
        }
        packer.packRawMap(props);
    } catch (NotFoundException e) {
        //node is deleted, just send along an empty node
        packer.packListHeader(0);
        packer.packRawMap(Collections.emptyMap());
    }
}
Also used : Label(org.neo4j.graphdb.Label) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 32 with NotFoundException

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

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 33 with NotFoundException

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

the class NodeProxyTest method shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode.

@Test
public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode() throws Exception {
    // Given a database with PROPERTY_KEY in it
    createNodeWith(PROPERTY_KEY);
    // When trying to get property from node without it
    try (Transaction ignored = db.beginTx()) {
        Node node = db.createNode();
        node.getProperty(PROPERTY_KEY);
        fail("Expected exception to have been thrown");
    }// Then
     catch (NotFoundException exception) {
        assertThat(exception.getMessage(), containsString(PROPERTY_KEY));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 34 with NotFoundException

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

the class NodeTest method testNodeChangeProperty.

@Test
public void testNodeChangeProperty() {
    String key1 = "key1";
    String key2 = "key2";
    String key3 = "key3";
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    String string1 = new String("1");
    String string2 = new String("2");
    Boolean bool1 = new Boolean(true);
    Boolean bool2 = new Boolean(false);
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    node1.setProperty(key1, int1);
    node2.setProperty(key1, string1);
    node1.setProperty(key2, string2);
    node2.setProperty(key2, int2);
    try {
        node1.setProperty(null, null);
        fail("Null argument should result in exception.");
    } catch (IllegalArgumentException ignored) {
    } catch (NotFoundException e) {
        fail("wrong exception");
    }
    // test change property
    node1.setProperty(key1, int2);
    node2.setProperty(key1, string2);
    assertEquals(string2, node2.getProperty(key1));
    node1.setProperty(key3, bool1);
    node1.setProperty(key3, bool2);
    assertEquals(string2, node2.getProperty(key1));
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 35 with NotFoundException

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

the class FunctionalTestPlugin method getOrCreateANode.

private Node getOrCreateANode(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        Node node;
        try {
            node = db.getNodeById(0L);
        } catch (NotFoundException e) {
            node = db.createNode();
        }
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException)

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