Esempio n. 1
0
 public Iterable<SimpleRelationship> getSimpleRelationships(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;
 }
Esempio n. 2
0
 @Override
 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;
 }
Esempio n. 3
0
 @Override
 public void invalidateCache(CacheAccessBackDoor cacheAccess) {
   cacheAccess.removeRelationshipFromCache(getKey());
   /*
    * If isRecovered() then beforeUpdate is the correct one UNLESS this is the second time this command
    * is executed, where it might have been actually written out to disk so the fields are already -1. So
    * we still need to check.
    * If !isRecovered() then beforeUpdate is the same as record, so we are still ok.
    * We don't check for !inUse() though because that is implicit in the call of this method.
    * The above is a hand waiving proof that the conditions that lead to the patchDeletedRelationshipNodes()
    * in the if below are the same as in RelationshipCommand.execute() so it should be safe.
    */
   if (beforeUpdate.getFirstNode() != -1 || beforeUpdate.getSecondNode() != -1) {
     cacheAccess.patchDeletedRelationshipNodes(
         getKey(),
         beforeUpdate.getFirstNode(),
         beforeUpdate.getFirstNextRel(),
         beforeUpdate.getSecondNode(),
         beforeUpdate.getSecondNextRel());
   }
   if (record.getFirstNode() != -1 || record.getSecondNode() != -1) {
     cacheAccess.removeNodeFromCache(record.getFirstNode());
     cacheAccess.removeNodeFromCache(record.getSecondNode());
   }
 }
Esempio n. 4
0
 @Override
 long get(RelationshipRecord rel) {
   return rel.getFirstNextRel();
 }