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

public Class TableImpl

extends Object
implements Table, Owner
Class Inheritance
All Implemented Interfaces
io.github.spannm.jackcess.impl.PropertyMaps.Owner, io.github.spannm.jackcess.Table, io.github.spannm.jackcess.TableDefinition, java.lang.Iterable
Known Direct Subclasses
io.github.spannm.jackcess.impl.TableDefinitionImpl
Imports
io.github.spannm.jackcess.BatchUpdateException, .Column, .ColumnBuilder, .ConstraintViolationException, .CursorBuilder, .Index, .IndexBuilder, .InvalidValueException, .JackcessException, .PropertyMap, .Row, .RowId, .Table, io.github.spannm.jackcess.expr.Identifier, io.github.spannm.jackcess.util.ErrorHandler, .ExportUtil, .ToStringBuilder, java.io.BufferedWriter, .IOException, .StringWriter, java.nio.BufferOverflowException, .BufferUnderflowException, .ByteBuffer, java.nio.charset.Charset, java.time.LocalDateTime, java.util.AbstractMap, .ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashMap, .Iterator, .LinkedHashSet, .List, .Map, .Set, .TreeSet, java.util.logging.Level, .Logger

A single database table

Is not thread-safe.

Author
Tim McCune

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
TableImpl.CalcColEvaluator

Utility for managing calculated columns.

public static enum
public class
TableImpl.RowState

Maintains the state of reading/updating a row of data.

private static enum
TableImpl.RowStateStatus

the phases the RowState moves through as the data is parsed

private static enum
TableImpl.RowStatus

various statuses for the row data

protected static class
TableImpl.WriteRowState

Maintains state for writing a new row of data.

Field Summary

Modifier and TypeField and Description
private final TempPageHolder
addRowBufferH

page buffer used to update data pages when adding rows

private Boolean
allowAutoNumInsert

optional flag indicating whether or not auto numbers can be directly inserted by the user

private final List<ColumnImpl>
autoNumColumns

List of autonumber columns in this table, ordered by column number

private final TableImpl.CalcColEvaluator
calcColEval

handler for calculated columns

private final List<ColumnImpl>
columns

List of columns in this table, ordered by column number

private final DatabaseImpl
database

owning database

private CursorImpl
defaultCursor

default cursor for iterating through the table, kept here for basic table traversal

private static final short
private static final Comparator<ColumnImpl>
DISPLAY_ORDER_COMPARATOR

comparator which sorts columns based on their display index

private final FKEnforcer
fkEnforcer

foreign-key enforcer for this table

private final int
flags

additional table flags from the catalog entry

private final UsageMap
freeSpacePages

Usage map of pages that this table owns with free space on them

private final Set<ColumnImpl>
indexColumns

List of columns in this table which are in one or more indexes

private int
indexCount

Number of actual indexes on the table

private final List<IndexData>
indexDatas

List of index datas on this table (the actual backing data for an index)

private final List<IndexImpl>
indexes

List of indexes on this table (multiple logical indexes may be backed by the same index data)

private int
lastComplexTypeAutoNumber

last complex type auto number for the table

private int
lastLongAutoNumber

last long auto number for the table

private static final Logger
private int
logicalIndexCount

Number of logical indexes for the table

private final TempPageHolder
longValueBufferH

page buffer used to write out-of-row "long value" data

pack-priv static final int
private static final int
private short
maxColumnCount

max Number of columns in the table (includes previous deletions)

private short
maxVarColumnCount

max Number of variable columns in the table

private int
modCount

modification count for the table, keeps row-states up-to-date

private final String
name

Table name as stored in Database

private static final short
private static final short
private final UsageMap
ownedPages

Usage map of pages that this table owns

private PropertyMaps
propertyMaps

properties group for this table (and columns)

private PropertyMap
props

properties for this table

private int
rowCount

Number of rows in the table

private RowValidatorEvalContext
rowValidator

table validator if any (and enabled)

