Example #1
0
  @Test
  public void shouldReadRelationshipRecords() throws IOException {
    URL nodeStoreFile = getClass().getResource("exampledb/neostore.relationshipstore.db");

    LegacyRelationshipStoreReader relationshipStoreReader =
        new LegacyRelationshipStoreReader(new File(nodeStoreFile.getFile()));
    assertEquals(1500, relationshipStoreReader.getMaxId());
    Iterable<RelationshipRecord> records = relationshipStoreReader.readRelationshipStore();
    int relationshipCount = 0;
    for (RelationshipRecord record : records) {
      if (record.inUse()) relationshipCount++;
    }
    assertEquals(500, relationshipCount);
    relationshipStoreReader.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();
    }