Example #1
0
 @Override
 public BatchRelationship getRelationshipById(long relId) {
   RelationshipRecord record = getRelationshipRecord(relId);
   RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(record.getType()));
   return new BatchRelationship(
       record.getId(), record.getFirstNode(), record.getSecondNode(), type);
 }
Example #2
0
 @Override
 public BatchRelationship apply(RelationshipRecord relRecord) {
   RelationshipType type =
       new RelationshipTypeImpl(relationshipTypeTokens.nameOf(relRecord.getType()));
   return new BatchRelationship(
       relRecord.getId(), relRecord.getFirstNode(), relRecord.getSecondNode(), type);
 }
Example #3
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;
 }
Example #4
0
 private void receiveRelationships(
     Iterable<RelationshipRecord> rels,
     ArrayMap<Integer, RelIdArray> newRelationshipMap,
     List<RelationshipImpl> relsList,
     DirectionWrapper dir,
     boolean hasLoops) {
   for (RelationshipRecord rel : rels) {
     long relId = rel.getId();
     RelationshipImpl relImpl = relCache.get(relId);
     RelationshipType type = null;
     int typeId;
     if (relImpl == null) {
       typeId = rel.getType();
       type = getRelationshipTypeById(typeId);
       assert type != null;
       relImpl =
           newRelationshipImpl(
               relId, rel.getFirstNode(), rel.getSecondNode(), type, typeId, false);
       relsList.add(relImpl);
     } else {
       typeId = relImpl.getTypeId();
       type = getRelationshipTypeById(typeId);
     }
     RelIdArray relationshipSet = newRelationshipMap.get(typeId);
     if (relationshipSet == null) {
       relationshipSet = hasLoops ? new RelIdArrayWithLoops(typeId) : new RelIdArray(typeId);
       newRelationshipMap.put(typeId, relationshipSet);
     }
     relationshipSet.add(relId, dir);
   }
 }
Example #5
0
 protected Relationship getRelationshipByIdOrNull(long relId) {
   RelationshipImpl relationship = relCache.get(relId);
   if (relationship != null) {
     return new RelationshipProxy(relId, relationshipLookups);
   }
   ReentrantLock loadLock = lockId(relId);
   try {
     relationship = relCache.get(relId);
     if (relationship != null) {
       return new RelationshipProxy(relId, relationshipLookups);
     }
     RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
     if (data == null) {
       return null;
     }
     int typeId = data.getType();
     RelationshipType type = getRelationshipTypeById(typeId);
     if (type == null) {
       throw new NotFoundException(
           "Relationship["
               + data.getId()
               + "] exist but relationship type["
               + typeId
               + "] not found.");
     }
     final long startNodeId = data.getFirstNode();
     final long endNodeId = data.getSecondNode();
     relationship = newRelationshipImpl(relId, startNodeId, endNodeId, type, typeId, false);
     relCache.put(relationship);
     return new RelationshipProxy(relId, relationshipLookups);
   } finally {
     loadLock.unlock();
   }
 }
Example #6
0
 @Override
 public BatchRelationship getRelationshipById(long relId) {
   RelationshipRecord record = getRelationshipRecord(relId).forReadingData();
   RelationshipType type =
       new RelationshipTypeImpl(relationshipTypeTokens.nameOf(record.getType()));
   return new BatchRelationship(
       record.getId(), record.getFirstNode(), record.getSecondNode(), type);
 }
Example #7
0
 private void connectRelationshipToDenseNode(
     NodeRecord node,
     RelationshipRecord rel,
     RecordAccess<Long, RelationshipRecord, Void> relRecords,
     RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
   RelationshipGroupRecord group =
       relGroupGetter
           .getOrCreateRelationshipGroup(node, rel.getType(), relGroupRecords)
           .forChangingData();
   RelIdArray.DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, node);
   long nextRel = dir.getNextRel(group);
   setCorrectNextRel(node, rel, nextRel);
   connect(node.getId(), nextRel, rel, relRecords);
   dir.setNextRel(group, rel.getId());
 }
Example #8
0
 public RelationshipImpl getRelationshipForProxy(long relId, LockType lock) {
   if (lock != null) {
     lock.acquire(getTransactionState(), new RelationshipProxy(relId, relationshipLookups));
   }
   RelationshipImpl relationship = relCache.get(relId);
   if (relationship != null) {
     return relationship;
   }
   ReentrantLock loadLock = lockId(relId);
   try {
     relationship = relCache.get(relId);
     if (relationship != null) {
       return relationship;
     }
     RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
     if (data == null) {
       throw new NotFoundException(format("Relationship %d not found", relId));
     }
     int typeId = data.getType();
     RelationshipType type = getRelationshipTypeById(typeId);
     if (type == null) {
       throw new NotFoundException(
           "Relationship["
               + data.getId()
               + "] exist but relationship type["
               + typeId
               + "] not found.");
     }
     relationship =
         newRelationshipImpl(
             relId, data.getFirstNode(), data.getSecondNode(), type, typeId, false);
     // relCache.put( relId, relationship );
     relCache.put(relationship);
     return relationship;
   } finally {
     loadLock.unlock();
   }
 }