Class SqlJetMemPage

  • All Implemented Interfaces:
    java.lang.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      SqlJetMemPage()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assemblePage​(int nCell, ISqlJetMemoryPointer[] apCell, int apCellPos, int[] aSize, int aSizePos)
      Add a list of cells to a page.
      void assertParentIndex​(int iIdx, int iChild)
      Page pParent is an internal (non-leaf) tree page.
      void clearCell​(ISqlJetMemoryPointer pCell)
      Free any overflow pages associated with the given Cell.
      java.lang.Object clone()  
      void copyNodeContent​(SqlJetMemPage pTo)  
      void decodeFlags​(int flagByte)
      Decode the flags byte (the first byte of the header) for a page and initialize fields of the MemPage structure accordingly.
      void dropCell​(int idx, int sz)
      Remove the i-th cell from pPage.
      int fillInCell​(ISqlJetMemoryPointer pCell, ISqlJetMemoryPointer pKey, long nKey, ISqlJetMemoryPointer pData, int nData, int nZero)
      Create the byte sequence used to represent a cell on page pPage and write that byte sequence into pCell[].
      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.
      ISqlJetMemoryPointer findOverflowCell​(int iCell)
      This a more complex version of findCell() that works for pages that do contain overflow cells.
      void freePage()
      Add a page of the database file to the freelist.
      void initPage()
      Initialize the auxiliary information for a disk block.
      void insertCell​(int i, ISqlJetMemoryPointer pCell, int sz, ISqlJetMemoryPointer pTemp, int iChild)
      Insert a new cell on pPage at cell index "i".
      void modifyPagePointer​(int iFrom, int iTo, short s)
      Somewhere on pPage, which is guarenteed to be a btree page, not an overflow page, is a pointer to page iFrom.
      org.tmatesoft.sqljet.core.internal.btree.SqlJetBtreeCellInfo parseCell​(int iCell)  
      void ptrmapPutOvfl​(int iCell)
      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.
      void ptrmapPutOvflPtr​(ISqlJetMemoryPointer pCell)
      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.
      static void releasePage​(SqlJetMemPage pPage)
      Release a MemPage.
      void setChildPtrmaps()
      Set the pointer-map entries for all children of page pPage.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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:
        Constant Field Values
    • Constructor Detail

      • SqlJetMemPage

        public SqlJetMemPage()
    • Method Detail

      • 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
      • 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
      • 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
      • clone

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