コード例 #1
0
 public PropertyRecord getRecord(long id) {
   PropertyRecord record;
   PersistenceWindow window = acquireWindow(id, OperationType.READ);
   try {
     record = getRecord(id, window, RecordLoad.NORMAL);
   } finally {
     releaseWindow(window);
   }
   for (PropertyBlock block : record.getPropertyBlocks()) {
     // assert block.inUse();
     if (block.getType() == PropertyType.STRING) {
       Collection<DynamicRecord> stringRecords =
           stringPropertyStore.getLightRecords(block.getSingleValueLong());
       for (DynamicRecord stringRecord : stringRecords) {
         stringRecord.setType(PropertyType.STRING.intValue());
         block.addValueRecord(stringRecord);
       }
     } else if (block.getType() == PropertyType.ARRAY) {
       Collection<DynamicRecord> arrayRecords =
           arrayPropertyStore.getLightRecords(block.getSingleValueLong());
       for (DynamicRecord arrayRecord : arrayRecords) {
         arrayRecord.setType(PropertyType.ARRAY.intValue());
         block.addValueRecord(arrayRecord);
       }
     }
   }
   return record;
 }
コード例 #2
0
ファイル: PropertyStore.java プロジェクト: popdevelop/neo4j
 public void ensureHeavy(PropertyBlock block) {
   if (block.getType() == PropertyType.STRING) {
     if (block.isLight()) {
       Collection<DynamicRecord> stringRecords =
           stringPropertyStore.getLightRecords(block.getSingleValueLong());
       for (DynamicRecord stringRecord : stringRecords) {
         stringRecord.setType(PropertyType.STRING.intValue());
         block.addValueRecord(stringRecord);
       }
     }
     for (DynamicRecord stringRecord : block.getValueRecords()) {
       stringPropertyStore.ensureHeavy(stringRecord);
     }
   } else if (block.getType() == PropertyType.ARRAY) {
     if (block.isLight()) {
       Collection<DynamicRecord> arrayRecords =
           arrayPropertyStore.getLightRecords(block.getSingleValueLong());
       for (DynamicRecord arrayRecord : arrayRecords) {
         arrayRecord.setType(PropertyType.ARRAY.intValue());
         block.addValueRecord(arrayRecord);
       }
     }
     for (DynamicRecord arrayRecord : block.getValueRecords()) {
       arrayPropertyStore.ensureHeavy(arrayRecord);
     }
   }
 }
コード例 #3
0
 private void updateDynamicRecords(List<DynamicRecord> records) {
   for (DynamicRecord valueRecord : records) {
     if (valueRecord.getType() == PropertyType.STRING.intValue()) {
       stringPropertyStore.updateRecord(valueRecord);
     } else if (valueRecord.getType() == PropertyType.ARRAY.intValue()) {
       arrayPropertyStore.updateRecord(valueRecord);
     } else {
       throw new InvalidRecordException("Unknown dynamic record" + valueRecord);
     }
   }
 }
コード例 #4
0
 /*
  * This will add the value records without checking if they are already
  * in the block - so make sure to call this after checking isHeavy() or
  * you will end up with duplicates.
  */
 public void makeHeavy(PropertyBlock record) {
   if (record.getType() == PropertyType.STRING) {
     Collection<DynamicRecord> stringRecords =
         stringPropertyStore.getLightRecords(record.getSingleValueLong());
     for (DynamicRecord stringRecord : stringRecords) {
       stringRecord.setType(PropertyType.STRING.intValue());
       record.addValueRecord(stringRecord);
     }
   } else if (record.getType() == PropertyType.ARRAY) {
     Collection<DynamicRecord> arrayRecords =
         arrayPropertyStore.getLightRecords(record.getSingleValueLong());
     for (DynamicRecord arrayRecord : arrayRecords) {
       arrayRecord.setType(PropertyType.ARRAY.intValue());
       record.addValueRecord(arrayRecord);
     }
   }
 }
