use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class BatchInserterImpl method getRelationships.
public Iterable<SimpleRelationship> getRelationships(long nodeId) {
NodeRecord nodeRecord = getNodeRecord(nodeId);
long nextRel = nodeRecord.getNextRel();
List<SimpleRelationship> rels = new ArrayList<SimpleRelationship>();
while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord relRecord = getRelationshipRecord(nextRel);
RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(relRecord.getType()));
rels.add(new SimpleRelationship(relRecord.getId(), relRecord.getFirstNode(), relRecord.getSecondNode(), type));
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (firstNode == nodeId) {
nextRel = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
nextRel = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
}
}
return rels;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class BatchInserterImpl method createRelationship.
public long createRelationship(long node1, long node2, RelationshipType type, Map<String, Object> properties) {
if (node1 == node2) {
throw new IllegalArgumentException("Start node[" + node1 + "] equals end node[" + node2 + "]");
}
NodeRecord firstNode = getNodeRecord(node1);
NodeRecord secondNode = getNodeRecord(node2);
int typeId = typeHolder.getTypeId(type.name());
if (typeId == -1) {
typeId = createNewRelationshipType(type.name());
}
long id = getRelationshipStore().nextId();
RelationshipRecord record = new RelationshipRecord(id, node1, node2, typeId);
record.setInUse(true);
record.setCreated();
connectRelationship(firstNode, secondNode, record);
getNodeStore().updateRecord(firstNode);
getNodeStore().updateRecord(secondNode);
record.setNextProp(createPropertyChain(properties));
getRelationshipStore().updateRecord(record);
return id;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class BatchInserterImpl method getRelationshipById.
public SimpleRelationship getRelationshipById(long relId) {
RelationshipRecord record = getRelationshipRecord(relId);
RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(record.getType()));
return new SimpleRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class BatchInserterImpl method connectRelationship.
private void connectRelationship(NodeRecord firstNode, NodeRecord secondNode, RelationshipRecord rel) {
rel.setFirstNextRel(firstNode.getNextRel());
rel.setSecondNextRel(secondNode.getNextRel());
if (firstNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord nextRel = getRelationshipStore().getRecord(firstNode.getNextRel());
if (nextRel.getFirstNode() == firstNode.getId()) {
nextRel.setFirstPrevRel(rel.getId());
} else if (nextRel.getSecondNode() == firstNode.getId()) {
nextRel.setSecondPrevRel(rel.getId());
} else {
throw new InvalidRecordException(firstNode + " dont match " + nextRel);
}
getRelationshipStore().updateRecord(nextRel);
}
if (secondNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord nextRel = getRelationshipStore().getRecord(secondNode.getNextRel());
if (nextRel.getFirstNode() == secondNode.getId()) {
nextRel.setFirstPrevRel(rel.getId());
} else if (nextRel.getSecondNode() == secondNode.getId()) {
nextRel.setSecondPrevRel(rel.getId());
} else {
throw new InvalidRecordException(secondNode + " dont match " + nextRel);
}
getRelationshipStore().updateRecord(nextRel);
}
firstNode.setNextRel(rel.getId());
secondNode.setNextRel(rel.getId());
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class BatchInserterImpl method getRelationshipIds.
public Iterable<Long> getRelationshipIds(long nodeId) {
NodeRecord nodeRecord = getNodeRecord(nodeId);
long nextRel = nodeRecord.getNextRel();
List<Long> ids = new ArrayList<Long>();
while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord relRecord = getRelationshipRecord(nextRel);
ids.add(relRecord.getId());
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (firstNode == nodeId) {
nextRel = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
nextRel = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
}
}
return ids;
}
Aggregations