public class TableImpl extends Object implements Table
Is not thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
TableImpl.IndexFeature |
class |
TableImpl.RowState
Maintains the state of reading/updating a row of data.
|
Table.ColumnOrder
Modifier and Type | Field and Description |
---|---|
static byte |
TYPE_SYSTEM
Table type code for system tables
|
static byte |
TYPE_USER
Table type code for user tables
|
Modifier and Type | Method and Description |
---|---|
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>> |
addRowFromMap(M row)
Calls
Table.asRow(java.util.Map<java.lang.String, ?>) 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>> |
addRowsFromMaps(List<M> rows)
Calls
Table.asRow(java.util.Map<java.lang.String, ?>) on the given row maps and passes the results to
Table.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 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() |
LocalDateTime |
getCreatedDate() |
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() |
LocalDateTime |
getUpdatedDate()
Note: jackcess does not automatically update the modified date of a
Table.
|
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 |
propertiesUpdated()
Invoked when new properties are saved.
|
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>> |
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.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final byte TYPE_SYSTEM
public static final byte TYPE_USER
public String getName()
getName
in interface Table
getName
in interface TableDefinition
public boolean isHidden()
Table
isHidden
in interface Table
isHidden
in interface TableDefinition
public boolean isSystem()
Table
isSystem
in interface Table
isSystem
in interface TableDefinition
public int getMaxColumnCount()
public int getColumnCount()
getColumnCount
in interface Table
getColumnCount
in interface TableDefinition
public DatabaseImpl getDatabase()
getDatabase
in interface Table
getDatabase
in interface TableDefinition
public JetFormat getFormat()
public PageChannel getPageChannel()
public ErrorHandler getErrorHandler()
Table
null
).
This will be used to handle all errors unless overridden at the Cursor
level.getErrorHandler
in interface Table
public void setErrorHandler(ErrorHandler newErrorHandler)
Table
null
, resets to using the
ErrorHandler configured at the Database level.setErrorHandler
in interface Table
public int getTableDefPageNumber()
public boolean isAllowAutoNumberInsert()
Table
isAllowAutoNumberInsert
in interface Table
Database.isAllowAutoNumberInsert()
public void setAllowAutoNumberInsert(Boolean allowAutoNumInsert)
Table
null
,
resets to using the policy configured at the Database level.setAllowAutoNumberInsert
in interface Table
public TableImpl.RowState createRowState()
public UsageMap.PageCursor getOwnedPagesCursor()
public int getApproximateOwnedPageCount()
To calculate the approximate number of bytes owned by a table:
int approxTableBytes = (table.getApproximateOwnedPageCount() *
table.getFormat().PAGE_SIZE);
public List<ColumnImpl> getColumns()
getColumns
in interface Table
getColumns
in interface TableDefinition
public ColumnImpl getColumn(String name)
getColumn
in interface Table
getColumn
in interface TableDefinition
public boolean hasColumn(String name)
public PropertyMap getProperties() throws IOException
getProperties
in interface Table
getProperties
in interface TableDefinition
IOException
public LocalDateTime getCreatedDate() throws IOException
getCreatedDate
in interface Table
getCreatedDate
in interface TableDefinition
IOException
public LocalDateTime getUpdatedDate() throws IOException
Table
getUpdatedDate
in interface Table
getUpdatedDate
in interface TableDefinition
IOException
public PropertyMaps getPropertyMaps() throws IOException
IOException
public void propertiesUpdated() throws IOException
IOException
public List<IndexImpl> getIndexes()
getIndexes
in interface Table
getIndexes
in interface TableDefinition
public IndexImpl getIndex(String name)
getIndex
in interface Table
getIndex
in interface TableDefinition
public IndexImpl getPrimaryKeyIndex()
getPrimaryKeyIndex
in interface Table
getPrimaryKeyIndex
in interface TableDefinition
public IndexImpl getForeignKeyIndex(Table otherTable)
getForeignKeyIndex
in interface Table
getForeignKeyIndex
in interface TableDefinition
public List<IndexData> getIndexDatas()
public int getLogicalIndexCount()
public IndexImpl findIndexForColumns(Collection<String> searchColumns, TableImpl.IndexFeature feature)
public CursorImpl getDefaultCursor()
getDefaultCursor
in interface Table
public CursorBuilder newCursor()
Table
public void reset()
Table
Table.getNextRow()
will return the first row
in the table, see Cursor.reset()
(uses the default cursor
).public Row deleteRow(Row row) throws IOException
Table
deleteRow
in interface Table
IOException
public RowId deleteRow(RowId rowId) throws IOException
IllegalStateException
- if the given row is not validIOException
public void deleteRow(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
IOException
public Row getNextRow() throws IOException
getNextRow
in interface Table
default cursor
)IOException
public Object getRowValue(TableImpl.RowState rowState, RowIdImpl rowId, ColumnImpl column) throws IOException
IOException
public RowImpl getRow(TableImpl.RowState rowState, RowIdImpl rowId, Collection<String> columnNames) throws IOException
columnNames
- Only column names in this collection will be returnedIOException
public static ByteBuffer positionAtRowHeader(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
IOException
public static ByteBuffer positionAtRowData(TableImpl.RowState rowState, RowIdImpl rowId) throws IOException
IOException
public Iterator<Row> iterator()
Table
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.
public Object[] asRow(Map<String,?> rowMap)
Table
Table.addRow(Object...)
.public Object[] asRowWithRowId(Map<String,?> rowMap)
addRow(Object...)
, where the generated
RowId will be an extra value at the end of the array.ColumnImpl.RETURN_ROW_ID
public Object[] asUpdateRow(Map<String,?> rowMap)
Table
Cursor.updateCurrentRow(Object...)
.asUpdateRow
in interface Table
public RowId getRowId(Object[] row)
asRowWithRowId(java.util.Map<java.lang.String, ?>)
public Object[] addRow(Object... row) throws IOException
Table
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<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).
addRow
in interface Table
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.IOException
public <M extends Map<String,Object>> M addRowFromMap(M row) throws IOException
Table
Table.asRow(java.util.Map<java.lang.String, ?>)
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.
addRowFromMap
in interface Table
IOException
public List<? extends Object[]> addRows(List<? extends Object[]> rows) throws IOException
Table
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.
addRows
in interface Table
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.IOException
for more details on row arrays
public <M extends Map<String,Object>> List<M> addRowsFromMaps(List<M> rows) throws IOException
Table
Table.asRow(java.util.Map<java.lang.String, ?>)
on the given row maps and passes the results to
Table.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 BatchUpdateException
which gives useful information in the case of a
partially successful write.
addRowsFromMaps
in interface Table
IOException
public Row updateRow(Row row) throws IOException
Table
updateRow
in interface Table
IOException
public Object[] updateRow(RowId rowId, Object... row) throws IOException
IllegalStateException
- if the given row is not valid, or deleted.IOException
public void updateValue(Column column, RowId rowId, Object value) throws IOException
IllegalStateException
- if the given row is not valid, or deleted.IOException
public <M extends Map<String,Object>> M updateRowFromMap(TableImpl.RowState rowState, RowIdImpl rowId, M row) throws IOException
IOException
public Object[] updateRow(TableImpl.RowState rowState, RowIdImpl rowId, Object... row) throws IOException
IOException
public int getRowCount()
getRowCount
in interface Table
public String display() throws IOException
IOException
public String display(long limit) throws IOException
limit
- Maximum number of rows to displayIOException
public static int addDataPageRow(ByteBuffer dataPage, int rowSize, JetFormat format, int rowFlags)
public static boolean isDeletedRow(short rowStart)
public static boolean isOverflowRow(short rowStart)
public static short cleanRowStart(short rowStart)
public static short findRowStart(ByteBuffer buffer, int rowNum, JetFormat format)
public static int getRowStartOffset(int rowNum, JetFormat format)
public static short findRowEnd(ByteBuffer buffer, int rowNum, JetFormat format)
public static int getRowEndOffset(int rowNum, JetFormat format)
public static int getRowSpaceUsage(int rowSize, JetFormat format)
public static boolean rowFitsOnDataPage(int rowLength, ByteBuffer dataPage, JetFormat format) throws IOException
true
if a row of the given size will fit on the given
data page, false
otherwise.IOException
Copyright © 2005–2024 OpenHMS. All rights reserved.