コード例 #5
0
ファイル: PropertyStore.java プロジェクト: popdevelop/neo4j
 public void makeHeavyIfLight(PropertyBlock record) {
   if (record.isLight()) {
     /*
      * This will add the value records without checking if they are already
      * in the block - so we only call this after checking isLight() or
      * else we will end up with duplicates.
      */
     if (record.getType() == PropertyType.STRING) {
       Collection<DynamicRecord> stringRecords =
           stringPropertyStore.getLightRecords(record.getSingleValueLong());
       for (DynamicRecord stringRecord : stringRecords) {
         stringRecord.setType(PropertyType.STRING.intValue());
         record.addValueRecord(stringRecord);
       }
     } else if (record.getType() == PropertyType.ARRAY) {
       Collection<DynamicRecord> arrayRecords =
           arrayPropertyStore.getLightRecords(record.getSingleValueLong());
       for (DynamicRecord arrayRecord : arrayRecords) {
         arrayRecord.setType(PropertyType.ARRAY.intValue());
         record.addValueRecord(arrayRecord);
       }
     }
   }
 }
コード例 #6
0
  public void encodeValue(PropertyBlock block, int keyId, Object value) {
    if (value instanceof String) { // Try short string first, i.e. inlined in the property block
      String string = (String) value;
      if (LongerShortString.encode(keyId, string, block, PropertyType.getPayloadSize())) return;

      // Fall back to dynamic string store
      long stringBlockId = nextStringBlockId();
      setSingleBlockValue(block, keyId, PropertyType.STRING, stringBlockId);
      byte[] encodedString = encodeString(string);
      Collection<DynamicRecord> valueRecords = allocateStringRecords(stringBlockId, encodedString);
      for (DynamicRecord valueRecord : valueRecords) {
        valueRecord.setType(PropertyType.STRING.intValue());
        block.addValueRecord(valueRecord);
      }
    } else if (value instanceof Integer)
      setSingleBlockValue(block, keyId, PropertyType.INT, ((Integer) value).longValue());
    else if (value instanceof Boolean)
      setSingleBlockValue(
          block, keyId, PropertyType.BOOL, (((Boolean) value).booleanValue() ? 1L : 0L));
    else if (value instanceof Float)
      setSingleBlockValue(
          block, keyId, PropertyType.FLOAT, Float.floatToRawIntBits(((Float) value).floatValue()));
    else if (value instanceof Long) {
      long keyAndType = keyId | (((long) PropertyType.LONG.intValue()) << 24);
      if (ShortArray.LONG.getRequiredBits((Long) value)
          <= 35) { // We only need one block for this value, special layout compared to, say, an
                   // integer
        block.setSingleBlock(keyAndType | (1L << 28) | (((Long) value).longValue() << 29));
      } else { // We need two blocks for this value
        block.setValueBlocks(new long[] {keyAndType, ((Long) value).longValue()});
      }
    } else if (value instanceof Double)
      block.setValueBlocks(
          new long[] {
            keyId | (((long) PropertyType.DOUBLE.intValue()) << 24),
            Double.doubleToRawLongBits(((Double) value).doubleValue())
          });
    else if (value instanceof Byte)
      setSingleBlockValue(block, keyId, PropertyType.BYTE, ((Byte) value).longValue());
    else if (value instanceof Character)
      setSingleBlockValue(block, keyId, PropertyType.CHAR, ((Character) value).charValue());
    else if (value instanceof Short)
      setSingleBlockValue(block, keyId, PropertyType.SHORT, ((Short) value).longValue());
    else if (value
        .getClass()
        .isArray()) { // Try short array first, i.e. inlined in the property block
      if (ShortArray.encode(keyId, value, block, PropertyType.getPayloadSize())) return;

      // Fall back to dynamic array store
      long arrayBlockId = nextArrayBlockId();
      setSingleBlockValue(block, keyId, PropertyType.ARRAY, arrayBlockId);
      Collection<DynamicRecord> arrayRecords = allocateArrayRecords(arrayBlockId, value);
      for (DynamicRecord valueRecord : arrayRecords) {
        valueRecord.setType(PropertyType.ARRAY.intValue());
        block.addValueRecord(valueRecord);
      }
    } else {
      throw new IllegalArgumentException(
          "Unknown property type on: " + value + ", " + value.getClass());
    }
  }