private final TempPageHolder
tableDefBufferH

page buffer used to update the table def page

private final int
tableDefPageNumber

page number of the definition of this table

private ErrorHandler
tableErrorHandler

optional error handler to use when row errors are encountered

private final byte
tableType

Type of the table (either TYPE_SYSTEM or TYPE_USER)

public static final byte
TYPE_SYSTEM

Table type code for system tables

public static final byte
TYPE_USER

Table type code for user tables

private static final Comparator<ColumnImpl>
VAR_LEN_COLUMN_COMPARATOR

comparator which sorts variable length columns based on their index into the variable length offset table

private final List<ColumnImpl>
varColumns

List of variable length columns in this table, ordered by offset

private String
writeDefError

description of an inconsistency between the table definition and the column definitions, null if they agree.

private final TempBufferHolder
writeRowBufferH

buffer used to writing rows of data

Constructor Summary

AccessConstructor and Description
protected
TableImpl(boolean testing, List<ColumnImpl> columns)

Only used by unit tests

protected
TableImpl(DatabaseImpl
database which owns this table
database
,
ByteBuffer
Buffer to read the table with
tableBuffer
,
int
Page number of the table definition
pageNumber
,
String
Table name
name
,
int flags)

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the row number of the new row
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.

public Object[]
addRow(Object... row)

Implements io.github.spannm.jackcess.Table.addRow.

Adds a single row to this table and writes it to disk.

public <M extends Map<String, Object>> M
addRowFromMap(M row)

Implements io.github.spannm.jackcess.Table.addRowFromMap.

Calls asRow on the given row map and passes the result to addRow.

public List<? extends Object[]>
addRows(List<? extends Object[]> rows)

Implements io.github.spannm.jackcess.Table.addRows.

Add multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled.

protected List<? extends Object[]>
addRows(List<? extends Object[]>
List of Object[] row values
rows
,
final boolean isBatchWrite)

Add multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled.

public <M extends Map<String, Object>> List<M>
addRowsFromMaps(List<M> rows)

Implements io.github.spannm.jackcess.Table.addRowsFromMaps.

Calls asRow on the given row maps and passes the results to addRows.

private Map.Entry<Integer, Integer>
addUsageMaps(int numMaps, Integer firstUsedPage)

Adds some usage maps for use with this table.

pack-priv void
adjustComplexTypeAutoNumber(int inComplexTypeAutoNumber)

pack-priv void
adjustLongAutoNumber(int inLongAutoNumber)

public Object[]
asRow(Map<String, ?> rowMap)

Implements io.github.spannm.jackcess.Table.asRow.

Converts a map of columnName -> columnValue to an array of row values appropriate for a call to addRow(Object...).

private Object[]
asRow(Map<String, ?> rowMap, Object defaultValue, boolean returnRowId)

Converts a map of columnName -> columnValue to an array of row values.

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.

public Object[]
asUpdateRow(Map<String, ?> rowMap)

Implements io.github.spannm.jackcess.Table.asUpdateRow.

Converts a map of columnName -> columnValue to an array of row values appropriate for a call to Cursor#updateCurrentRow(Object...).

public static short
cleanRowStart(short rowStart)

pack-priv void
private void
protected ByteBuffer
createRow(Object[] rowArray, ByteBuffer buffer)

private ByteBuffer

Returns:

the given buffer, filled with the row data
createRow
(Object[]
row data, expected to be correct length for this table
rowArray
,
ByteBuffer
buffer to which to write the row data
buffer
,
int
min size for result row
minRowSize
,
Map<ColumnImpl, byte[]>
optional, pre-written values for var length columns (enables re-use of previously written values).
rawVarValues
)

Serialize a row of Objects into a byte buffer.

public TableImpl.RowState
private static void
createUsageMapDefinitionBuffer(TableCreator creator)

Create the usage map definition page buffer.

private static ByteBuffer
createUsageMapDefPage(PageChannel pageChannel, int freeSpace)

