private NodeRecord readNodeRecord(long id) throws IOException {
      byte inUseFlag = channel.get();
      boolean inUse = false;
      if (inUseFlag == Record.IN_USE.byteValue()) {
        inUse = true;
      } else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
      }
      NodeRecord record;
      if (inUse) {
        record = new NodeRecord(id, false, channel.getLong(), channel.getLong());
        // labels
        long labelField = channel.getLong();
        Collection<DynamicRecord> dynamicLabelRecords = new ArrayList<>();
        readDynamicRecords(dynamicLabelRecords, COLLECTION_DYNAMIC_RECORD_ADDER);
        record.setLabelField(labelField, dynamicLabelRecords);
      } else {
        record =
            new NodeRecord(
                id,
                false,
                Record.NO_NEXT_RELATIONSHIP.intValue(),
                Record.NO_NEXT_PROPERTY.intValue());
      }

      record.setInUse(inUse);
      return record;
    }
 @Override
 public boolean visitNodeCommand(Command.NodeCommand command) throws IOException {
   NodeRecord before = command.getBefore();
   NodeRecord after = command.getAfter();
   channel.put(NeoCommandType.NODE_COMMAND);
   channel.putLong(after.getId());
   writeNodeRecord(before);
   writeNodeRecord(after);
   return false;
 }
    @Override
    public boolean visitNodeCommand(Command.NodeCommand command) throws IOException {
      long id = channel.getLong();

      NodeRecord before = readNodeRecord(id);
      if (before == null) {
        return true;
      }

      NodeRecord after = readNodeRecord(id);
      if (after == null) {
        return true;
      }

      if (!before.inUse() && after.inUse()) {
        after.setCreated();
      }

      command.init(before, after);
      return false;
    }
 private boolean writeNodeRecord(NodeRecord record) throws IOException {
   byte inUse = record.inUse() ? Record.IN_USE.byteValue() : Record.NOT_IN_USE.byteValue();
   channel.put(inUse);
   if (record.inUse()) {
     channel.put(record.isDense() ? (byte) 1 : (byte) 0);
     channel.putLong(record.getNextRel()).putLong(record.getNextProp());
     channel.putLong(record.getLabelField());
   }
   // Always write dynamic label records because we want to know which ones have been deleted
   // especially if the node has been deleted.
   writeDynamicRecords(record.getDynamicLabelRecords());
   return false;
 }
 public RecordProxy<Long, RelationshipGroupRecord, Integer> getRelationshipGroup(
     NodeRecord node, int type) {
   long groupId = node.getNextRel();
   long previousGroupId = Record.NO_NEXT_RELATIONSHIP.intValue();
   Set<Integer> allTypes = new HashSet<>();
   while (groupId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
     RecordProxy<Long, RelationshipGroupRecord, Integer> change =
         recordChangeSet.getRelGroupRecords().getOrLoad(groupId, type);
     RelationshipGroupRecord record = change.forReadingData();
     record.setPrev(previousGroupId); // not persistent so not a "change"
     allTypes.add(record.getType());
     if (record.getType() == type) {
       return change;
     }
     previousGroupId = groupId;
     groupId = record.getNext();
   }
   return null;
 }