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