public Row
deleteRow(Row row)

Implements io.github.spannm.jackcess.Table.deleteRow.

Delete the given row.

public RowId

Returns:

the given rowId
deleteRow
(RowId rowId)

Delete the row with the given id. Provided RowId must have previously been returned from this Table.

public void
deleteRow(TableImpl.RowState rowState, RowIdImpl rowId)

Delete the row for the given rowId.

public String

Returns:

A simple String representation of the entire table in tab-delimited format
display
()

Returns a simple String representation of the entire table in tab-delimited format.

public String

Returns:

A simple String representation of the entire table in tab-delimited format
display
(long
Maximum number of rows to display
limit
)

Returns a simple String representation of the entire table in tab-delimited format.

pack-priv static Object[]
dupeRow(Object[] row, int newRowLength)

Duplicates and returns a row of data, optionally with a longer length filled with null.

private ByteBuffer
private ByteBuffer
findFreeRowSpace(int rowSize, ByteBuffer dataPage, int pageNumber)

pack-priv static ByteBuffer
findFreeRowSpace(UsageMap ownedPages, UsageMap freeSpacePages, TempPageHolder rowBufferH)

public IndexImpl
public static short
findRowEnd(ByteBuffer buffer, int rowNum, JetFormat format)

public static short
findRowStart(ByteBuffer buffer, int rowNum, JetFormat format)

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).

pack-priv List<ColumnImpl>
public ColumnImpl
getColumn(String colName)

Implements io.github.spannm.jackcess.Table.getColumn.

Returns the column with the given name.

public int
getColumnCount()

Implements io.github.spannm.jackcess.Table.getColumnCount.

Returns the number of columns in this table.

public List<ColumnImpl>
getColumns()

Implements io.github.spannm.jackcess.Table.getColumns.

Returns all of the columns in this table (unmodifiable List).

public LocalDateTime
getCreatedDate()

Implements io.github.spannm.jackcess.Table.getCreatedDate.

Returns the created date for this table if available.

public DatabaseImpl
getDatabase()

Implements io.github.spannm.jackcess.Table.getDatabase.

Returns the database to which this table belongs.

public CursorImpl
getDefaultCursor()

Implements io.github.spannm.jackcess.Table.getDefaultCursor.

Returns a simple Cursor, initialized on demand and held by this table.

public ErrorHandler
getErrorHandler()

Implements io.github.spannm.jackcess.Table.getErrorHandler.

Gets the currently configured ErrorHandler (always non-null).

public IndexImpl
getForeignKeyIndex(Table otherTable)

Implements io.github.spannm.jackcess.Table.getForeignKeyIndex.

Returns the foreign key index joining this table to the given other table.

public JetFormat
public IndexImpl
getIndex(String indexName)

Implements io.github.spannm.jackcess.Table.getIndex.

Returns the index with the given name.

pack-priv int
public List<IndexData>

Returns:

All of the IndexData on this table (unmodifiable List)
getIndexDatas
()

Returns all of the IndexData on this table (unmodifiable List).

public List<IndexImpl>
getIndexes()

Implements io.github.spannm.jackcess.Table.getIndexes.

Returns all of the Indexes on this table (unmodifiable List).

private static Object
getInputAutoNumberRowValue(boolean enableInsert, ColumnImpl col, Object[] row)

Optionally get the input autonumber row value for the given column from the given row if one was provided.

pack-priv int
pack-priv int
public int
getLogicalIndexCount()

Only called by unit tests

protected TempPageHolder
public int
public String
getName()

Implements io.github.spannm.jackcess.Table.getName.

Returns the name of the table.

pack-priv int
pack-priv int
public Row
getNextRow()

Implements io.github.spannm.jackcess.Table.getNextRow.

Returns the next row in this table (Column name -> Column value) (uses the default cursor).

public UsageMap.PageCursor
public PageChannel
public IndexImpl
getPrimaryKeyIndex()

