Class SqlJetMemPage
java.lang.Object
org.tmatesoft.sqljet.core.internal.SqlJetCloneable
org.tmatesoft.sqljet.core.internal.btree.SqlJetMemPage
- All Implemented Interfaces:
Cloneable
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte
Page type flags.static final byte
static final byte
static final byte
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.clone()
void
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[].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.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
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
Set the pointer-map entries for all children of page pPage.
-
Field Details
-
PTF_INTKEY
public static final byte PTF_INTKEYPage 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
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
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
Release a MemPage. This should be called once for each prior call to sqlite3BtreeGetPage.- Throws:
SqlJetException
-
setChildPtrmaps
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
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. -
findCell
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
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
Add a page of the database file to the freelist. unref() is NOT called for pPage.- Throws:
SqlJetException
-
clearCell
Free any overflow pages associated with the given Cell.- Throws:
SqlJetException
-
dropCell
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 pagepCell
- Content of the new cellsz
- Bytes of content in pCellpTemp
- Temp storage space for pCell, if needednSkip
- Do not write the first nSkip bytes of the cell- Throws:
SqlJetException
-
findOverflowCell
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 pageapCell
- Pointers to cell bodiesaSize
- 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 cellpKey
- The keynKey
- The keypData
- The datanData
- The datanZero
- Extra zero bytes to append to pData- Returns:
- cell size
- Throws:
SqlJetException
-
ptrmapPutOvfl
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
- Throws:
SqlJetException
-
clone
- Overrides:
clone
in classSqlJetCloneable
- Throws:
CloneNotSupportedException
-