示例#1
0
  private void connectRelationship(
      NodeRecord firstNode,
      NodeRecord secondNode,
      RelationshipRecord rel,
      RecordAccess<Long, RelationshipRecord, Void> relRecords,
      RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
    // Assertion interpreted: if node is a normal node and we're trying to create a
    // relationship that we already have as first rel for that node --> error
    assert firstNode.getNextRel() != rel.getId() || firstNode.isDense();
    assert secondNode.getNextRel() != rel.getId() || secondNode.isDense();

    if (!firstNode.isDense()) {
      rel.setFirstNextRel(firstNode.getNextRel());
    }
    if (!secondNode.isDense()) {
      rel.setSecondNextRel(secondNode.getNextRel());
    }

    if (!firstNode.isDense()) {
      connect(firstNode, rel, relRecords);
    } else {
      connectRelationshipToDenseNode(firstNode, rel, relRecords, relGroupRecords);
    }

    if (!secondNode.isDense()) {
      if (firstNode.getId() != secondNode.getId()) {
        connect(secondNode, rel, relRecords);
      } else {
        rel.setFirstInFirstChain(true);
        rel.setSecondPrevRel(rel.getFirstPrevRel());
      }
    } else if (firstNode.getId() != secondNode.getId()) {
      connectRelationshipToDenseNode(secondNode, rel, relRecords, relGroupRecords);
    }

    if (!firstNode.isDense()) {
      firstNode.setNextRel(rel.getId());
    }
    if (!secondNode.isDense()) {
      secondNode.setNextRel(rel.getId());
    }
  }
示例#2
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);
    }
  }
示例#3
0
 @Override
 long get(RelationshipRecord rel) {
   return rel.isFirstInFirstChain()
       ? Record.NO_NEXT_RELATIONSHIP.intValue()
       : rel.getFirstPrevRel();
 }