Implements io.github.spannm.jackcess.Table.getPrimaryKeyIndex.

Returns the primary key index for this table.

public PropertyMap
getProperties()

Implements io.github.spannm.jackcess.Table.getProperties.

Returns the properties for this table.

public PropertyMaps

Returns:

all PropertyMaps for this table (and columns)
getPropertyMaps
()

Returns all PropertyMaps for this table (and columns).

public RowImpl
getRow(TableImpl.RowState rowState, RowIdImpl rowId, Collection<String>
Only column names in this collection will be returned
columnNames
)

Reads some columns from the given row.

private static RowImpl
getRow(JetFormat format, TableImpl.RowState rowState, ByteBuffer rowBuffer, Collection<ColumnImpl> columns, Collection<String> columnNames)

Reads the row data from the given row buffer.

private static Object
getRowColumn(JetFormat format, ByteBuffer rowBuffer, ColumnImpl column, TableImpl.RowState rowState, Map<ColumnImpl, byte[]> rawVarValues)

Reads the column data from the given row buffer.

public int
getRowCount()

Implements io.github.spannm.jackcess.Table.getRowCount.

Returns the number of rows currently stored in this table.

public static int
getRowEndOffset(int rowNum, JetFormat format)

public RowId

Returns:

the generated RowId added to a row of values created via asRowWithRowId
getRowId
(Object[] row)

Returns the generated RowId added to a row of values created via asRowWithRowId.

private NullMask
getRowNullMask(ByteBuffer rowBuffer)

Reads the null mask from the given row buffer.

pack-priv static int
getRowsOnDataPage(ByteBuffer rowBuffer, JetFormat format)

Returns the row count for the current page.

public static int
getRowSpaceUsage(int rowSize, JetFormat format)

public static int
getRowStartOffset(int rowNum, JetFormat format)

public Object
getRowValue(TableImpl.RowState rowState, RowIdImpl rowId, ColumnImpl column)

Reads a single column from the given row.

public int
public LocalDateTime
getUpdatedDate()

Implements io.github.spannm.jackcess.Table.getUpdatedDate.

Note

jackcess does not automatically update the modified date of a Table.

private void
handleAutoNumbersForAdd(Object[] row, TableImpl.WriteRowState writeRowState)

Fill in all autonumber column values for add.

private void
handleAutoNumbersForUpdate(Object[] row, ByteBuffer rowBuffer, TableImpl.RowState rowState)

Fill in all autonumber column values for update.

public boolean
hasColumn(String colName)

private void
private void
public boolean
isAllowAutoNumberInsert()

Implements io.github.spannm.jackcess.Table.isAllowAutoNumberInsert.

Gets the currently configured auto number insert policy.

public static boolean
isDeletedRow(short rowStart)

public boolean
isHidden()

Implements io.github.spannm.jackcess.Table.isHidden.

Whether or not this table has been marked as hidden.

public static boolean
isOverflowRow(short rowStart)

public boolean
isSystem()

Implements io.github.spannm.jackcess.Table.isSystem.

Whether or not this table is a system (internal) table.

pack-priv boolean
isThisTable(Identifier identifier)

private static boolean
public Iterator<Row>
iterator()

Implements io.github.spannm.jackcess.Table.iterator.

Calls reset on this table and returns a modifiable Iterator which will iterate through all the rows of this table.

private ByteBuffer
loadCompleteTableDefinitionBuffer(ByteBuffer tableBuffer, List<Integer> pages)

Returns a single ByteBuffer which contains the entire table definition (which may span multiple database pages).

private ByteBuffer
protected ColumnImpl
mutateAddColumn(TableUpdater mutator)

Writes a column defined by the given TableUpdater to this table.

protected IndexImpl
mutateAddIndex(TableUpdater mutator)

Writes a index defined by the given TableUpdater to this table.

protected IndexData
mutateAddIndexData(TableUpdater mutator)

Writes a index defined by the given TableUpdater to this table.

