APIdia Launch Partner
Top Description Inners Fields Constructors Methods
io.github.spannm.jackcess.impl

public Class IndexPageCache

extends Object
Class Inheritance
Annotations
@SuppressWarnings:PMD.FieldDeclarationsShouldBeAtStartOfClass
Static Imports
io.github.spannm.jackcess.impl.IndexData.EMPTY_PREFIX, .IndexData.FIRST_ENTRY, .IndexData.INVALID_INDEX_PAGE_NUMBER, .IndexData.missingIndexToInsertionPoint

Manager of the index pages for a IndexData.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
IndexPageCache.CacheDataPage

IndexPageCache implementation of an Index DataPage.

private static class
IndexPageCache.DataPageExtra

Keeps track of the extra info for an index page.

private class
IndexPageCache.DataPageMain

Keeps track of the main info for an index page.

private static class
IndexPageCache.EntryListView

A view of an index page's entries which combines the normal entries and tail entry into one collection.

private static enum
private class
IndexPageCache.Validator

Utility class for running index validation.

Field Summary

Modifier and TypeField and Description
private final Map<Integer, IndexPageCache.DataPageMain>
dataPages

the currently loaded pages for this index, pageNumber -> page

private final IndexData
indexData

the index whose pages this cache is managing

private static final int
MAX_CACHE_SIZE

max number of pages to cache (unless a write operation is in progress)

private final List<IndexPageCache.CacheDataPage>
modifiedPages

the currently modified index pages

private IndexPageCache.DataPageMain
rootPage

the root page for the index

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
addEntry(IndexPageCache.CacheDataPage
the page to which to add the entry
cacheDataPage
,
int
the index at which to add the entry
entryIdx
,
IndexData.Entry
the entry to add
newEntry
)

Adds the entry to the given page at the given index.

private void
addParentEntry(IndexPageCache.CacheDataPage
the parent page to which to add the entry
parentDataPage
,
IndexPageCache.CacheDataPage
the child from which to get the entry to add
childDataPage
)

Adds an entry for the given child page to the given parent page.

private void
addToPeersBefore(IndexPageCache.CacheDataPage
the new index page
newDataPage
,
IndexPageCache.CacheDataPage
the current index page
origDataPage
)

Inserts the new page as a peer between the given original page and any previous peer page.

private IndexPageCache.CacheDataPage

Returns:

the newly created page
allocateNewCacheDataPage
(Integer
the parent page for the new page
parentPageNumber
,
boolean
whether or not the new page is a leaf page
isLeaf
,
int
the level of the new page in the index tree
level
)

Allocates a new index page with the given parent page and type.

private List<Object>
collectPages(List<Object>
the List to update
pages
,
IndexPageCache.DataPageMain
the index page to collect
dpMain
)

Collects all the cache pages in the cache.

private void
deleteDataPage(IndexPageCache.CacheDataPage cacheDataPage)

Deletes the given index page from the file (clears the page).

private void
demoteTail(IndexPageCache.CacheDataPage
the page whose tail must be updated
cacheDataPage
)

Makes the tail entry of the given page a normal entry on that page, done when there is only one entry left on a page, and it is the tail.

public IndexPageCache.CacheDataPage
findCacheDataPage(IndexData.Entry
the entry to find
e
)

Finds the index page on which the given entry does or should reside.

public IndexPageCache.CacheDataPage
getCacheDataPage(Integer pageNumber)

Returns a CacheDataPage for the given page number, may be null if the given page number is invalid.

private IndexPageCache.DataPageMain
getDataPage(Integer pageNumber)

Returns a DataPageMain for the given page number, may be null if the given page number is invalid.

public IndexData
public PageChannel
private void
handleEmptyPages()

Handles any modified pages which are empty as the first pass during a write call.

private IndexPageCache.CacheDataPage

Returns:

the newly created page nested under the root page
nestRootDataPage
(IndexPageCache.CacheDataPage
the root data page
rootDataPage
)

Copies the current root page info into a new page and nests this page under the root page.

private void
preparePagesForWriting()

Prepares any non-empty modified pages for writing as the second pass during a write call.

