Class SqlJetMemPage

java.lang.Object
org.tmatesoft.sqljet.core.internal.SqlJetCloneable
org.tmatesoft.sqljet.core.internal.btree.SqlJetMemPage
All Implemented Interfaces:
Cloneable

public class SqlJetMemPage extends SqlJetCloneable
As each page of the file is loaded into memory, an instance of the following structure is appended and initialized to zero. This structure stores information about the page that is decoded from the raw file page. The pParent field points back to the parent page. This allows us to walk up the BTree from any leaf to the root. Care must be taken to unref() the parent page pointer when this page is no longer referenced. The pageDestructor() routine handles that chore. Access to all fields of this structure is controlled by the mutex stored in MemPage.pBt->mutex.
Author:
TMate Software Ltd., Sergey Scherbina (sergey.scherbina@gmail.com)
  • Field Details

    • PTF_INTKEY

      public static final byte PTF_INTKEY
      Page type flags. An ORed combination of these flags appear as the first byte of on-disk image of every BTree page.
      See Also:
    • PTF_ZERODATA

      public static final byte PTF_ZERODATA
      See Also:
    • PTF_LEAFDATA

      public static final byte PTF_LEAFDATA
      See Also:
    • PTF_LEAF

      public static final byte PTF_LEAF
      See Also:
  • Constructor Details

    • SqlJetMemPage

      public SqlJetMemPage()
  • Method Details

    • decodeFlags

      public void decodeFlags(int flagByte) throws SqlJetException
      Decode the flags byte (the first byte of the header) for a page and initialize fields of the MemPage structure accordingly. Only the following combinations are supported. Anything different indicates a corrupt database files:

      PTF_ZERODATA

      PTF_ZERODATA | PTF_LEAF

      PTF_LEAFDATA | PTF_INTKEY

      PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF

      Throws:
      SqlJetException
    • initPage

      public void initPage() throws SqlJetException
      Initialize the auxiliary information for a disk block. Return SQLITE_OK on success. If we see that the page does not contain a well-formed database page, then return SQLITE_CORRUPT. Note that a return of SQLITE_OK does not guarantee that the page is well-formed. It only shows that we failed to detect any corruption.
      Throws:
      SqlJetException
    • releasePage

      public static void releasePage(SqlJetMemPage pPage) throws SqlJetException
      Release a MemPage. This should be called once for each prior call to sqlite3BtreeGetPage.
      Throws:
      SqlJetException
    • setChildPtrmaps

      public void setChildPtrmaps() throws SqlJetException
      Set the pointer-map entries for all children of page pPage. Also, if pPage contains cells that point to overflow pages, set the pointer map entries for the overflow pages as well.
      Throws:
      SqlJetException
    • modifyPagePointer

      public void modifyPagePointer(int iFrom, int iTo, short s) throws SqlJetException
      Somewhere on pPage, which is guarenteed to be a btree page, not an overflow page, is a pointer to page iFrom. Modify this pointer so that it points to iTo. Parameter eType describes the type of pointer to be modified, as follows: PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child page of pPage. PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow page pointed to by one of the cells on pPage. PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next overflow page in the list.
      Throws:
      SqlJetExceptionRemove
      SqlJetException
    • findCell

      public ISqlJetMemoryPointer findCell(int i)
      Given a btree page and a cell index (0 means the first cell on the page, 1 means the second cell, and so forth) return a pointer to the cell content. This routine works only for pages that do not contain overflow cells.
    • ptrmapPutOvflPtr

      public void ptrmapPutOvflPtr(ISqlJetMemoryPointer pCell) throws SqlJetException
      If the cell pCell, part of page pPage contains a pointer to an overflow page, insert an entry into the pointer-map for the overflow page.
      Throws:
      SqlJetException
    • parseCell

      public org.tmatesoft.sqljet.core.internal.btree.SqlJetBtreeCellInfo parseCell(int iCell)
      Parameters:
      iCell - The cell index. First cell is 0
      Returns:
    • freePage

      public void freePage() throws SqlJetException
      Add a page of the database file to the freelist. unref() is NOT called for pPage.
      Throws:
      SqlJetException
    • clearCell

      public void clearCell(ISqlJetMemoryPointer pCell) throws SqlJetException
      Free any overflow pages associated with the given Cell.
      Throws:
      SqlJetException
    • dropCell

      public void dropCell(int idx, int sz) throws SqlJetException
      Remove the i-th cell from pPage. This routine effects pPage only. The cell content is not freed or deallocated. It is assumed that the cell content has been copied someplace else. This routine just removes the reference to the cell from pPage. "sz" must be the number of bytes in the cell.
      Parameters:
      idx -
      sz -
      Throws:
      SqlJetException
    • insertCell

      public void insertCell(int i, ISqlJetMemoryPointer pCell, int sz, ISqlJetMemoryPointer pTemp, int iChild) throws SqlJetException
      Insert a new cell on pPage at cell index "i". pCell points to the content of the cell. If the cell content will fit on the page, then put it there. If it will not fit, then make a copy of the cell content into pTemp if pTemp is not null. Regardless of pTemp, allocate a new entry in pPage->aOvfl[] and make it point to the cell content (either in pTemp or the original pCell) and also record its index. Allocating a new entry in pPage->aCell[] implies that pPage->nOverflow is incremented. If nSkip is non-zero, then do not copy the first nSkip bytes of the cell. The caller will overwrite them after this function returns. If nSkip is non-zero, then pCell may not point to an invalid memory location (but pCell+nSkip is always valid).
      Parameters:
      i - New cell becomes the i-th cell of the page
      pCell - Content of the new cell
      sz - Bytes of content in pCell
      pTemp - Temp storage space for pCell, if needed
      nSkip - Do not write the first nSkip bytes of the cell
      Throws:
      SqlJetException
    • findOverflowCell

      public ISqlJetMemoryPointer findOverflowCell(int iCell)
      This a more complex version of findCell() that works for pages that do contain overflow cells. See insert
      Parameters:
      iCell -
      Returns:
    • assemblePage

      public void assemblePage(int nCell, ISqlJetMemoryPointer[] apCell, int apCellPos, int[] aSize, int aSizePos) throws SqlJetException
      Add a list of cells to a page. The page should be initially empty. The cells are guaranteed to fit on the page.
      Parameters:
      nCell - The number of cells to add to this page
      apCell - Pointers to cell bodies
      aSize - Sizes of the cells
      Throws:
      SqlJetException
    • assertParentIndex

      public void assertParentIndex(int iIdx, int iChild)
      Page pParent is an internal (non-leaf) tree page. This function asserts that page number iChild is the left-child if the iIdx'th cell in page pParent. Or, if iIdx is equal to the total number of cells in pParent, that page number iChild is the right-child of the page.
      Parameters:
      iIdx -
      iChild -
    • fillInCell

      public int fillInCell(ISqlJetMemoryPointer pCell, ISqlJetMemoryPointer pKey, long nKey, ISqlJetMemoryPointer pData, int nData, int nZero) throws SqlJetException
      Create the byte sequence used to represent a cell on page pPage and write that byte sequence into pCell[]. Overflow pages are allocated and filled in as necessary. The calling procedure is responsible for making sure sufficient space has been allocated for pCell[]. Note that pCell does not necessary need to point to the pPage->aData area. pCell might point to some temporary storage. The cell will be constructed in this temporary area then copied into pPage->aData later.
      Parameters:
      pCell - Complete text of the cell
      pKey - The key
      nKey - The key
      pData - The data
      nData - The data
      nZero - Extra zero bytes to append to pData
      Returns:
      cell size
      Throws:
      SqlJetException
    • ptrmapPutOvfl

      public void ptrmapPutOvfl(int iCell) throws SqlJetException
      If the cell with index iCell on page pPage contains a pointer to an overflow page, insert an entry into the pointer-map for the overflow page.
      Parameters:
      iCell -
      Throws:
      SqlJetException
    • copyNodeContent

      public void copyNodeContent(SqlJetMemPage pTo) throws SqlJetException
      Throws:
      SqlJetException
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class SqlJetCloneable
      Throws:
      CloneNotSupportedException