Class TableImpl
- java.lang.Object
-
- com.healthmarketscience.jackcess.impl.TableImpl
-
- All Implemented Interfaces:
Table,TableDefinition,Iterable<Row>
- Direct Known Subclasses:
TableDefinitionImpl
public class TableImpl extends Object implements Table
A single database tableIs not thread-safe.
- Author:
- Tim McCune
- Usage:
- Intermediate: This class requires moderate API knowledge.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTableImpl.IndexFeatureclassTableImpl.RowStateMaintains the state of reading/updating a row of data.-
Nested classes/interfaces inherited from interface com.healthmarketscience.jackcess.Table
Table.ColumnOrder
-
-
Field Summary
Fields Modifier and Type Field Description static byteTYPE_SYSTEMTable type code for system tablesstatic byteTYPE_USERTable type code for user tables
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intaddDataPageRow(ByteBuffer dataPage, int rowSize, JetFormat format, int rowFlags)Updates free space and row info for a new row of the given size in the given data page.Object[]addRow(Object... row)Adds a single row to this table and writes it to disk.<M extends Map<String,Object>>
MaddRowFromMap(M row)CallsTable.asRow(java.util.Map<java.lang.String, ?>)on the given row map and passes the result toTable.addRow(java.lang.Object...).List<? extends Object[]>addRows(List<? extends Object[]> rows)Add multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled.<M extends Map<String,Object>>
List<M>addRowsFromMaps(List<M> rows)CallsTable.asRow(java.util.Map<java.lang.String, ?>)on the given row maps and passes the results toTable.addRows(java.util.List<? extends java.lang.Object[]>).Object[]asRow(Map<String,?> rowMap)Converts a map of columnName -> columnValue to an array of row values appropriate for a call toTable.addRow(Object...).Object[]asRowWithRowId(Map<String,?> rowMap)Converts a map of columnName -> columnValue to an array of row values appropriate for a call toaddRow(Object...), where the generated RowId will be an extra value at the end of the array.Object[]asUpdateRow(Map<String,?> rowMap)Converts a map of columnName -> columnValue to an array of row values appropriate for a call toCursor.updateCurrentRow(Object...).static shortcleanRowStart(short rowStart)TableImpl.RowStatecreateRowState()voiddeleteRow(TableImpl.RowState rowState, RowIdImpl rowId)Delete the row for the given rowId.RowdeleteRow(Row row)Delete the given row.RowIddeleteRow(RowId rowId)Delete the row with the given id.Stringdisplay()Stringdisplay(long limit)IndexImplfindIndexForColumns(Collection<String> searchColumns, TableImpl.IndexFeature feature)static shortfindRowEnd(ByteBuffer buffer, int rowNum, JetFormat format)static shortfindRowStart(ByteBuffer buffer, int rowNum, JetFormat format)intgetApproximateOwnedPageCount()Returns the approximate number of database pages owned by this table and all related indexes (this number does not take into account pages used for large OLE/MEMO fields).ColumnImplgetColumn(String name)intgetColumnCount()List<ColumnImpl>getColumns()LocalDateTimegetCreatedDate()DatabaseImplgetDatabase()CursorImplgetDefaultCursor()ErrorHandlergetErrorHandler()Gets the currently configured ErrorHandler (always non-null).IndexImplgetForeignKeyIndex(Table otherTable)JetFormatgetFormat()IndexImplgetIndex(String name)List<IndexData>getIndexDatas()List<IndexImpl>getIndexes()intgetLogicalIndexCount()Only called by unit testsintgetMaxColumnCount()StringgetName()RowgetNextRow()UsageMap.PageCursorgetOwnedPagesCursor()PageChannelgetPageChannel()IndexImplgetPrimaryKeyIndex()PropertyMapgetProperties()PropertyMapsgetPropertyMaps()RowImplgetRow(TableImpl.RowState rowState, RowIdImpl rowId, Collection<String> columnNames)Reads some columns from the given row.intgetRowCount()static intgetRowEndOffset(int rowNum, JetFormat format)RowIdgetRowId(Object[] row)static intgetRowSpaceUsage(int rowSize, JetFormat format)static intgetRowStartOffset(int rowNum, JetFormat format)ObjectgetRowValue(TableImpl.RowState rowState, RowIdImpl rowId, ColumnImpl column)Reads a single column from the given row.intgetTableDefPageNumber()LocalDateTimegetUpdatedDate()Note: jackcess does not automatically update the modified date of a Table.booleanhasColumn(String name)booleanisAllowAutoNumberInsert()Gets the currently configured auto number insert policy.static booleanisDeletedRow(short rowStart)booleanisHidden()Whether or not this table has been marked as hidden.static booleanisOverflowRow(short rowStart)booleanisSystem()Whether or not this table is a system (internal) table.Iterator<Row>iterator()CallsTable.reset()on this table and returns a modifiable Iterator which will iterate through all the rows of this table.CursorBuildernewCursor()Convenience method for constructing a new CursorBuilder for this Table.static ByteBufferpositionAtRowData(TableImpl.RowState rowState, RowIdImpl rowId)Sets the position and limit in a new buffer using the given rowState according to the given row number and row end, following overflow row pointers as necessary.static ByteBufferpositionAtRowHeader(TableImpl.RowState rowState, RowIdImpl rowId)Sets a new buffer to the correct row header page using the given rowState according to the given rowId.voidpropertiesUpdated()voidreset()After calling this method,Table.getNextRow()will return the first row in the table, seeCursor.reset()(uses thedefault cursor).static booleanrowFitsOnDataPage(int rowLength, ByteBuffer dataPage, JetFormat format)Returnstrueif a row of the given size will fit on the given data page,falseotherwise.voidsetAllowAutoNumberInsert(Boolean allowAutoNumInsert)Sets the new auto number insert policy for the Table.voidsetErrorHandler(ErrorHandler newErrorHandler)Sets a new ErrorHandler.StringtoString()Object[]updateRow(TableImpl.RowState rowState, RowIdImpl rowId, Object... row)Update the row for the given rowId.RowupdateRow(Row row)Update the given row.Object[]updateRow(RowId rowId, Object... row)Update the row with the given id.<M extends Map<String,Object>>
MupdateRowFromMap(TableImpl.RowState rowState, RowIdImpl rowId, M row)voidupdateValue(Column column, RowId rowId, Object value)Update the given column's value for the given row id.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
TYPE_SYSTEM
public static final byte TYPE_SYSTEM
Table type code for system tables- See Also:
- Constant Field Values
- Usage:
- Intermediate: This class requires moderate API knowledge.
-
TYPE_USER
public static final byte TYPE_USER
Table type code for user tables- See Also:
- Constant Field Values
- Usage:
- Intermediate: This class requires moderate API knowledge.
-
-
Method Detail
-
getName
public String getName()
- Specified by:
getNamein interfaceTable- Specified by:
getNamein interfaceTableDefinition- Returns:
- The name of the table
-
isHidden
public boolean isHidden()
Description copied from interface:TableWhether or not this table has been marked as hidden.- Specified by:
isHiddenin interfaceTable- Specified by:
isHiddenin interfaceTableDefinition
-
isSystem
public boolean isSystem()
Description copied from interface:TableWhether or not this table is a system (internal) table.- Specified by:
isSystemin interfaceTable- Specified by:
isSystemin interfaceTableDefinition
-
getMaxColumnCount
public int getMaxColumnCount()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCountin interfaceTable- Specified by:
getColumnCountin interfaceTableDefinition
-
getDatabase
public DatabaseImpl getDatabase()
- Specified by:
getDatabasein interfaceTable- Specified by:
getDatabasein interfaceTableDefinition
-
getFormat
public JetFormat getFormat()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getPageChannel
public PageChannel getPageChannel()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getErrorHandler
public ErrorHandler getErrorHandler()
Description copied from interface:TableGets the currently configured ErrorHandler (always non-null). This will be used to handle all errors unless overridden at the Cursor level.- Specified by:
getErrorHandlerin interfaceTable
-
setErrorHandler
public void setErrorHandler(ErrorHandler newErrorHandler)
Description copied from interface:TableSets a new ErrorHandler. Ifnull, resets to using the ErrorHandler configured at the Database level.- Specified by:
setErrorHandlerin interfaceTable
-
getTableDefPageNumber
public int getTableDefPageNumber()
-
isAllowAutoNumberInsert
public boolean isAllowAutoNumberInsert()
Description copied from interface:TableGets the currently configured auto number insert policy.- Specified by:
isAllowAutoNumberInsertin interfaceTable- See Also:
Database.isAllowAutoNumberInsert()
-
setAllowAutoNumberInsert
public void setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
Description copied from interface:TableSets the new auto number insert policy for the Table. Ifnull, resets to using the policy configured at the Database level.- Specified by:
setAllowAutoNumberInsertin interfaceTable
-
createRowState
public TableImpl.RowState createRowState()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getOwnedPagesCursor
public UsageMap.PageCursor getOwnedPagesCursor()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getApproximateOwnedPageCount
public int getApproximateOwnedPageCount()
Returns the approximate number of database pages owned by this table and all related indexes (this number does not take into account pages used for large OLE/MEMO fields).To calculate the approximate number of bytes owned by a table:
int approxTableBytes = (table.getApproximateOwnedPageCount() * table.getFormat().PAGE_SIZE);- Usage:
- Intermediate: This method requires moderate API knowledge.
-
getColumns
public List<ColumnImpl> getColumns()
- Specified by:
getColumnsin interfaceTable- Specified by:
getColumnsin interfaceTableDefinition- Returns:
- All of the columns in this table (unmodifiable List)
-
getColumn
public ColumnImpl getColumn(String name)
- Specified by:
getColumnin interfaceTable- Specified by:
getColumnin interfaceTableDefinition- Returns:
- the column with the given name
-
hasColumn
public boolean hasColumn(String name)
-
getProperties
public PropertyMap getProperties() throws IOException
- Specified by:
getPropertiesin interfaceTable- Specified by:
getPropertiesin interfaceTableDefinition- Returns:
- the properties for this table
- Throws:
IOException
-
getCreatedDate
public LocalDateTime getCreatedDate() throws IOException
- Specified by:
getCreatedDatein interfaceTable- Specified by:
getCreatedDatein interfaceTableDefinition- Returns:
- the created date for this table if available
- Throws:
IOException
-
getUpdatedDate
public LocalDateTime getUpdatedDate() throws IOException
Description copied from interface:TableNote: jackcess does not automatically update the modified date of a Table.- Specified by:
getUpdatedDatein interfaceTable- Specified by:
getUpdatedDatein interfaceTableDefinition- Returns:
- the last updated date for this table if available
- Throws:
IOException
-
getPropertyMaps
public PropertyMaps getPropertyMaps() throws IOException
- Returns:
- all PropertyMaps for this table (and columns)
- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
propertiesUpdated
public void propertiesUpdated() throws IOException- Throws:
IOException
-
getIndexes
public List<IndexImpl> getIndexes()
- Specified by:
getIndexesin interfaceTable- Specified by:
getIndexesin interfaceTableDefinition- Returns:
- All of the Indexes on this table (unmodifiable List)
-
getIndex
public IndexImpl getIndex(String name)
- Specified by:
getIndexin interfaceTable- Specified by:
getIndexin interfaceTableDefinition- Returns:
- the index with the given name
-
getPrimaryKeyIndex
public IndexImpl getPrimaryKeyIndex()
- Specified by:
getPrimaryKeyIndexin interfaceTable- Specified by:
getPrimaryKeyIndexin interfaceTableDefinition- Returns:
- the primary key index for this table
-
getForeignKeyIndex
public IndexImpl getForeignKeyIndex(Table otherTable)
- Specified by:
getForeignKeyIndexin interfaceTable- Specified by:
getForeignKeyIndexin interfaceTableDefinition- Returns:
- the foreign key index joining this table to the given other table
-
getIndexDatas
public List<IndexData> getIndexDatas()
- Returns:
- All of the IndexData on this table (unmodifiable List)
- Usage:
- Advanced: This method is for advanced/internal use.
-
getLogicalIndexCount
public int getLogicalIndexCount()
Only called by unit tests- Usage:
- Advanced: This method is for advanced/internal use.
-
findIndexForColumns
public IndexImpl findIndexForColumns(Collection<String> searchColumns, TableImpl.IndexFeature feature)
-
getDefaultCursor
public CursorImpl getDefaultCursor()
- Specified by:
getDefaultCursorin interfaceTable- Returns:
- a simple Cursor, initialized on demand and held by this table. This cursor backs the row traversal methods available on the Table interface. For advanced Table traversal and manipulation, use the Cursor directly.
-
newCursor
public CursorBuilder newCursor()
Description copied from interface:TableConvenience method for constructing a new CursorBuilder for this Table.
-
reset
public void reset()
Description copied from interface:TableAfter calling this method,Table.getNextRow()will return the first row in the table, seeCursor.reset()(uses thedefault cursor).
-
deleteRow
public Row deleteRow(Row row) throws IOException
Description copied from interface:TableDelete the given row. Provided Row must have previously been returned from this Table.- Specified by:
deleteRowin interfaceTable- Returns:
- the given row
- Throws:
IOException
-
deleteRow
public RowId deleteRow(RowId rowId) throws IOException
Delete the row with the given id. Provided RowId must have previously been returned from this Table.- Returns:
- the given rowId
- Throws:
IllegalStateException- if the given row is not validIOException- Usage:
- Intermediate: This method requires moderate API knowledge.
-
deleteRow
public void deleteRow(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
Delete the row for the given rowId.- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
getNextRow
public Row getNextRow() throws IOException
- Specified by:
getNextRowin interfaceTable- Returns:
- The next row in this table (Column name -> Column value) (uses
the
default cursor) - Throws:
IOException
-
getRowValue
public Object getRowValue(TableImpl.RowState rowState, RowIdImpl rowId, ColumnImpl column) throws IOException
Reads a single column from the given row.- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
getRow
public RowImpl getRow(TableImpl.RowState rowState, RowIdImpl rowId, Collection<String> columnNames) throws IOException
Reads some columns from the given row.- Parameters:
columnNames- Only column names in this collection will be returned- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
positionAtRowHeader
public static ByteBuffer positionAtRowHeader(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
Sets a new buffer to the correct row header page using the given rowState according to the given rowId. Deleted state is determined, but overflow row pointers are not followed.- Returns:
- a ByteBuffer of the relevant page, or null if row was invalid
- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
positionAtRowData
public static ByteBuffer positionAtRowData(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
Sets the position and limit in a new buffer using the given rowState according to the given row number and row end, following overflow row pointers as necessary.- Returns:
- a ByteBuffer narrowed to the actual row data, or null if row was invalid or deleted
- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
iterator
public Iterator<Row> iterator()
Description copied from interface:TableCallsTable.reset()on this table and returns a modifiable Iterator which will iterate through all the rows of this table. Use of the Iterator follows the same restrictions as a call toTable.getNextRow().For more advanced iteration, use the
default cursordirectly.
-
asRow
public Object[] asRow(Map<String,?> rowMap)
Description copied from interface:TableConverts a map of columnName -> columnValue to an array of row values appropriate for a call toTable.addRow(Object...).
-
asRowWithRowId
public Object[] asRowWithRowId(Map<String,?> rowMap)
Converts a map of columnName -> columnValue to an array of row values appropriate for a call toaddRow(Object...), where the generated RowId will be an extra value at the end of the array.- See Also:
ColumnImpl.RETURN_ROW_ID- Usage:
- Intermediate: This method requires moderate API knowledge.
-
asUpdateRow
public Object[] asUpdateRow(Map<String,?> rowMap)
Description copied from interface:TableConverts a map of columnName -> columnValue to an array of row values appropriate for a call toCursor.updateCurrentRow(Object...).- Specified by:
asUpdateRowin interfaceTable
-
getRowId
public RowId getRowId(Object[] row)
- Returns:
- the generated RowId added to a row of values created via
asRowWithRowId(java.util.Map<java.lang.String, ?>) - Usage:
- Intermediate: This method requires moderate API knowledge.
-
addRow
public Object[] addRow(Object... row) throws IOException
Description copied from interface:TableAdds a single row to this table and writes it to disk. The values are expected to be given in the order that the Columns are listed by theTable.getColumns()method. This is by default the storage order of the Columns in the database, however this order can be influenced by setting the ColumnOrder viaDatabase.setColumnOrder(com.healthmarketscience.jackcess.Table.ColumnOrder)prior to opening the Table. TheTable.asRow(java.util.Map<java.lang.String, ?>)method can be used to easily convert a row Map into the appropriate row array for this Table.Note, if this table has an auto-number column, the value generated will be put back into the given row array (assuming the given row array is at least as long as the number of Columns in this Table).
- Specified by:
addRowin interfaceTable- Parameters:
row- row values for a single row. the given row array will be modified if this table contains an auto-number column, otherwise it will not be modified.- Returns:
- the given row values if long enough, otherwise a new array. the returned array will contain any autonumbers generated
- Throws:
IOException
-
addRowFromMap
public <M extends Map<String,Object>> M addRowFromMap(M row) throws IOException
Description copied from interface:TableCallsTable.asRow(java.util.Map<java.lang.String, ?>)on the given row map and passes the result toTable.addRow(java.lang.Object...).Note, if this table has an auto-number column, the value generated will be put back into the given row map.
- Specified by:
addRowFromMapin interfaceTable- Returns:
- the given row map, which will contain any autonumbers generated
- Throws:
IOException
-
addRows
public List<? extends Object[]> addRows(List<? extends Object[]> rows) throws IOException
Description copied from interface:TableAdd multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled. This is much more efficient than callingTable.addRow(java.lang.Object...)multiple times.Note, if this table has an auto-number column, the values written will be put back into the given row arrays (assuming the given row array is at least as long as the number of Columns in this Table).
Most exceptions thrown from this method will be wrapped with a
BatchUpdateExceptionwhich gives useful information in the case of a partially successful write.- Specified by:
addRowsin interfaceTable- Parameters:
rows- List of Object[] row values. the rows will be modified if this table contains an auto-number column, otherwise they will not be modified.- Returns:
- the given row values list (unless row values were to small), with appropriately sized row values (the ones passed in if long enough). the returned arrays will contain any autonumbers generated
- Throws:
IOException- See Also:
for more details on row arrays
-
addRowsFromMaps
public <M extends Map<String,Object>> List<M> addRowsFromMaps(List<M> rows) throws IOException
Description copied from interface:TableCallsTable.asRow(java.util.Map<java.lang.String, ?>)on the given row maps and passes the results toTable.addRows(java.util.List<? extends java.lang.Object[]>).Note, if this table has an auto-number column, the values generated will be put back into the appropriate row maps.
Most exceptions thrown from this method will be wrapped with a
BatchUpdateExceptionwhich gives useful information in the case of a partially successful write.- Specified by:
addRowsFromMapsin interfaceTable- Returns:
- the given row map list, where the row maps will contain any autonumbers generated
- Throws:
IOException
-
updateRow
public Row updateRow(Row row) throws IOException
Description copied from interface:TableUpdate the given row. Provided Row must have previously been returned from this Table.- Specified by:
updateRowin interfaceTable- Returns:
- the given row, updated with the current row values
- Throws:
IOException
-
updateRow
public Object[] updateRow(RowId rowId, Object... row) throws IOException
Update the row with the given id. Provided RowId must have previously been returned from this Table.- Returns:
- the given row, updated with the current row values
- Throws:
IllegalStateException- if the given row is not valid, or deleted.IOException- Usage:
- Intermediate: This method requires moderate API knowledge.
-
updateValue
public void updateValue(Column column, RowId rowId, Object value) throws IOException
Update the given column's value for the given row id. Provided RowId must have previously been returned from this Table.- Throws:
IllegalStateException- if the given row is not valid, or deleted.IOException- Usage:
- Intermediate: This method requires moderate API knowledge.
-
updateRowFromMap
public <M extends Map<String,Object>> M updateRowFromMap(TableImpl.RowState rowState, RowIdImpl rowId, M row) throws IOException
- Throws:
IOException
-
updateRow
public Object[] updateRow(TableImpl.RowState rowState, RowIdImpl rowId, Object... row) throws IOException
Update the row for the given rowId.- Throws:
IOException- Usage:
- Advanced: This method is for advanced/internal use.
-
getRowCount
public int getRowCount()
- Specified by:
getRowCountin interfaceTable
-
display
public String display() throws IOException
- Returns:
- A simple String representation of the entire table in tab-delimited format
- Throws:
IOException- Usage:
- General: This method is general use.
-
display
public String display(long limit) throws IOException
- Parameters:
limit- Maximum number of rows to display- Returns:
- A simple String representation of the entire table in tab-delimited format
- Throws:
IOException- Usage:
- General: This method is general use.
-
addDataPageRow
public static int addDataPageRow(ByteBuffer dataPage, int rowSize, JetFormat format, int rowFlags)
Updates free space and row info for a new row of the given size in the given data page. Positions the page for writing the row data.- Returns:
- the row number of the new row
- Usage:
- Advanced: This method is for advanced/internal use.
-
isDeletedRow
public static boolean isDeletedRow(short rowStart)
- Usage:
- Advanced: This method is for advanced/internal use.
-
isOverflowRow
public static boolean isOverflowRow(short rowStart)
- Usage:
- Advanced: This method is for advanced/internal use.
-
cleanRowStart
public static short cleanRowStart(short rowStart)
- Usage:
- Advanced: This method is for advanced/internal use.
-
findRowStart
public static short findRowStart(ByteBuffer buffer, int rowNum, JetFormat format)
- Usage:
- Advanced: This method is for advanced/internal use.
-
getRowStartOffset
public static int getRowStartOffset(int rowNum, JetFormat format)- Usage:
- Advanced: This method is for advanced/internal use.
-
findRowEnd
public static short findRowEnd(ByteBuffer buffer, int rowNum, JetFormat format)
- Usage:
- Advanced: This method is for advanced/internal use.
-
getRowEndOffset
public static int getRowEndOffset(int rowNum, JetFormat format)- Usage:
- Advanced: This method is for advanced/internal use.
-
getRowSpaceUsage
public static int getRowSpaceUsage(int rowSize, JetFormat format)- Usage:
- Advanced: This method is for advanced/internal use.
-
rowFitsOnDataPage
public static boolean rowFitsOnDataPage(int rowLength, ByteBuffer dataPage, JetFormat format)Returnstrueif a row of the given size will fit on the given data page,falseotherwise.- Usage:
- Advanced: This method is for advanced/internal use.
-
-