use of org.neo4j.graphdb.RelationshipType 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.RelationshipType in project graphdb by neo4j-attic.
the class NodeManager method getMoreRelationships.
Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> getMoreRelationships(NodeImpl node) {
long nodeId = node.getId();
RelationshipChainPosition position = node.getRelChainPosition();
Iterable<RelationshipData> rels = persistenceManager.getMoreRelationships(nodeId, position);
ArrayMap<String, RelIdArray> newRelationshipMap = new ArrayMap<String, RelIdArray>();
Map<Long, RelationshipImpl> relsMap = new HashMap<Long, RelationshipImpl>(150);
for (RelationshipData rel : rels) {
long relId = rel.getId();
RelationshipImpl relImpl = relCache.get(relId);
RelationshipType type = null;
if (relImpl == null) {
type = getRelationshipTypeById(rel.relationshipType());
assert type != null;
relImpl = new RelationshipImpl(relId, rel.firstNode(), rel.secondNode(), type, false);
relsMap.put(relId, relImpl);
// relCache.put( relId, relImpl );
} else {
type = relImpl.getType();
}
RelIdArray relationshipSet = newRelationshipMap.get(type.name());
if (relationshipSet == null) {
relationshipSet = new RelIdArray();
newRelationshipMap.put(type.name(), relationshipSet);
}
relationshipSet.add(relId);
}
// relCache.putAll( relsMap );
return Pair.of(newRelationshipMap, relsMap);
}
use of org.neo4j.graphdb.RelationshipType 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.RelationshipType in project graphdb by neo4j-attic.
the class TestTraversal method testMultiRelDepthTraversal.
// Traverses the test "ise-tree-like" population depth first,
// but only traverses "ise" relationships (the population also contains
// "ise_clone" rels)
@Test
public void testMultiRelDepthTraversal() throws Exception {
Node root = this.buildIseTreePopulation();
RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST };
Traverser traverser = root.traverse(DEPTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, traversableRels[0], Direction.BOTH);
try {
assertNodes(traverser, "1", "2", "3", "4", "5", "6", "7", "10", "11", "12", "13");
assertTrue("Too many nodes returned from traversal", traverser.iterator().hasNext() == false);
} catch (java.util.NoSuchElementException nsee) {
fail("Too few nodes returned from traversal");
} finally {
this.deleteNodeTreeRecursively(root, 0);
}
}
use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.
the class CircularGraphTest method testCircularBug.
@Test
public void testCircularBug() {
final long timestamp = 3;
Transaction tx = beginTx();
getNodeWithName("2").setProperty("timestamp", 1L);
getNodeWithName("3").setProperty("timestamp", 2L);
tx.success();
tx.finish();
final RelationshipType type = DynamicRelationshipType.withName("TO");
Traverser t = referenceNode().traverse(Order.DEPTH_FIRST, new StopEvaluator() {
public boolean isStopNode(TraversalPosition position) {
Relationship last = position.lastRelationshipTraversed();
if (last != null && last.isType(type)) {
Node node = position.currentNode();
long currentTime = (Long) node.getProperty("timestamp");
return currentTime >= timestamp;
}
return false;
}
}, new ReturnableEvaluator() {
public boolean isReturnableNode(TraversalPosition position) {
Relationship last = position.lastRelationshipTraversed();
if (last != null && last.isType(type)) {
return true;
}
return false;
}
}, type, Direction.OUTGOING);
Iterator<Node> nodes = t.iterator();
assertEquals("2", nodes.next().getProperty("name"));
assertEquals("3", nodes.next().getProperty("name"));
assertFalse(nodes.hasNext());
}
Aggregations