use of org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper in project neo4j-mobile-android by neo4j-contrib.
the class ReadTransaction method getMoreRelationships.
static Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, Long> getMoreRelationships(long nodeId, long position, int grabSize, RelationshipStore relStore) {
// initialCapacity=grabSize saves the lists the trouble of resizing
List<RelationshipRecord> out = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> in = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> loop = null;
Map<DirectionWrapper, Iterable<RelationshipRecord>> result = new EnumMap<DirectionWrapper, Iterable<RelationshipRecord>>(DirectionWrapper.class);
result.put(DirectionWrapper.OUTGOING, out);
result.put(DirectionWrapper.INCOMING, in);
for (int i = 0; i < grabSize && position != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = relStore.getChainRecord(position);
if (relRecord == null) {
// return what we got so far
return Pair.of(result, position);
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (relRecord.inUse()) {
if (firstNode == secondNode) {
if (loop == null) {
// This is done lazily because loops are probably quite
// rarely encountered
loop = new ArrayList<RelationshipRecord>();
result.put(DirectionWrapper.BOTH, loop);
}
loop.add(relRecord);
} else if (firstNode == nodeId) {
out.add(relRecord);
} else if (secondNode == nodeId) {
in.add(relRecord);
}
} else {
i--;
}
if (firstNode == nodeId) {
position = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
position = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
return Pair.of(result, position);
}
use of org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper in project neo4j-mobile-android by neo4j-contrib.
the class NodeImpl method getRelationships.
public Iterable<Relationship> getRelationships(NodeManager nodeManager, RelationshipType type, Direction dir) {
RelationshipType[] types = new RelationshipType[] { type };
DirectionWrapper direction = RelIdArray.wrap(dir);
return new IntArrayIterator(getAllRelationshipsOfType(nodeManager, direction, types), this, direction, nodeManager, types, !hasMoreRelationshipsToLoad());
}
use of org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper in project neo4j-mobile-android by neo4j-contrib.
the class NodeImpl method getSingleRelationship.
public Relationship getSingleRelationship(NodeManager nodeManager, RelationshipType type, Direction dir) {
DirectionWrapper direction = RelIdArray.wrap(dir);
RelationshipType[] types = new RelationshipType[] { type };
Iterator<Relationship> rels = new IntArrayIterator(getAllRelationshipsOfType(nodeManager, direction, types), this, direction, nodeManager, types, !hasMoreRelationshipsToLoad());
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;
}
Aggregations