示例#1
0
 /**
  * Creates a relationship with the given id, from the nodes identified by id and of type typeId
  *
  * @param id The id of the relationship to create.
  * @param type The id of the relationship type this relationship will have.
  * @param firstNodeId The id of the start node.
  * @param secondNodeId The id of the end node.
  */
 public void relationshipCreate(
     long id, int type, long firstNodeId, long secondNodeId, RecordAccessSet recordChangeSet) {
   // TODO could be unnecessary to mark as changed here already, dense nodes may not need to change
   NodeRecord firstNode =
       recordChangeSet.getNodeRecords().getOrLoad(firstNodeId, null).forChangingLinkage();
   if (!firstNode.inUse()) {
     throw new IllegalStateException(
         "First node[" + firstNodeId + "] is deleted and cannot be used to create a relationship");
   }
   NodeRecord secondNode =
       recordChangeSet.getNodeRecords().getOrLoad(secondNodeId, null).forChangingLinkage();
   if (!secondNode.inUse()) {
     throw new IllegalStateException(
         "Second node["
             + secondNodeId
             + "] is deleted and cannot be used to create a relationship");
   }
   convertNodeToDenseIfNecessary(
       firstNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords());
   convertNodeToDenseIfNecessary(
       secondNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords());
   RelationshipRecord record =
       recordChangeSet.getRelRecords().create(id, null).forChangingLinkage();
   record.setLinks(firstNodeId, secondNodeId, type);
   record.setInUse(true);
   record.setCreated();
   connectRelationship(
       firstNode,
       secondNode,
       record,
       recordChangeSet.getRelRecords(),
       recordChangeSet.getRelGroupRecords());
 }
示例#2
0
  @Test
  public void shouldReadNodeRecords() throws IOException {
    URL nodeStoreFile = getClass().getResource("exampledb/neostore.nodestore.db");

    LegacyNodeStoreReader nodeStoreReader =
        new LegacyNodeStoreReader(new File(nodeStoreFile.getFile()));
    assertEquals(1001, nodeStoreReader.getMaxId());
    Iterable<NodeRecord> records = nodeStoreReader.readNodeStore();
    int nodeCount = 0;
    for (NodeRecord record : records) {
      if (record.inUse()) nodeCount++;
    }
    assertEquals(501, nodeCount);
    nodeStoreReader.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();
 }