com.healthmarketscience.jackcess.impl
Class TableImpl

java.lang.Object
  extended by com.healthmarketscience.jackcess.impl.TableImpl
All Implemented Interfaces:
Table, Iterable<Row>

public class TableImpl
extends Object
implements Table

A single database table

Is not thread-safe.

Author:
Tim McCune
Usage:
Intermediate: This class requires moderate API knowledge.

Nested Class Summary
static class TableImpl.IndexFeature
           
 class TableImpl.RowState
          Maintains the state of reading/updating a row of data.
 
Nested classes/interfaces inherited from interface com.healthmarketscience.jackcess.Table
Table.ColumnOrder
 
Field Summary
static byte TYPE_SYSTEM
          Table type code for system tables
static byte TYPE_USER
          Table type code for user tables
 
Method Summary
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.
 Object[] addRow(Object... row)
          Adds a single row to this table and writes it to disk.
<M extends Map<String,Object>>
M
addRowFromMap(M row)
          Calls Table.asRow(java.util.Map) on the given row map and passes the result to Table.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)
          Calls Table.asRow(java.util.Map) on the given row maps and passes the results to Table.addRows(java.util.List).
 Object[] asRow(Map<String,?> rowMap)
          Converts a map of columnName -> columnValue to an array of row values appropriate for a call to Table.addRow(Object...).
 Object[] asRowWithRowId(Map<String,?> rowMap)
          Converts a map of columnName -> columnValue to an array of row values appropriate for a call to addRow(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 to Cursor.updateCurrentRow(Object...).
static short cleanRowStart(short rowStart)
           
 TableImpl.RowState createRowState()
           
 Row deleteRow(Row row)
          Delete the given row.
 RowId deleteRow(RowId rowId)
          Delete the row with the given id.
 void deleteRow(TableImpl.RowState rowState, RowIdImpl rowId)
          Delete the row for the given rowId.
 String display()
           
 String display(long limit)
           
 IndexImpl findIndexForColumns(Collection<String> searchColumns, TableImpl.IndexFeature feature)
           
static short findRowEnd(ByteBuffer buffer, int rowNum, JetFormat format)
           
static short findRowStart(ByteBuffer buffer, int rowNum, JetFormat format)
           
 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).
 ColumnImpl getColumn(String name)
           
 int getColumnCount()
           
 List<ColumnImpl> getColumns()
           
 DatabaseImpl getDatabase()
           
 CursorImpl getDefaultCursor()
           
 ErrorHandler getErrorHandler()
          Gets the currently configured ErrorHandler (always non-null).
 IndexImpl getForeignKeyIndex(Table otherTable)
           
 JetFormat getFormat()
           
 IndexImpl getIndex(String name)
           
 List<IndexData> getIndexDatas()
           
 List<IndexImpl> getIndexes()
           
 int getLogicalIndexCount()
          Only called by unit tests
 int getMaxColumnCount()
           
 String getName()
           
 Row getNextRow()
           
 UsageMap.PageCursor getOwnedPagesCursor()
           
 PageChannel getPageChannel()
           
 IndexImpl getPrimaryKeyIndex()
           
 PropertyMap getProperties()
           
 PropertyMaps getPropertyMaps()
           
 RowImpl getRow(TableImpl.RowState rowState, RowIdImpl rowId, Collection<String> columnNames)
          Reads some columns from the given row.
 int getRowCount()
           
static int getRowEndOffset(int rowNum, JetFormat format)
           
 RowId getRowId(Object[] row)
           
static int getRowSpaceUsage(int rowSize, JetFormat format)
           
static int getRowStartOffset(int rowNum, JetFormat format)
           
 Object getRowValue(TableImpl.RowState rowState, RowIdImpl rowId, ColumnImpl column)
          Reads a single column from the given row.
 int getTableDefPageNumber()
           
 boolean hasColumn(String name)
           
 boolean isAllowAutoNumberInsert()
          Gets the currently configured auto number insert policy.
static boolean isDeletedRow(short rowStart)
           
 boolean isHidden()
          Whether or not this table has been marked as hidden.
static boolean isOverflowRow(short rowStart)
           
 boolean isSystem()
          Whether or not this table is a system (internal) table.
 Iterator<Row> iterator()
          Calls Table.reset() on this table and returns a modifiable Iterator which will iterate through all the rows of this table.
 CursorBuilder newCursor()
          Convenience method for constructing a new CursorBuilder for this Table.
