public Migration(LegacyStore legacyStore, NeoStore neoStore) {
   this.legacyStore = legacyStore;
   this.neoStore = neoStore;
   totalEntities =
       legacyStore.getNodeStoreReader().getMaxId()
           + legacyStore.getRelationshipStoreReader().getMaxId();
 }
 private void migrate() throws IOException {
   migrateNeoStore(neoStore);
   migrateNodes(neoStore.getNodeStore(), new PropertyWriter(neoStore.getPropertyStore()));
   migrateRelationships(
       neoStore.getRelationshipStore(), new PropertyWriter(neoStore.getPropertyStore()));
   migratePropertyIndexes(neoStore.getPropertyStore().getIndexStore());
   legacyStore.getPropertyStoreReader().close();
   migrateRelationshipTypes(neoStore.getRelationshipTypeStore());
   legacyStore.close();
 }
 private long migrateProperties(long startOfPropertyChain, PropertyWriter propertyWriter)
     throws IOException {
   LegacyPropertyRecord propertyRecord =
       legacyStore.getPropertyStoreReader().readPropertyRecord(startOfPropertyChain);
   List<Pair<Integer, Object>> properties = new ArrayList<Pair<Integer, Object>>();
   while (propertyRecord.getNextProp() != Record.NO_NEXT_PROPERTY.intValue()) {
     properties.add(extractValue(propertyRecord));
     propertyRecord =
         legacyStore.getPropertyStoreReader().readPropertyRecord(propertyRecord.getNextProp());
   }
   properties.add(extractValue(propertyRecord));
   return propertyWriter.writeProperties(properties);
 }
    public void migratePropertyIndexes(PropertyIndexStore propIndexStore) throws IOException {
      LegacyPropertyIndexStoreReader indexStoreReader = legacyStore.getPropertyIndexStoreReader();
      LegacyDynamicStoreReader propertyIndexKeyStoreReader =
          legacyStore.getPropertyIndexKeyStoreReader();

      for (PropertyIndexRecord propertyIndexRecord : indexStoreReader.readPropertyIndexStore()) {
        List<LegacyDynamicRecord> dynamicRecords =
            propertyIndexKeyStoreReader.getPropertyChain(propertyIndexRecord.getNameId());
        String key =
            LegacyDynamicRecordFetcher.joinRecordsIntoString(
                propertyIndexRecord.getNameId(), dynamicRecords);
        createPropertyIndex(propIndexStore, key, propertyIndexRecord.getId());
      }
      propertyIndexKeyStoreReader.close();
    }
    private void migrateNeoStore(NeoStore neoStore) {
      LegacyNeoStoreReader neoStoreReader = legacyStore.getNeoStoreReader();

      neoStore.setCreationTime(neoStoreReader.getCreationTime());
      neoStore.setRandomNumber(neoStoreReader.getRandomNumber());
      neoStore.setVersion(neoStoreReader.getVersion());
      updateLastCommittedTxInSimulatedRecoveredStatus(
          neoStore, neoStoreReader.getLastCommittedTx());
    }
    public void migrateRelationshipTypes(RelationshipTypeStore relationshipTypeStore)
        throws IOException {
      LegacyRelationshipTypeStoreReader relationshipTypeStoreReader =
          legacyStore.getRelationshipTypeStoreReader();
      LegacyDynamicStoreReader relationshipTypeNameStoreReader =
          legacyStore.getRelationshipTypeNameStoreReader();

      for (RelationshipTypeRecord relationshipTypeRecord :
          relationshipTypeStoreReader.readRelationshipTypes()) {
        List<LegacyDynamicRecord> dynamicRecords =
            relationshipTypeNameStoreReader.getPropertyChain(relationshipTypeRecord.getNameId());
        String name =
            LegacyDynamicRecordFetcher.joinRecordsIntoString(
                relationshipTypeRecord.getNameId(), dynamicRecords);
        createRelationshipType(relationshipTypeStore, name, relationshipTypeRecord.getId());
      }
      relationshipTypeNameStoreReader.close();
    }
 private void migrateNodes(NodeStore nodeStore, PropertyWriter propertyWriter)
     throws IOException {
   Iterable<NodeRecord> records = legacyStore.getNodeStoreReader().readNodeStore();
   // estimate total number of nodes using file size then calc number of dots or percentage
   // complete
   for (NodeRecord nodeRecord : records) {
     reportProgress(nodeRecord.getId());
     nodeStore.setHighId(nodeRecord.getId() + 1);
     if (nodeRecord.inUse()) {
       long startOfPropertyChain = nodeRecord.getNextProp();
       if (startOfPropertyChain != Record.NO_NEXT_RELATIONSHIP.intValue()) {
         long propertyRecordId = migrateProperties(startOfPropertyChain, propertyWriter);
         nodeRecord.setNextProp(propertyRecordId);
       }
       nodeStore.updateRecord(nodeRecord);
     } else {
       nodeStore.freeId(nodeRecord.getId());
     }
   }
   legacyStore.getNodeStoreReader().close();
 }
    private void migrateRelationships(
        RelationshipStore relationshipStore, PropertyWriter propertyWriter) throws IOException {
      long nodeMaxId = legacyStore.getNodeStoreReader().getMaxId();

      Iterable<RelationshipRecord> records =
          legacyStore.getRelationshipStoreReader().readRelationshipStore();
      for (RelationshipRecord relationshipRecord : records) {
        reportProgress(nodeMaxId + relationshipRecord.getId());
        relationshipStore.setHighId(relationshipRecord.getId() + 1);
        if (relationshipRecord.inUse()) {
          long startOfPropertyChain = relationshipRecord.getNextProp();
          if (startOfPropertyChain != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            long propertyRecordId = migrateProperties(startOfPropertyChain, propertyWriter);
            relationshipRecord.setNextProp(propertyRecordId);
          }
          relationshipStore.updateRecord(relationshipRecord);
        } else {
          relationshipStore.freeId(relationshipRecord.getId());
        }
      }
      legacyStore.getRelationshipStoreReader().close();
    }
 private Pair<Integer, Object> extractValue(LegacyPropertyRecord propertyRecord) {
   int keyIndexId = propertyRecord.getKeyIndexId();
   Object value =
       propertyRecord.getType().getValue(propertyRecord, legacyStore.getDynamicRecordFetcher());
   return Pair.of(keyIndexId, value);
 }