Package net.sf.joafip.heapfile.record.entity

Examples of net.sf.joafip.heapfile.record.entity.HeapRecord


      throws HeapException {
    heapRecord.freeRecord();
    final long positionInFile = heapRecord.getPositionInFile();
    final int areaSize = next.getRecordSize() + heapRecord.getRecordSize();
    /* first delete from free node tree */
    final HeapRecord nextHeapRecord = next;
    freeNodeTreeDelete(nextHeapRecord);
    /* then delete record */
    heapElementManager.delete(next.getPositionInFile());
    final long nextPositionInFile = next.getNextRecordFilePosition();
    if (nextHeapRecord.getPositionInFile() == heapHeader
        .getLastRecordPositionInFile()) {
      heapHeader.setLastRecordPositionInFile(positionInFile);
    }
    freeRecord(positionInFile, areaSize, nextPositionInFile, heapRecord);
  }
View Full Code Here


   * @throws HeapException
   */
  private HeapRecord deleteAndGetDataRecord(final HeapIdNode heapIdNode)
      throws HeapException {
    final DataRecordIdentifier identifier = heapIdNode.getElement();
    final HeapRecord heapRecord = heapIdNode.getHeapRecord();
    idNodeTreeDelete(heapRecord);
    final long positionInFile = heapRecord.getPositionInFile();
    if (logger.debugEnabled) {
      logger.debug("data record #" + identifier + " position in file "
          + positionInFile + " is free record="
          + heapRecord.isFreeRecord());
    }
    return heapRecord;
  }
View Full Code Here

  @Override
  public byte[] readDataRecordImpl(
      final DataRecordIdentifier dataRecordIdentifier)
      throws HeapException {
    final byte[] dataAssociated;
    HeapRecord heapRecord;
    try {
      heapRecord = getHeapRecord(dataRecordIdentifier);
    } catch (HeapException exception) {// NOPMD
      final String message = FAILED_READ_DATA_RECORD
          + dataRecordIdentifier;
      logger.warn(message);
      throw new HeapException(message, exception);
    }
    if (heapRecord == null) {
      /*
       * no data associated to heap record => no data record
       */
      dataAssociated = null;
      if (logger.debugEnabled) {
        logger.debug("no record #" + dataRecordIdentifier);
      }
    } else {
      dataAssociated = heapRecord.getDataAssociated();
    }
    return dataAssociated;
  }
View Full Code Here

  @Override
  public IFileStorable createHeapRecord(
      final IHeapElementManager heapElementManager,
      final long positionInFile) throws HeapException {
    return new HeapRecord(heapElementManager, positionInFile);
  }
