Class IndexData
- java.lang.Object
-
- com.healthmarketscience.jackcess.impl.IndexData
-
public class IndexData extends Object
Access table index data. This is the actual data which backs a logical Index, where one or more logical indexes can be backed by the same index data.- Author:
- Tim McCune
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIndexData.ColumnDescriptorInformation about the columns in an index.static classIndexData.EntryA single leaf entry in an index (points to a single row)classIndexData.EntryCursorUtility class to traverse the entries in the Index.static classIndexData.EntryTypetype attributes for Entries which simplify comparisonsstatic classIndexData.PendingChangeUtility class which maintains information about a pending index update.
-
Field Summary
Fields Modifier and Type Field Description static byteASCENDING_COLUMN_FLAGstatic Comparator<byte[]>BYTE_CODE_COMPARATORstatic IndexData.EntryFIRST_ENTRYspecial entry which is less than any other entrystatic byteIGNORE_NULLS_INDEX_FLAGstatic IndexData.EntryLAST_ENTRYspecial entry which is greater than any other entrystatic intMAX_COLUMNSMax number of columns in an indexstatic ObjectMAX_VALUEspecial object which will always be greater than any other value, when searching for an index entry range in a multi-value indexstatic ObjectMIN_VALUEspecial object which will always be greater than any other value, when searching for an index entry range in a multi-value indexstatic byteREQUIRED_INDEX_FLAGstatic byteUNIQUE_INDEX_FLAGstatic byteUNKNOWN_INDEX_FLAG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidcommitAll(IndexData.PendingChange change)Object[]constructIndexRow(String colName, Object value)Constructs an array of values appropriate for this index from the given column value.Object[]constructIndexRow(Map<String,?> row)Constructs an array of values appropriate for this index from the given column values.Object[]constructIndexRowFromEntry(Object... values)Constructs an array of values appropriate for this index from the given column values, expected to match the columns for this index.Object[]constructPartialIndexRow(Object filler, String colName, Object value)Constructs an array of values appropriate for this index from the given column value, which must be the first column of the index.Object[]constructPartialIndexRow(Object filler, Map<String,?> row)Constructs an array of values appropriate for this index from the given column values, possibly only using a subset of the given values.Object[]constructPartialIndexRowFromEntry(Object filler, Object... values)Constructs an array of values appropriate for this index from the given column values, possibly only providing a prefix subset of the index columns (at least one value must be provided).static IndexDatacreate(TableImpl table, ByteBuffer tableBuffer, int number, JetFormat format)Creates an IndexData appropriate for the given table, using information from the given table definition buffer.IndexData.EntryCursorcursor()Gets a new cursor for this index.IndexData.EntryCursorcursor(Object[] startRow, boolean startInclusive, Object[] endRow, boolean endInclusive)Gets a new cursor for this index, narrowed to the range defined by the given startRow and endRow.voiddeleteRow(Object[] row, RowIdImpl rowId)Removes a row from this indexintgetColumnCount()List<IndexData.ColumnDescriptor>getColumns()Returns the Columns for this index (unmodifiable)intgetEntryCount()Returns the number of index entries in the index.JetFormatgetFormat()intgetIndexDataNumber()List<Index>getIndexes()bytegetIndexFlags()StringgetName()intgetOwnedPageCount()Returns the number of database pages owned by this index data.PageChannelgetPageChannel()IndexgetPrimaryIndex()TableImplgetTable()intgetUniqueEntryCount()intgetUniqueEntryCountOffset()voidinitialize()Forces initialization of this index (actual parsing of index pages).booleanisInitialized()Whether or not the complete index state has been read.booleanisRequired()Whether or not values are required in the columns.booleanisUnique()Whether or not index entries must be unique.IndexData.PendingChangeprepareAddRow(Object[] row, RowIdImpl rowId, IndexData.PendingChange nextChange)Prepares to add a row to this index.IndexData.PendingChangeprepareUpdateRow(Object[] oldRow, RowIdImpl rowId, Object[] newRow, IndexData.PendingChange nextChange)Prepares to update a row in this index.voidread(ByteBuffer tableBuffer, List<ColumnImpl> availableColumns)Read the rest of the index info from a tableBufferstatic voidrollbackAll(IndexData.PendingChange change)booleanshouldIgnoreNulls()Whether or notnullvalues are actually recorded in the index.StringtoString()voidupdate()Writes the current index state to the database.voidvalidate(boolean forceLoad)Used by unit tests to validate the internal status of the index.
-
-
-
Field Detail
-
FIRST_ENTRY
public static final IndexData.Entry FIRST_ENTRY
special entry which is less than any other entry
-
LAST_ENTRY
public static final IndexData.Entry LAST_ENTRY
special entry which is greater than any other entry
-
MAX_VALUE
public static final Object MAX_VALUE
special object which will always be greater than any other value, when searching for an index entry range in a multi-value index
-
MIN_VALUE
public static final Object MIN_VALUE
special object which will always be greater than any other value, when searching for an index entry range in a multi-value index
-
MAX_COLUMNS
public static final int MAX_COLUMNS
Max number of columns in an index- See Also:
- Constant Field Values
-
ASCENDING_COLUMN_FLAG
public static final byte ASCENDING_COLUMN_FLAG
- See Also:
- Constant Field Values
-
UNIQUE_INDEX_FLAG
public static final byte UNIQUE_INDEX_FLAG
- See Also:
- Constant Field Values
-
IGNORE_NULLS_INDEX_FLAG
public static final byte IGNORE_NULLS_INDEX_FLAG
- See Also:
- Constant Field Values
-
REQUIRED_INDEX_FLAG
public static final byte REQUIRED_INDEX_FLAG
- See Also:
- Constant Field Values
-
UNKNOWN_INDEX_FLAG
public static final byte UNKNOWN_INDEX_FLAG
- See Also:
- Constant Field Values
-
BYTE_CODE_COMPARATOR
public static final Comparator<byte[]> BYTE_CODE_COMPARATOR
-
-
Method Detail
-
create
public static IndexData create(TableImpl table, ByteBuffer tableBuffer, int number, JetFormat format)
Creates an IndexData appropriate for the given table, using information from the given table definition buffer.
-
getName
public String getName()
-
getTable
public TableImpl getTable()
-
getFormat
public JetFormat getFormat()
-
getPageChannel
public PageChannel getPageChannel()
-
getPrimaryIndex
public Index getPrimaryIndex()
- Returns:
- the "main" logical index which is backed by this data.
-
getIndexes
public List<Index> getIndexes()
- Returns:
- All of the Indexes backed by this data (unmodifiable List)
-
getIndexFlags
public byte getIndexFlags()
-
getIndexDataNumber
public int getIndexDataNumber()
-
getUniqueEntryCount
public int getUniqueEntryCount()
-
getUniqueEntryCountOffset
public int getUniqueEntryCountOffset()
-
shouldIgnoreNulls
public boolean shouldIgnoreNulls()
Whether or notnullvalues are actually recorded in the index.
-
isUnique
public boolean isUnique()
Whether or not index entries must be unique.Some notes about uniqueness:
- Access does not seem to consider multiple
nullentries invalid for a unique index - text indexes collapse case, and Access seems to compare only the index entry bytes, therefore two strings which differ only in case will violate the unique constraint
- Access does not seem to consider multiple
-
isRequired
public boolean isRequired()
Whether or not values are required in the columns.
-
getColumns
public List<IndexData.ColumnDescriptor> getColumns()
Returns the Columns for this index (unmodifiable)
-
getColumnCount
public int getColumnCount()
-
isInitialized
public boolean isInitialized()
Whether or not the complete index state has been read.
-
getOwnedPageCount
public int getOwnedPageCount()
Returns the number of database pages owned by this index data.- Usage:
- Intermediate: This method requires moderate API knowledge.
-
validate
public void validate(boolean forceLoad) throws IOExceptionUsed by unit tests to validate the internal status of the index.- Parameters:
forceLoad- iffalseonly validate currently loaded index data pages, otherwise, load and validate all index pages- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
getEntryCount
public int getEntryCount() throws IOExceptionReturns the number of index entries in the index. Only called by unit tests.Forces index initialization.
- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
initialize
public void initialize() throws IOExceptionForces initialization of this index (actual parsing of index pages). normally, the index will not be initialized until the entries are actually needed.- Throws:
IOException
-
update
public void update() throws IOExceptionWrites the current index state to the database.Forces index initialization.
- Throws:
IOException
-
read
public void read(ByteBuffer tableBuffer, List<ColumnImpl> availableColumns) throws IOException
Read the rest of the index info from a tableBuffer- Parameters:
tableBuffer- table definition buffer to read from initial infoavailableColumns- Columns that this index may use- Throws:
IOException
-
prepareAddRow
public IndexData.PendingChange prepareAddRow(Object[] row, RowIdImpl rowId, IndexData.PendingChange nextChange) throws IOException
Prepares to add a row to this index. All constraints are checked before this method returns.Forces index initialization.
- Parameters:
row- Row to addrowId- rowId of the row to be added- Returns:
- a PendingChange which can complete the addition or roll it back
- Throws:
IOException
-
prepareUpdateRow
public IndexData.PendingChange prepareUpdateRow(Object[] oldRow, RowIdImpl rowId, Object[] newRow, IndexData.PendingChange nextChange) throws IOException
Prepares to update a row in this index. All constraints are checked before this method returns.Forces index initialization.
- Parameters:
oldRow- Row to be removednewRow- Row to be addedrowId- rowId of the row to be updated- Returns:
- a PendingChange which can complete the update or roll it back
- Throws:
IOException
-
deleteRow
public void deleteRow(Object[] row, RowIdImpl rowId) throws IOException
Removes a row from this indexForces index initialization.
- Parameters:
row- Row to removerowId- rowId of the row to be removed- Throws:
IOException
-
commitAll
public static void commitAll(IndexData.PendingChange change) throws IOException
- Throws:
IOException
-
rollbackAll
public static void rollbackAll(IndexData.PendingChange change) throws IOException
- Throws:
IOException
-
cursor
public IndexData.EntryCursor cursor() throws IOException
Gets a new cursor for this index.Forces index initialization.
- Throws:
IOException
-
cursor
public IndexData.EntryCursor cursor(Object[] startRow, boolean startInclusive, Object[] endRow, boolean endInclusive) throws IOException
Gets a new cursor for this index, narrowed to the range defined by the given startRow and endRow.Forces index initialization.
- Parameters:
startRow- the first row of data for the cursor, ornullfor the first entrystartInclusive- whether or not startRow is inclusive or exclusiveendRow- the last row of data for the cursor, ornullfor the last entryendInclusive- whether or not endRow is inclusive or exclusive- Throws:
IOException
-
constructIndexRowFromEntry
public Object[] constructIndexRowFromEntry(Object... values)
Constructs an array of values appropriate for this index from the given column values, expected to match the columns for this index.- Returns:
- the appropriate sparse array of data
- Throws:
IllegalArgumentException- if the wrong number of values are provided
-
constructPartialIndexRowFromEntry
public Object[] constructPartialIndexRowFromEntry(Object filler, Object... values)
Constructs an array of values appropriate for this index from the given column values, possibly only providing a prefix subset of the index columns (at least one value must be provided). If a prefix entry is provided, any missing, trailing index entry values will use the given filler value.- Returns:
- the appropriate sparse array of data
- Throws:
IllegalArgumentException- if at least one value is not provided
-
constructIndexRow
public Object[] constructIndexRow(String colName, Object value)
Constructs an array of values appropriate for this index from the given column value.- Returns:
- the appropriate sparse array of data or
nullif not all columns for this index were provided
-
constructPartialIndexRow
public Object[] constructPartialIndexRow(Object filler, String colName, Object value)
Constructs an array of values appropriate for this index from the given column value, which must be the first column of the index. Any missing, trailing index entry values will use the given filler value.- Returns:
- the appropriate sparse array of data or
nullif no prefix list of columns for this index were provided
-
constructIndexRow
public Object[] constructIndexRow(Map<String,?> row)
Constructs an array of values appropriate for this index from the given column values.- Returns:
- the appropriate sparse array of data or
nullif not all columns for this index were provided
-
constructPartialIndexRow
public Object[] constructPartialIndexRow(Object filler, Map<String,?> row)
Constructs an array of values appropriate for this index from the given column values, possibly only using a subset of the given values. A partial row can be created if one or more prefix column values are provided. If a prefix can be found, any missing, trailing index entry values will use the given filler value.- Returns:
- the appropriate sparse array of data or
nullif no prefix list of columns for this index were provided
-
-