static ByteBuffer positionAtRowData(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 ByteBuffer positionAtRowHeader(TableImpl.RowState rowState, RowIdImpl rowId)
          Sets a new buffer to the correct row header page using the given rowState according to the given rowId.
 void reset()
          After calling this method, Table.getNextRow() will return the first row in the table, see Cursor.reset() (uses the default cursor).
static boolean rowFitsOnDataPage(int rowLength, ByteBuffer dataPage, JetFormat format)
          Returns true if a row of the given size will fit on the given data page, false otherwise.
 void setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
          Sets the new auto number insert policy for the Table.
 void setErrorHandler(ErrorHandler newErrorHandler)
          Sets a new ErrorHandler.
 String toString()
           
 Row updateRow(Row row)
          Update the given row.
 Object[] updateRow(RowId rowId, Object... row)
          Update the row with the given id.
 Object[] updateRow(TableImpl.RowState rowState, RowIdImpl rowId, Object... row)
          Update the row for the given rowId.
<M extends Map<String,Object>>
M
updateRowFromMap(TableImpl.RowState rowState, RowIdImpl rowId, M row)
           
 void updateValue(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
 

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:
getName in interface Table
Returns:
The name of the table

isHidden

public boolean isHidden()
Description copied from interface: Table
Whether or not this table has been marked as hidden.

Specified by:
isHidden in interface Table

isSystem

public boolean isSystem()
Description copied from interface: Table
Whether or not this table is a system (internal) table.

Specified by:
isSystem in interface Table

getMaxColumnCount

public int getMaxColumnCount()
Usage:
Advanced: This method is for advanced/internal use.

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface Table

getDatabase

public DatabaseImpl getDatabase()
Specified by:
getDatabase in interface Table

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: Table
Gets the currently configured ErrorHandler (always non-null). This will be used to handle all errors unless overridden at the Cursor level.

Specified by:
getErrorHandler in interface Table

setErrorHandler

public void setErrorHandler(ErrorHandler newErrorHandler)
Description copied from interface: Table
Sets a new ErrorHandler. If null, resets to using the ErrorHandler configured at the Database level.

Specified by:
setErrorHandler in interface Table

getTableDefPageNumber

public int getTableDefPageNumber()

isAllowAutoNumberInsert

public boolean isAllowAutoNumberInsert()
Description copied from interface: Table
Gets the currently configured auto number insert policy.

Specified by:
isAllowAutoNumberInsert in interface Table
See Also:
Database.isAllowAutoNumberInsert()

setAllowAutoNumberInsert

public void setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
Description copied from interface: Table
Sets the new auto number insert policy for the Table. If null, resets to using the policy configured at the Database level.

Specified by:
setAllowAutoNumberInsert in interface Table

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:
getColumns in interface Table
Returns:
All of the columns in this table (unmodifiable List)

getColumn

public ColumnImpl getColumn(String name)
Specified by:
getColumn in interface Table
Returns:
the column with the given name

hasColumn

public boolean hasColumn(String name)

getProperties

public PropertyMap getProperties()
                          throws IOException
Specified by:
getProperties in interface Table
Returns:
the properties for this table
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.

getIndexes

public List<IndexImpl> getIndexes()
Specified by:
getIndexes in interface Table
Returns:
All of the Indexes on this table (unmodifiable List)

getIndex

public IndexImpl getIndex(String name)
Specified by:
getIndex in interface Table
Returns:
the index with the given name

getPrimaryKeyIndex

public IndexImpl getPrimaryKeyIndex()
Specified by:
getPrimaryKeyIndex in interface Table
Returns:
the primary key index for this table

getForeignKeyIndex

public IndexImpl getForeignKeyIndex(Table otherTable)
Specified by:
getForeignKeyIndex in interface Table
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:
getDefaultCursor in interface Table
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: Table
Convenience method for constructing a new CursorBuilder for this Table.

Specified by:
newCursor in interface Table

reset

public void reset()
Description copied from interface: Table
After calling this method, Table.getNextRow() will return the first row in the table, see Cursor.reset() (uses the default cursor).

Specified by:
reset in interface Table

deleteRow

public Row deleteRow(Row row)
              throws IOException
Description copied from interface: Table
Delete the given row. Provided Row must have previously been returned from this Table.

Specified by:
deleteRow in interface Table
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 valid
IOException
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:
getNextRow in interface Table
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: Table
Calls Table.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 to Table.getNextRow().

For more advanced iteration, use the default cursor directly.

Specified by:
iterator in interface Table
Specified by:
iterator in interface Iterable<Row>

asRow

public Object[] asRow(Map<String,?> rowMap)
Description copied from interface: Table
Converts a map of columnName -> columnValue to an array of row values appropriate for a call to Table.addRow(Object...).

Specified by:
asRow in interface Table

asRowWithRowId

public Object[] asRowWithRowId(Map<String,?> rowMap)
Converts a map of columnName -> columnValue to an array of row values appropriate for a call to addRow(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: Table
Converts a map of columnName -> columnValue to an array of row values appropriate for a call to Cursor.updateCurrentRow(Object...).

Specified by:
asUpdateRow in interface Table

getRowId

public RowId getRowId(Object[] row)
Returns:
the generated RowId added to a row of values created via asRowWithRowId(java.util.Map)
Usage:
Intermediate: This method requires moderate API knowledge.

addRow

public Object[] addRow(Object... row)
                throws IOException
Description copied from interface: Table
Adds 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 the Table.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 via Database.setColumnOrder(com.healthmarketscience.jackcess.Table.ColumnOrder) prior to opening the Table. The Table.asRow(java.util.Map) 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:
addRow in interface Table
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: Table
Calls Table.asRow(java.util.Map) on the given row map and passes the result to Table.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:
addRowFromMap in interface Table
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: Table
Add 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 calling Table.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 BatchUpdateException which gives useful information in the case of a partially successful write.

Specified by:
addRows in interface Table
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: Table
Calls Table.asRow(java.util.Map) on the given row maps and passes the results to Table.addRows(java.util.List).

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 BatchUpdateException which gives useful information in the case of a partially successful write.

Specified by:
addRowsFromMaps in interface Table
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: Table
Update the given row. Provided Row must have previously been returned from this Table.

Specified by:
updateRow in interface Table
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:
getRowCount in interface Table

toString

public String toString()
Overrides:
toString in class Object

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)
                                 throws IOException
Returns true if a row of the given size will fit on the given data page, false otherwise.

Throws:
IOException
Usage:
Advanced: This method is for advanced/internal use.


Copyright © 2005–2017 Health Market Science. All rights reserved.