View Full Code Here

   */
  private HeapRecord createRecordForDataFromFree(final int neededDataSize,
      final DataRecordIdentifier nodeIdentifier,
      final int neededRecordSize, final HeapFreeNode freeNode)
      throws HeapException {
    final HeapRecord heapRecord;
    /* usable free area size */
    final int freeRecordSize = freeNode.getRecordSize();
    /* unused area size is usable minus needed area size */
    final int newFreeRecordSize = freeRecordSize - neededRecordSize;
    heapRecord = freeNode.getHeapRecord();
    /* no more free */
    freeNodeTreeDelete(heapRecord);
    // NO NO NO do not delete, reused as data record
    // heapElementManager.delete(heapRecord.getPositionInFile());
    /* will update heap header for free and used size */
    final HeapHeader heapHeader = (HeapHeader) heapElementManager
        .getHeapHeader();

    if (newFreeRecordSize >= HeapRecord.MAX_RECORD_HEADER_SIZE
        + MINIMUM_RECORD_DATA_SIZE + 4) {
      /*
       * split free record : one part used for data the other keep free
       */
      final long nextRecordFilePosition = heapRecord
          .getNextRecordFilePosition();
      heapRecord.unfreeRecord(neededDataSize, neededRecordSize,
          nodeIdentifier, false);
      final long positionInFile = heapRecord.getPositionInFile();
      final long newFreeRecordPositionInFile = positionInFile
          + neededRecordSize;

      final HeapRecord newFreeHeapRecord = new HeapRecord(
          heapElementManager,
          newFreeRecordPositionInFile/* positionInFile */,
          positionInFile/* previousPositionInFile */,
          null/* nodeIdentifier */, true/* freeRecord */,
          0/* dataAssociatedSize */, newFreeRecordSize/* recordSize */);

      // final HeapRecord newFreeHeapRecord = heapElementManager
      // .newHeapFileRecord(
      // newFreeRecordPositionInFile/* positionInFile */,
      // positionInFile/* previousPositionInFile */,
      // null/* nodeIdentifier */, true/* freeRecord */,
      // null/* dataAssociatedSize */, newFreeRecordSize/*recordSize*/);

      heapElementManager.appendHeapFileRecord(newFreeHeapRecord);

      if (heapRecord.getPositionInFile() == heapHeader
          .getLastRecordPositionInFile()) {
        heapHeader
            .setLastRecordPositionInFile(newFreeRecordPositionInFile);
      }
      freeNodeTreeAppend(newFreeHeapRecord);
      if (nextRecordFilePosition != -1) {
        final HeapRecord nextHeapRecord = readHeapFileDataRecord(nextRecordFilePosition);
        nextHeapRecord
            .setPreviousRecordPositionInFile(newFreeRecordPositionInFile);
      }
    } else {
      heapRecord.unfreeRecord(neededDataSize, nodeIdentifier);
    }
View Full Code Here

    assert assertFirstPositionInFile(positionInFile,
        previousRecordPositionInFile);
    heapHeader.setLastRecordPositionInFile(positionInFile);
    heapHeader.addUsedSize(needAreaSize);
    /* new at end of file with a new record identification */
    final HeapRecord heapRecord = new HeapRecord(heapElementManager,
        positionInFile, previousRecordPositionInFile, nodeIdentifier,
        false, needDataSize, needAreaSize);
    // final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
    // positionInFile, previousRecordPositionInFile, nodeIdentifier,
    // false, needDataSize, needAreaSize);
View Full Code Here

   * @throws HeapException
   */
  private HeapRecord getHeapRecord(final DataRecordIdentifier identifier)
      throws HeapException {
    final HeapIdNode heapIdNode = idNodeSearchMayBeNotExist(identifier);
    final HeapRecord heapRecord;
    if (heapIdNode == null) {
      heapRecord = null;
    } else {
      final long positionInFile = heapIdNode.getPositionInFile();
      heapRecord = readHeapFileDataRecord(positionInFile);
View Full Code Here

    heapElementManager.startService();
    heapElementManager.openTransaction();

    // final HeapRecord heapRecord = new HeapRecord(heapElementManager,
    // HeapHeader.HEAP_HEADER_SIZE);
    final HeapRecord heapRecord = new HeapRecord(heapElementManager,
        HeapHeader.HEAP_HEADER_SIZE,
        -1L/* previousRecordPositionInFile */,
        DataRecordIdentifier.ZERO/* nodeIdentification */,
        false/* freeRecord */, 0/* dataAssociatedSize */,
        HeapRecord.DATA_RECORD_HEADER_SIZE + 4/* areaSize */);

    // final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
    // HeapHeader.HEAP_HEADER_SIZE,
    // -1/* previousRecordPositionInFile */,
    // DataRecordIdentifier.ZERO/* nodeIdentification */,
    // false/* freeRecord */, 0/* dataAssociatedSize */,
    // HeapRecord.DATA_RECORD_HEADER_SIZE + 4/* areaSize */);
    heapElementManager.appendHeapFileRecord(heapRecord);

    heapIdNode = new HeapIdNode(heapElementManager,
        heapRecord.getPositionInFile(), -1, -1, -1, false, false, 0,
        heapRecord.getNodeIdentifier());
  }
View Full Code Here

  @Override
  public IFileStorable createHeapRecord(
      final IHeapElementManager heapElementManager,
      final long positionInFile) throws HeapException {
    return new HeapRecord(heapElementManager, positionInFile);
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.heapfile.record.entity.HeapRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.