Exemplo n.º 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);
    }
  }
Exemplo n.º 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);
   }
 }
Exemplo n.º 3
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());
    }
  }
Exemplo n.º 4
0
 @Override
 void set(RelationshipRecord rel, long id, boolean isFirst) {
   rel.setSecondPrevRel(id);
   rel.setFirstInSecondChain(isFirst);
 }