use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method connect.
private void connect(NodeRecord node, RelationshipRecord rel) {
if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(node.getNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(node.getNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(node.getNextRel());
addRelationshipRecord(nextRel);
}
boolean changed = false;
if (nextRel.getFirstNode() == node.getId()) {
nextRel.setFirstPrevRel(rel.getId());
changed = true;
}
if (nextRel.getSecondNode() == node.getId()) {
nextRel.setSecondPrevRel(rel.getId());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(node + " dont match " + nextRel);
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method doPrepare.
@Override
protected void doPrepare() throws XAException {
if (committed) {
throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
}
if (prepared) {
throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
}
// generate records then write to logical log via addCommand method
prepared = true;
for (RelationshipTypeRecord record : relTypeRecords.values()) {
Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
relTypeCommands.add(command);
addCommand(command);
}
for (NodeRecord record : nodeRecords.values()) {
if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
throw new InvalidRecordException("Node record " + record + " still has relationships");
}
Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
nodeCommands.add(command);
if (!record.inUse()) {
removeNodeFromCache(record.getId());
}
addCommand(command);
}
for (RelationshipRecord record : relRecords.values()) {
Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
relCommands.add(command);
if (!record.inUse()) {
removeRelationshipFromCache(record.getId());
}
addCommand(command);
}
for (PropertyIndexRecord record : propIndexRecords.values()) {
Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
propIndexCommands.add(command);
addCommand(command);
}
for (PropertyRecord record : propertyRecords.values()) {
Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
propCommands.add(command);
addCommand(command);
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relLoadLight.
@Override
public RelationshipRecord relLoadLight(long id) {
RelationshipRecord relRecord = getRelationshipRecord(id);
if (relRecord != null) {
// }
return relRecord;
}
relRecord = getRelationshipStore().getLightRel(id);
if (relRecord != null) {
return relRecord;
}
return null;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
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;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method createRelationship.
public long createRelationship(long node1, long node2, RelationshipType type, Map<String, Object> properties) {
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;
}
Aggregations