use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.
the class ReadTransaction method getMoreRelationships.
public Iterable<RelationshipData> getMoreRelationships(long nodeId, RelationshipChainPosition position) {
long nextRel = position.getNextRecord();
List<RelationshipData> rels = new ArrayList<RelationshipData>();
for (int i = 0; i < getRelGrabSize() && nextRel != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = getRelationshipStore().getChainRecord(nextRel);
if (relRecord == null) {
// return what we got so far
position.setNextRecord(Record.NO_NEXT_RELATIONSHIP.intValue());
return rels;
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (relRecord.inUse()) {
rels.add(new RelationshipData(relRecord.getId(), firstNode, secondNode, relRecord.getType()));
} else {
i--;
}
if (firstNode == nodeId) {
nextRel = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
nextRel = relRecord.getSecondNextRel();
} else {
System.out.println(relRecord);
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
position.setNextRecord(nextRel);
return rels;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.
the class WriteTransaction method relationshipLoad.
public RelationshipData relationshipLoad(long id) {
RelationshipRecord relRecord = getRelationshipRecord(id);
if (relRecord != null) {
// }
return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
}
relRecord = getRelationshipStore().getLightRel(id);
if (relRecord != null) {
return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
}
return null;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.
the class NodeManager method getRelForProxy.
RelationshipImpl getRelForProxy(long relId) {
RelationshipImpl relationship = relCache.get(relId);
if (relationship != null) {
return relationship;
}
ReentrantLock loadLock = lockId(relId);
try {
relationship = relCache.get(relId);
if (relationship != null) {
return relationship;
}
RelationshipData data = persistenceManager.loadLightRelationship(relId);
if (data == null) {
throw new NotFoundException("Relationship[" + relId + "] not found.");
}
int typeId = data.relationshipType();
RelationshipType type = getRelationshipTypeById(typeId);
if (type == null) {
throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
}
relationship = new RelationshipImpl(relId, data.firstNode(), data.secondNode(), type, false);
relCache.put(relId, relationship);
return relationship;
} finally {
loadLock.unlock();
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.
the class WriteTransaction method getMoreRelationships.
public Iterable<RelationshipData> getMoreRelationships(long nodeId, RelationshipChainPosition position) {
long nextRel = position.getNextRecord();
List<RelationshipData> rels = new ArrayList<RelationshipData>();
for (int i = 0; i < getRelGrabSize() && nextRel != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = getRelationshipStore().getChainRecord(nextRel);
if (relRecord == null) {
// return what we got so far
position.setNextRecord(Record.NO_NEXT_RELATIONSHIP.intValue());
return rels;
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (// && !relRecord.isCreated() )
relRecord.inUse()) {
rels.add(new RelationshipData(relRecord.getId(), firstNode, secondNode, relRecord.getType()));
} else {
i--;
}
if (firstNode == nodeId) {
nextRel = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
nextRel = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
position.setNextRecord(nextRel);
return rels;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipData 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);
}
Aggregations