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());
}
}
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();
}
}
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));
}
}
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();
}
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;
}
}
Aggregations