Exemple #1
0
 private void setRecord(long id, long value) {
   PersistenceWindow window = acquireWindow(id, OperationType.WRITE);
   try {
     Buffer buffer = window.getOffsettedBuffer(id);
     buffer.put(Record.IN_USE.byteValue()).putLong(value);
     registerIdFromUpdateRecord(id);
   } finally {
     releaseWindow(window);
   }
 }
Exemple #2
0
 private long getRecord(long id) {
   PersistenceWindow window = acquireWindow(id, OperationType.READ);
   try {
     Buffer buffer = window.getOffsettedBuffer(id);
     buffer.get();
     return buffer.getLong();
   } finally {
     releaseWindow(window);
   }
 }
 private PropertyRecord getRecord(long id, PersistenceWindow window, RecordLoad load) {
   Buffer buffer = window.getOffsettedBuffer(id);
   PropertyRecord toReturn = getRecordFromBuffer(id, buffer);
   if (!toReturn.inUse() && load != RecordLoad.FORCE) {
     throw new InvalidRecordException("PropertyRecord[" + id + "] not in use");
   }
   return toReturn;
 }
Exemple #4
0
  private void updateRecord(PropertyRecord record, PersistenceWindow window) {
    long id = record.getId();
    registerIdFromUpdateRecord(id);
    Buffer buffer = window.getOffsettedBuffer(id);
    if (record.inUse()) {
      // Set up the record header
      short prevModifier =
          record.getPrevProp() == Record.NO_NEXT_RELATIONSHIP.intValue()
              ? 0
              : (short) ((record.getPrevProp() & 0xF00000000L) >> 28);
      short nextModifier =
          record.getNextProp() == Record.NO_NEXT_RELATIONSHIP.intValue()
              ? 0
              : (short) ((record.getNextProp() & 0xF00000000L) >> 32);
      byte modifiers = (byte) (prevModifier | nextModifier);
      /*
       * [pppp,nnnn] previous, next high bits
       */
      buffer.put(modifiers);
      buffer.putInt((int) record.getPrevProp()).putInt((int) record.getNextProp());

      // Then go through the blocks
      int longsAppended = 0; // For marking the end of blocks
      for (PropertyBlock block : record.getPropertyBlocks()) {
        long[] propBlockValues = block.getValueBlocks();
        for (long propBlockValue : propBlockValues) {
          buffer.putLong(propBlockValue);
        }

        longsAppended += propBlockValues.length;
        /*
         * For each block we need to update its dynamic record chain if
         * it is just created. Deleted dynamic records are in the property
         * record and dynamic records are never modified. Also, they are
         * assigned as a whole, so just checking the first should be enough.
         */
        if (!block.isLight() && block.getValueRecords().get(0).isCreated()) {
          updateDynamicRecords(block.getValueRecords());
        }
      }
      if (longsAppended < PropertyType.getPayloadSizeLongs()) {
        buffer.putLong(0);
      }
    } else {
      if (!isInRecoveryMode()) {
        freeId(id);
      }
      // skip over the record header, nothing useful there
      buffer.setOffset(buffer.getOffset() + 9);
      buffer.putLong(0);
    }
    updateDynamicRecords(record.getDeletedRecords());
  }
 protected void updateRecord(T record, PersistenceWindow window) {
   int id = record.getId();
   Buffer buffer = window.getOffsettedBuffer(id);
   if (record.inUse()) {
     buffer.put(Record.IN_USE.byteValue());
     writeRecord(record, buffer);
   } else {
     buffer.put(Record.NOT_IN_USE.byteValue());
     if (!isInRecoveryMode()) {
       freeId(id);
     }
   }
 }
  protected T getRecord(int id, PersistenceWindow window, boolean force) {
    Buffer buffer = window.getOffsettedBuffer(id);
    byte inUseByte = buffer.get();
    boolean inUse = (inUseByte == Record.IN_USE.byteValue());
    if (!inUse && !force) {
      throw new InvalidRecordException("Record[" + id + "] not in use");
    }
    if (inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue()) {
      throw new InvalidRecordException("Record[" + id + "] unknown in use flag[" + inUse + "]");
    }

    T record = newRecord(id);
    record.setInUse(inUse);
    readRecord(record, buffer);
    return record;
  }