public RelationshipChainField fieldFor(long nodeId, RelationshipRecord rel) {
   if (rel.getFirstNode() == nodeId) {
     return first;
   } else if (rel.getSecondNode() == nodeId) {
     return second;
   }
   throw new IllegalArgumentException(format("%s does not reference node %d", rel, nodeId));
 }
Пример #2
0
 @Override
 public boolean visitRelationshipCommand(Command.RelationshipCommand command) throws IOException {
   RelationshipRecord record = command.getRecord();
   byte flags =
       bitFlags(
           bitFlag(record.inUse(), Record.IN_USE.byteValue()),
           bitFlag(record.isCreated(), Record.CREATED_IN_TX));
   channel.put(NeoCommandType.REL_COMMAND);
   channel.putLong(record.getId());
   channel.put(flags);
   if (record.inUse()) {
     channel
         .putLong(record.getFirstNode())
         .putLong(record.getSecondNode())
         .putInt(record.getType())
         .putLong(record.getFirstPrevRel())
         .putLong(record.getFirstNextRel())
         .putLong(record.getSecondPrevRel())
         .putLong(record.getSecondNextRel())
         .putLong(record.getNextProp())
         .put(
             (byte)
                 ((record.isFirstInFirstChain() ? 1 : 0)
                     | (record.isFirstInSecondChain() ? 2 : 0)));
   } else {
     channel.putInt(record.getType());
   }
   return false;
 }
    @Override
    public boolean visitRelationshipCommand(Command.RelationshipCommand command)
        throws IOException {
      long id = channel.getLong();
      byte inUseFlag = channel.get();
      boolean inUse = false;
      if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
        inUse = true;
      } else if ((inUseFlag & Record.IN_USE.byteValue()) != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
      }
      RelationshipRecord record;
      if (inUse) {
        record = new RelationshipRecord(id, channel.getLong(), channel.getLong(), channel.getInt());
        record.setInUse(inUse);
        record.setFirstPrevRel(channel.getLong());
        record.setFirstNextRel(channel.getLong());
        record.setSecondPrevRel(channel.getLong());
        record.setSecondNextRel(channel.getLong());
        record.setNextProp(channel.getLong());

        /*
         * Logs for version 2.0 do not contain the proper values for the following two flags. Also,
         * the defaults won't do, because the pointers for prev in the fist record will not be interpreted
         * properly. So we need to set the flags explicitly here.
         *
         * Note that this leaves the prev field for the first record in the chain having a value of -1,
         * which is not correct, as it should contain the relationship count instead. However, we cannot
         * determine this value from the contents of the log alone.
         */
        record.setFirstInFirstChain(
            record.getFirstPrevRel() == Record.NO_PREV_RELATIONSHIP.intValue());
        record.setFirstInSecondChain(
            record.getSecondPrevRel() == Record.NO_PREV_RELATIONSHIP.intValue());
      } else {
        record = new RelationshipRecord(id, -1, -1, -1);
        record.setInUse(false);
      }
      command.init(record);
      return false;
    }
 /**
  * Keeps track of the given relationship and makes use of it later in {@link #accept(long)} and
  * {@link #apply(long, long)}
  *
  * @param deletedRelationship relationship that has been deleted in this transaction.
  */
 public void deleted(RelationshipRecord deletedRelationship) {
   nodes.add(deletedRelationship.getFirstNode());
   nodes.add(deletedRelationship.getSecondNode());
   relationships.put(deletedRelationship.getId(), deletedRelationship);
 }