private void
promoteTail(IndexPageCache.CacheDataPage
the cache data page being processed
cacheDataPage
,
IndexPageCache.DataPageMain
the main data page to be promoted
lastMain
)

Makes the last normal entry of the given page the tail entry on that page, done when there are multiple entries on a page and no tail entry.

private void
purgeOldPages()

Trims the size of the dataPages cache appropriately (assuming caller has already verified that the cache needs trimming).

private IndexPageCache.CacheDataPage
readDataPage(Integer pageNumber)

Reads the given index page from the file.

private void
removeDataPage(IndexPageCache.CacheDataPage
the parent of the removed page
parentDataPage
,
IndexPageCache.CacheDataPage
the page to remove
cacheDataPage
,
IndexData.Entry
the last entry for this page (before it was removed)
oldLastEntry
)

Removes an index page which has become empty.

private IndexData.Entry
removeEntry(IndexPageCache.CacheDataPage
the page from which to remove the entry
cacheDataPage
,
int
the index of the entry to remove
entryIdx
)

Removes the entry with the given index from the given page.

private void
removeFromPeers(IndexPageCache.CacheDataPage
the page to remove
cacheDataPage
)

Removes a now empty index page from its next and previous peers.

private void
reparentChildren(IndexPageCache.CacheDataPage
the page whose children need to be updated
cacheDataPage
)

Sets the parent info for the children of the given page to the given page.

private void
replaceParentEntry(IndexPageCache.CacheDataPage
the parent page in which to replace the entry
parentDataPage
,
IndexPageCache.CacheDataPage
the child for which the entry is being replaced
childDataPage
,
IndexData.Entry
the old child entry for the child page
oldEntry
)

Replaces the entry for the given child page in the given parent page.

private void
separateFromNextPeer(IndexPageCache.CacheDataPage
the index page to be separated
cacheDataPage
)

Separates the given index page from any next peer page.

private void
setModified(IndexPageCache.CacheDataPage
the modified index page
cacheDataPage
)

Marks the given index page as modified and saves it for writing, if necessary (if the page is already marked, does nothing).

public void
setRootPageNumber(int
the root page number
pageNumber
)

Sets the root page for this index, must be called before normal usage.

private void
splitDataPage(IndexPageCache.CacheDataPage
the page to split
origDataPage
)

Splits an index page which has too many entries on it.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private IndexData.Entry
updateEntry(IndexPageCache.CacheDataPage
the page to update
cacheDataPage
,
int
the index at which to add/remove/replace the entry
entryIdx
,
IndexData.Entry
the entry to add/replace
newEntry
,
IndexPageCache.UpdateType
the type of update to make
upType
)

Updates the entries on the given page according to the given updateType.

private void
updateParentEntry(IndexPageCache.CacheDataPage
the parent page in which to update the entry
parentDataPage
,
IndexPageCache.CacheDataPage
the child for which the entry is being updated
childDataPage
,
IndexData.Entry
the old child entry to remove/replace
oldEntry
,
IndexData.Entry
the new child entry to replace/add
newEntry
,
IndexPageCache.UpdateType
the type of update to make
upType
)

Updates the entry for the given child page in the given parent page according to the given updateType.

private void
updateParentTail(IndexPageCache.CacheDataPage
the parent page in which to update the child tail
parentDataPage
,
IndexPageCache.CacheDataPage
the child to add/replace
childDataPage
,
IndexPageCache.UpdateType
the type of update to make
upType
)

Updates the child tail info in the given parent page according to the given updateType.

pack-priv void
validate(boolean forceLoad)

Used by unit tests to validate the internal status of the index.

private void
validateEntryForPage(IndexPageCache.DataPageMain
the page to which the entry will be added
dpMain
,
IndexData.Entry
the entry being added
entry
)

Verifies that the given entry type (node/leaf) is valid for the given page (node/leaf).

private String
public void
write()

Writes any outstanding changes for this index to the file.

private void
writeDataPage(IndexPageCache.CacheDataPage cacheDataPage)

Writes the given index page to the file.

private void
writeDataPages()

Writes any non-empty modified pages as the last pass during a write call.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait