Example #1
0
  private void connect(
      long nodeId,
      long firstRelId,
      RelationshipRecord rel,
      RecordAccess<Long, RelationshipRecord, Void> relRecords) {
    long newCount = 1;
    if (firstRelId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
      locker.getWriteLock(firstRelId);
      RelationshipRecord firstRel = relRecords.getOrLoad(firstRelId, null).forChangingLinkage();
      boolean changed = false;
      if (firstRel.getFirstNode() == nodeId) {
        newCount = firstRel.getFirstPrevRel() + 1;
        firstRel.setFirstPrevRel(rel.getId());
        firstRel.setFirstInFirstChain(false);
        changed = true;
      }
      if (firstRel.getSecondNode() == nodeId) {
        newCount = firstRel.getSecondPrevRel() + 1;
        firstRel.setSecondPrevRel(rel.getId());
        firstRel.setFirstInSecondChain(false);
        changed = true;
      }
      if (!changed) {
        throw new InvalidRecordException(nodeId + " doesn't match " + firstRel);
      }
    }

    // Set the relationship count
    if (rel.getFirstNode() == nodeId) {
      rel.setFirstPrevRel(newCount);
      rel.setFirstInFirstChain(true);
    }
    if (rel.getSecondNode() == nodeId) {
      rel.setSecondPrevRel(newCount);
      rel.setFirstInSecondChain(true);
    }
  }
Example #2
0
 private void connect(NodeRecord node, RelationshipRecord rel) {
   if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
     RelationshipRecord nextRel = getRelationshipStore().getRecord(node.getNextRel());
     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);
     }
     getRelationshipStore().updateRecord(nextRel);
   }
 }
 @Override
 void set(RelationshipRecord rel, long id, boolean isFirst) {
   rel.setFirstPrevRel(id);
   rel.setFirstInFirstChain(isFirst);
 }