Examples of IDataBlock


Examples of net.sf.joafip.btreeplus.entity.IDataBlock

        final byte[] data = btreePlusElementMgr
            .getData(dataBlockPosition);
        final byte[] expectedData = createData(data.length,
            context.getContentValue(dataBlockIndex));
        assertTrue("bad content", Arrays.equals(expectedData, data));
        final IDataBlock dataBlock = btreePlusElementMgr
            .getDataBlock(dataBlockPosition);
        assertEquals("bad data block type", bits, dataBlock.getBits());
      }
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // remove test
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Deque<Long> positionDeque = new LinkedList<Long>();// NOPMD
      for (int dataBlockIndex = 0; dataBlockIndex < context.size(); dataBlockIndex++) {
        final long dataBlockPosition = context
            .getPosition(dataBlockIndex);
        final IDataBlock dataBlock = btreePlusElementMgr
            .getDataBlock(dataBlockPosition);
        btreePlusElementMgr.remove(dataBlock);
        assertEquals("header not updated", dataBlockPosition,
            getHeapHeader().getFreeDataBlockPosition(bits));
        positionDeque.addFirst(dataBlockPosition);
      }
      context.setPositionDeque(positionDeque);
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // check removed state
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Deque<Long> positionDeque = context.getPositionDeque();
      long expectedPosition = getHeapHeader().getFreeDataBlockPosition(
          bits);
      for (Long currentPosition : positionDeque) {
        assertEquals("bad free position (bits=" + bits + ")",
            expectedPosition, currentPosition.longValue());
        expectedPosition = btreePlusElementMgr.getDataBlock(
            expectedPosition).getNextFreeDataBlockPositionOfFree();
      }
      assertEquals("bad free position", -1, expectedPosition);
      index++;
    }
    btreePlusElementMgr.closeTransaction();

    // add test when free record available
    btreePlusElementMgr.openTransaction();
    index = 0;
    for (byte bits = PageConstant.MIN_DATA_BLOCK_BITS; bits < PageConstant.MAX_DATA_BLOCK_BITS; bits++) {
      final TestDataBlockContext context = contextByBits[index];
      final Iterator<Long> iterator = context.getPositionDeque()
          .iterator();
      final DataBlock dataBlock = createDataBlock(bits, (byte) 0);
      assertEquals("bad allocation", iterator.next().longValue(),
          dataBlock.getPositionInFile());
      assertEquals("bad new free", iterator.next().longValue(),
          getHeapHeader().getFirstFreeBlock(bits));
      index++;
    }
    btreePlusElementMgr.closeTransaction();
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

    final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
    final boolean created;
    if (leafPage == null) {
      // no existing data because no leaf page for key
      created = true;
      final IDataBlock dataBlock = btreePlusElementMgr
          .createDataBlock(data);
      btreePlusElementMgr
          .newRootLeafPage(dataRecordIdentifier, dataBlock);
      btreePlusElementMgr.incrementNumberOfDataRecord();
    } else {
      // existing leaf page for key
      final long dataBlockPosition = leafPage
          .getDataBlockPosition(dataRecordIdentifier);
      if (dataBlockPosition == -1) {
        // data record not found
        created = true;
        final IDataBlock dataBlock = btreePlusElementMgr
            .createDataBlock(data);
        if (!leafPage.add(dataRecordIdentifier, dataBlock)) {
          final NonTerminalPage nonTerminalPage = (NonTerminalPage) leafPage
              .getParentPage();
          if (nonTerminalPage == null) {
            splitLeafPage(leafPage, dataRecordIdentifier,
                nonTerminalPage, dataBlock);
          } else if (tryBalanceOrMerge(leafPage, nonTerminalPage)) {
            if (!leafPage.add(dataRecordIdentifier, dataBlock)) {
              splitLeafPage(leafPage, dataRecordIdentifier,
                  nonTerminalPage, dataBlock);
            }
          } else {
            splitLeafPage(leafPage, dataRecordIdentifier,
                nonTerminalPage, dataBlock);
          }
        }
        btreePlusElementMgr.incrementNumberOfDataRecord();
      } else {
        // data record found
        created = false;
        final IDataBlock dataBlock = btreePlusElementMgr
            .getDataBlock(dataBlockPosition);
        if (data.length >= dataBlock.getMinDataSize()
            && data.length <= dataBlock.getMaxDataSize()) {
          dataBlock.setData(data);
        } else {
          final int index = dataBlock.getIndexInDataBlockPage();
          btreePlusElementMgr.remove(dataBlock);
          final IDataBlock newDataBlock = btreePlusElementMgr
              .createDataBlock(data);
          leafPage.setDataBlock(index, newDataBlock);
        }
      }
    }
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

  @Override
  protected boolean deleteDataRecordImpl(
      final DataRecordIdentifier dataRecordIdentifier)
      throws HeapException {
    final boolean deleted;
    final IDataBlock dataBlock = dataBlock(dataRecordIdentifier);
    if (dataBlock == null) {
      deleted = false;
    } else {
      deleted = true;
      final LeafPage leafPage = dataBlock.getParentLeafPage();
      final int indexInLeafPage = dataBlock.getIndexInLeafPage();
      btreePlusElementMgr.remove(dataBlock);
      leafPage.remove(indexInLeafPage);
      final NonTerminalPage nonTerminalPage = (NonTerminalPage) leafPage
          .getParentPage();
      if (nonTerminalPage == null) {
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

  }

  private IDataBlock dataBlock(final IPageRecordable root,
      final DataRecordIdentifier dataRecordIdentifier)
      throws HeapException {
    final IDataBlock dataBlock;
    final LeafPage leafPage = leafPage(root, dataRecordIdentifier);
    if (leafPage == null) {
      dataBlock = null;
    } else {
      final long dataBlockPosition = leafPage
          .getDataBlockPosition(dataRecordIdentifier);
      if (dataBlockPosition == -1L) {
        dataBlock = null;
      } else {
        final int indexinLeafPage = leafPage.getIndex();
        dataBlock = btreePlusElementMgr.getDataBlock(dataBlockPosition);
        dataBlock.setParent(leafPage, indexinLeafPage);
      }
    }
    return dataBlock;
  }
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

   * @param dataBlockPosition
   * @return data of data block at position
   * @throws HeapException
   */
  public byte[] getData(final long dataBlockPosition) throws HeapException {
    final IDataBlock datablock = getDataBlock(dataBlockPosition);
    return datablock.getData();
  }
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

    final PageRecord pageRecord = (PageRecord) heapElementManager
        .readHeapFileDataRecord(dataBlockPosition
            & PageConstant.START_PAGE_POSITION_MASK);
    final DataBlockPage dataBlockPage = (DataBlockPage) pageRecord
        .getPageRecordable();
    final IDataBlock datablock = dataBlockPage
        .getDataBlock(dataBlockPosition);
    return datablock;
  }
View Full Code Here

Examples of net.sf.joafip.btreeplus.entity.IDataBlock

  public IDataBlock createDataBlock(final byte[] data) throws HeapException {
    final byte bits = DataBlockPage.bitsForLength(data.length);
    final long freeDataBlockPosition = header
        .getFreeDataBlockPosition(bits);
    final IDataBlock dataBlock;
    if (freeDataBlockPosition == -1L) {
      final DataBlockPage dataBlockPage = new DataBlockPage(bits);
      final long pageNumber = header.getFileSizeAsNumberOfPage();
      final long previousRecordPositionInFile = header
          .getLastRecordPositionInFile();
      // the new page record for page recordable
      final IPageRecord pageRecord = new PageRecord(heapElementManager,
          previousRecordPositionInFile, dataBlockPage, pageNumber);
      header.setFileSizeAsNumberOfPage(pageNumber
          + pageRecord.getNumberOfPage());
      header.setLastRecordPositionInFile(pageNumber << PageConstant.PAGE_BITS);
      dataBlockPage.setPageRecord(pageRecord);
      heapElementManager.appendHeapFileRecord(pageRecord);
      dataBlockPage.setAllFree();
      header.incrementNumberOfFreeRecord(dataBlockPage.getNumberOfBlock());
      dataBlock = dataBlockPage.getDataBlock(0);
    } else {
      dataBlock = getDataBlock(freeDataBlockPosition);
    }
    final long nextFreeDataBlockPosition = dataBlock
        .getNextFreeDataBlockPositionOfFree();
    header.setFreeDataBlockPosition(bits, nextFreeDataBlockPosition);
    dataBlock.setData(data);
    header.decrementNumberOfFreeRecord();
    return dataBlock;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.