Esempio n. 1
0
  @Test
  public void shouldReadASimplePropertyRecordById() throws IOException {
    URL propertyStoreFile = getClass().getResource("exampledb/neostore.propertystore.db");

    LegacyPropertyRecord propertyRecord =
        new LegacyPropertyStoreReader(new File(propertyStoreFile.getFile())).readPropertyRecord(24);

    int keyIndexId = propertyRecord.getKeyIndexId();
    assertEquals(2, keyIndexId);
    Object value = propertyRecord.getType().getValue(propertyRecord, null);
    assertEquals(Integer.MAX_VALUE, value);
  }
 public Object getArrayFor(LegacyPropertyRecord propertyRecord) {
   long recordToFind = propertyRecord.getPropBlock();
   Map<Long, LegacyDynamicRecord> recordsMap = new HashMap<Long, LegacyDynamicRecord>();
   for (LegacyDynamicRecord record : readDynamicRecords(propertyRecord)) {
     recordsMap.put(record.getId(), record);
   }
   List<byte[]> byteList = new LinkedList<byte[]>();
   int totalSize = 0;
   while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) {
     LegacyDynamicRecord record = recordsMap.get(recordToFind);
     if (!record.isCharData()) {
       ByteBuffer buf = ByteBuffer.wrap(record.getData());
       byte[] bytes = new byte[record.getData().length];
       totalSize += bytes.length;
       buf.get(bytes);
       byteList.add(bytes);
     } else {
       throw new InvalidRecordException("Expected byte data on record " + record);
     }
     recordToFind = record.getNextBlock();
   }
   byte[] bArray = new byte[totalSize];
   int offset = 0;
   for (byte[] currentArray : byteList) {
     System.arraycopy(currentArray, 0, bArray, offset, currentArray.length);
     offset += currentArray.length;
   }
   return arrayPropertyStore.getRightArray(bArray);
 }
 public List<LegacyDynamicRecord> readDynamicRecords(LegacyPropertyRecord record) {
   if (record.getType() == LegacyPropertyType.STRING) {
     List<LegacyDynamicRecord> stringRecords =
         stringPropertyStore.getPropertyChain(record.getPropBlock());
     for (LegacyDynamicRecord stringRecord : stringRecords) {
       stringRecord.setType(PropertyType.STRING.intValue());
     }
     return stringRecords;
   } else if (record.getType() == LegacyPropertyType.ARRAY) {
     List<LegacyDynamicRecord> arrayRecords =
         arrayPropertyStore.getPropertyChain(record.getPropBlock());
     for (LegacyDynamicRecord arrayRecord : arrayRecords) {
       arrayRecord.setType(PropertyType.ARRAY.intValue());
     }
     return arrayRecords;
   }
   return null;
 }
Esempio n. 4
0
  @Test
  public void shouldReadAStringPropertyRecordById() throws IOException {
    URL propertyStoreFile = getClass().getResource("exampledb/neostore.propertystore.db");
    URL stringStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.strings");
    URL arrayStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.arrays");

    LegacyPropertyRecord propertyRecord =
        new LegacyPropertyStoreReader(new File(propertyStoreFile.getFile())).readPropertyRecord(25);

    int keyIndexId = propertyRecord.getKeyIndexId();
    assertEquals(3, keyIndexId);
    Object value =
        propertyRecord
            .getType()
            .getValue(
                propertyRecord,
                new LegacyDynamicRecordFetcher(
                    new File(stringStoreFile.getFile()), new File(arrayStoreFile.getFile())));
    assertEquals(1000, ((String) value).length());
  }
Esempio n. 5
0
  @Test
  public void shouldReadAnArrayPropertyRecordById() throws IOException {
    URL propertyStoreFile = getClass().getResource("exampledb/neostore.propertystore.db");
    URL stringStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.strings");
    URL arrayStoreFile = getClass().getResource("exampledb/neostore.propertystore.db.arrays");

    LegacyPropertyRecord propertyRecord2 =
        new LegacyPropertyStoreReader(new File(propertyStoreFile.getFile())).readPropertyRecord(32);

    int keyIndexId = propertyRecord2.getKeyIndexId();
    assertEquals(10, keyIndexId);
    Object value =
        propertyRecord2
            .getType()
            .getValue(
                propertyRecord2,
                new LegacyDynamicRecordFetcher(
                    new File(stringStoreFile.getFile()), new File(arrayStoreFile.getFile())));
    assertArrayEquals(MigrationTestUtils.makeLongArray(), (int[]) value);
  }
 public Object getStringFor(LegacyPropertyRecord propRecord) {
   long startRecordId = propRecord.getPropBlock();
   List<LegacyDynamicRecord> legacyDynamicRecords = readDynamicRecords(propRecord);
   return joinRecordsIntoString(startRecordId, legacyDynamicRecords);
 }