public CursorBuilder
newCursor()

Implements io.github.spannm.jackcess.Table.newCursor.

Convenience method for constructing a new CursorBuilder for this Table.

private ByteBuffer

Returns:

Page number of the new page
newDataPage
()

Create a new data page

private static void
padRowBuffer(ByteBuffer buffer, int minRowSize, int trailerSize)

private void
public static ByteBuffer

Returns:

a ByteBuffer narrowed to the actual row data, or null if row was invalid or deleted
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.

public void
private void
readColumnDefinitions(ByteBuffer tableBuffer, short columnCount)

private boolean
private void
private static short[]
readJumpTableVarColOffsets(TableImpl.RowState rowState, ByteBuffer rowBuffer, int rowStart, NullMask nullMask)

private String
readName(ByteBuffer buffer)

Returns a name read from the buffer at the current position.

private int
readNameLength(ByteBuffer buffer)

Returns a name length read from the buffer at the current position.

private void
private void
private void
public void
reset()

Implements io.github.spannm.jackcess.Table.reset.

After calling this method, getNextRow will return the first row in the table, see Cursor#reset (uses the default cursor).

private void
restoreAutoNumbersFromAdd(Object[] row)

Restores all autonumber column values from a failed add row.

pack-priv void
restoreLastComplexTypeAutoNumber(int newLastComplexTypeAutoNumber)

pack-priv void
restoreLastLongAutoNumber(int newLastLongAutoNumber)

private static void
returnRowValues(Map<String, Object> row, Object[] rowValues, List<ColumnImpl> cols)

public 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.

public void
setAllowAutoNumberInsert(Boolean newAllowAutoNumInsert)

Implements io.github.spannm.jackcess.Table.setAllowAutoNumberInsert.

Sets the new auto number insert policy for the Table.

public void
setErrorHandler(ErrorHandler newErrorHandler)

Implements io.github.spannm.jackcess.Table.setErrorHandler.

Sets a new ErrorHandler.

private void
setWriteDefError(String
description of the inconsistency
reason
)

Records the first inconsistency found by validateColumnDefs.

private static void
skipNames(ByteBuffer tableBuffer, int count)

Skips the given number of names in the table buffer.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Row
updateRow(Row row)

Implements io.github.spannm.jackcess.Table.updateRow.

Update the given row.

public Object[]

Returns:

the given row, updated with the current row values
updateRow
(RowId rowId, Object... row)

Update the row with the given id. Provided RowId must have previously been returned from this Table.

public Object[]
updateRow(TableImpl.RowState rowState, RowIdImpl rowId, Object... row)

Update the row for the given rowId.

public <M extends Map<String, Object>> M
updateRowFromMap(TableImpl.RowState rowState, RowIdImpl rowId, M row)

private void
updateTableDefinition(int rowCountInc)

Updates the table definition after rows are modified.

public void
updateValue(Column column, RowId rowId, Object value)

Update the given column's value for the given row id. Provided RowId must have previously been returned from this Table.

private void
validateColumnDefs()

Verifies that the column counts and sizes in the table definition cover the columns which are actually defined.

private void
pack-priv String
private void
writeDataPage(ByteBuffer pageBuffer, int pageNumber)

Writes the given page data to the given page number, clears any other relevant buffers.

pack-priv static void
writeName(ByteBuffer buffer, String name, Charset charset)

Writes the given name into the given buffer in the format as expected by readName.

protected static void
writeTableDefinition(TableCreator creator)

Writes a new table defined by the given TableCreator to the database.

private static void
writeTableDefinitionBuffer(ByteBuffer buffer, int tdefPageNumber, TableMutator mutator, List<Integer> reservedPages)

private static void
writeTableDefinitionHeader(TableCreator creator, ByteBuffer
Buffer to write to
buffer
,
int totalTableDefSize)

private static void
writeTablePageHeader(ByteBuffer
Buffer to write to
buffer
)

Writes the page header for a table definition page

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait