## org.h2.table
Class Table

    java.lang.Object
      org.h2.engine.DbObjectBase
          org.h2.schema.SchemaObjectBase
              org.h2.table.Table

All Implemented Interfaces:
  DbObject, SchemaObject

Direct Known Subclasses:
  FunctionTable, MetaTable, RangeTable, TableBase, TableLink, TableView

    public abstract class Table

extends SchemaObjectBase

This is the base class for most tables. A table contains a list of columns and a list of rows.

Field Summary
`protected Column[]` `columns` The columns of this table.
`protected CompareMode` `compareMode` The compare mode used for this table.
`static java.lang.String` `EXTERNAL_TABLE_ENGINE` The table type name for external table engines.
`protected boolean` `isHidden` Protected tables are not listed in the meta data and are excluded when using the SCRIPT command.
`static java.lang.String` `SYSTEM_TABLE` The table type name for system tables.
`static java.lang.String` `TABLE` The table type name for regular data tables.
`static java.lang.String` `TABLE_LINK` The table type name for linked tables.
`static int` `TYPE_CACHED` The table type that means this table is a regular persistent table.
`static int` `TYPE_MEMORY` The table type that means this table is a regular persistent table.
`static java.lang.String` `VIEW` The table type name for views.

Fields inherited from class org.h2.engine.DbObjectBase
`comment, database, trace`

Fields inherited from interface org.h2.engine.DbObject
`AGGREGATE, COMMENT, CONSTANT, CONSTRAINT, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, TABLE_OR_VIEW, TRIGGER, USER, USER_DATATYPE`

Constructor Summary
`Table(Schema schema, int id, java.lang.String name, boolean persistIndexes, boolean persistData)`

Method Summary
`void` `addConstraint(Constraint constraint)` Add a constraint to the table.
`void` `addDependencies(java.util.HashSet<DbObject> dependencies)` Add all objects that this table depends on to the hash set.
`abstract Index` `addIndex(Session session, java.lang.String indexName, int indexId, IndexColumn[] cols, IndexType indexType, boolean create, java.lang.String indexComment)` Create an index for this table
`abstract void` `addRow(Session session, Row row)` Add a row to the table and all indexes.
`void` `addSequence(Sequence sequence)` Add a sequence to this table.
`void` `addTrigger(TriggerObject trigger)` Add a trigger to this table.
`void` `addView(TableView view)` Add a view to this table.
`abstract boolean` `canDrop()` Check if this table can be dropped.
`abstract boolean` `canGetRowCount()` Check if the row count can be retrieved quickly.
`boolean` `canReference()` Check if this table can be referenced.
`boolean` `canTruncate()` Check if this table can be truncated.
`java.util.ArrayList<Session>` `checkDeadlock(Session session, Session clash, java.util.Set<Session> visited)` Check if a deadlock occurred.
`abstract void` `checkSupportAlter()` Check if this table supports ALTER TABLE.
`void` `checkWritingAllowed()` Tests if the table can be written.
`abstract void` `close(Session session)` Close the table object and flush changes.
`void` `commit(short operation, Row row)` Commit an operation (when using multi-version concurrency).
`int` `compareTypeSave(Value a, Value b)` Compare two values with the current comparison mode.
`boolean` `doesColumnExist(java.lang.String columnName)` Does the column with the given name exist?
`void` `dropSingleColumnConstraintsAndIndexes(Session session, Column col)` Check that this column is not referenced by a multi-column constraint or multi-column index.
`Index` `findPrimaryKey()` Get the primary key index if there is one, or null if there is none.
`void` `fire(Session session, int type, boolean beforeAction)` Fire the triggers for this table.
`void` `fireAfterRow(Session session, Row oldRow, Row newRow, boolean rollback)` Fire all triggers that need to be called after a row is updated.
`boolean` `fireBeforeRow(Session session, Row oldRow, Row newRow)` Fire all triggers that need to be called before a row is updated.
`boolean` `fireRow()` Check if row based triggers or constraints are defined.
`PlanItem` `getBestPlanItem(Session session, int[] masks, SortOrder sortOrder)` Get the best plan for the given search mask.
`boolean` `getCheckForeignKeyConstraints()`
`java.util.ArrayList<DbObject>` `getChildren()` Get the list of dependent children (for tables, this includes indexes and so on).
`Column` `getColumn(int index)` Get the column at the given index.
`Column` `getColumn(java.lang.String columnName)` Get the column with the given name.
`Column[]` `getColumns()`
`CompareMode` `getCompareMode()`
`java.util.ArrayList<Constraint>` `getConstraints()`
`java.lang.String` `getCreateSQLForCopy(Table table, java.lang.String quotedName)` Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
`Value` `getDefaultValue(Session session, Column column)` Get or generate a default value for the given column.
`abstract long` `getDiskSpaceUsed()`
`abstract java.util.ArrayList<Index>` `getIndexes()` Get all indexes for this table.
`Index` `getIndexForColumn(Column column)` Get the index that has the given column as the first element.
`abstract long` `getMaxDataModificationId()` Get the last data modification id.
`boolean` `getOnCommitDrop()`
`boolean` `getOnCommitTruncate()`
`Index` `getPrimaryKey()`
`abstract long` `getRowCount(Session session)` Get the row count for this table.
`abstract long` `getRowCountApproximation()` Get the approximated row count for this table.
`Column` `getRowIdColumn()` Get the row id column if this table has one.
`abstract Index` `getScanIndex(Session session)` Get the scan index to iterate through all rows.
`abstract java.lang.String` `getTableType()` Get the table type name
`Row` `getTemplateRow()`
`SearchRow` `getTemplateSimpleRow(boolean singleColumn)` Get a new simple row object.
`int` `getType()` Get the object type.
`abstract Index` `getUniqueIndex()` Get any unique index for this table if one exists.
`java.util.ArrayList<TableView>` `getViews()`
`boolean` `hasSelectTrigger()` Check whether this table has a select trigger.
`abstract boolean` `isDeterministic()` Check if the table is deterministic.
`boolean` `isGlobalTemporary()`
`boolean` `isHidden()` Check whether this is a hidden object that doesn't appear in the meta data and in the script, and is not dropped on DROP ALL OBJECTS.
`abstract boolean` `isLockedExclusively()` Check if this table is locked exclusively.
`boolean` `isLockedExclusivelyBy(Session session)` Check if the table is exclusively locked by this session.
`boolean` `isMVStore()`
`boolean` `isPersistData()`
`boolean` `isPersistIndexes()`
`abstract void` `lock(Session session, boolean exclusive, boolean force)` Lock the table for the given session.
`void` `removeChildrenAndResources(Session session)` Remove all dependent objects and free all resources (files, blocks in files) of this object.
`void` `removeConstraint(Constraint constraint)` Remove the given constraint from the list.
`void` `removeIndex(Index index)` Remove the given index from the list.
`void` `removeIndexOrTransferOwnership(Session session, Index index)` If the index is still required by a constraint, transfer the ownership to it.
`abstract void` `removeRow(Session session, Row row)` Remove a row from the table and all indexes.
`void` `removeSequence(Sequence sequence)` Remove a sequence from the table.
`void` `removeTrigger(TriggerObject trigger)` Remove the given trigger from the list.
`void` `removeView(TableView view)` Remove the given view from the list.
`void` `rename(java.lang.String newName)` Rename the object.
`void` `renameColumn(Column column, java.lang.String newName)` Rename a column of this table.
`void` `setCheckForeignKeyConstraints(Session session, boolean enabled, boolean checkExisting)` Enable or disable foreign key constraint checking for this table.
`protected void` `setColumns(Column[] columns)`
`void` `setHidden(boolean hidden)`
`void` `setOnCommitDrop(boolean onCommitDrop)`
`void` `setOnCommitTruncate(boolean onCommitTruncate)`
`abstract void` `truncate(Session session)` Remove all rows from the table and indexes.
`abstract void` `unlock(Session s)` Release the lock for this session.
`void` `updateRows(Prepared prepared, Session session, RowList rows)` Update a list of rows in this table.
`void` `validateConvertUpdateSequence(Session session, Row row)` Validate all values in this row, convert the values if required, and update the sequence values if required.

Methods inherited from class org.h2.schema.SchemaObjectBase
`getSchema, getSQL, initSchemaObjectBase`

Methods inherited from class org.h2.engine.DbObjectBase
`checkRename, getComment, getCreateSQL, getDatabase, getDropSQL, getId, getModificationId, getName, initDbObjectBase, invalidate, isTemporary, setComment, setModified, setObjectName, setTemporary, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.h2.engine.DbObject
`checkRename, getComment, getCreateSQL, getDatabase, getDropSQL, getId, getName, isTemporary, setComment, setTemporary`

Field Detail

### TYPE_CACHED

    public static final int TYPE_CACHED

  The table type that means this table is a regular persistent table.

  See Also:
    Constant Field Values

### TYPE_MEMORY

    public static final int TYPE_MEMORY

  The table type that means this table is a regular persistent table.

  See Also:
    Constant Field Values

### TABLE_LINK

    public static final java.lang.String TABLE_LINK

  The table type name for linked tables.

  See Also:
    Constant Field Values

### SYSTEM_TABLE

    public static final java.lang.String SYSTEM_TABLE

  The table type name for system tables.

  See Also:
    Constant Field Values

### TABLE

    public static final java.lang.String TABLE

  The table type name for regular data tables.

  See Also:
    Constant Field Values

### VIEW

    public static final java.lang.String VIEW

  The table type name for views.

  See Also:
    Constant Field Values

### EXTERNAL_TABLE_ENGINE

    public static final java.lang.String EXTERNAL_TABLE_ENGINE

  The table type name for external table engines.

  See Also:
    Constant Field Values

### columns

    protected Column[] columns

  The columns of this table.

### compareMode

    protected CompareMode compareMode

  The compare mode used for this table.

### isHidden

    protected boolean isHidden

  Protected tables are not listed in the meta data and are excluded when using the SCRIPT command.

Constructor Detail

### Table

    public Table(Schema schema,
                 int id,
                 java.lang.String name,
                 boolean persistIndexes,
                 boolean persistData)

Method Detail

### rename

    public void rename(java.lang.String newName)

  Description copied from interface: `DbObject`
  Rename the object.

  Specified by:
    `rename` in interface `DbObject`
  Overrides:
    `rename` in class `DbObjectBase`
  Parameters:
    `newName` - the new name

### lock

    public abstract void lock(Session session,
                              boolean exclusive,
                              boolean force)

  Lock the table for the given session. This method waits until the lock is granted.

  Parameters:
    `session` - the session
    `exclusive` - true for write locks, false for read locks
    `force` - lock even in the MVCC mode
  Throws:
    `DbException` - if a lock timeout occurred

### close

    public abstract void close(Session session)

  Close the table object and flush changes.

  Parameters:
    `session` - the session

### unlock

    public abstract void unlock(Session s)

  Release the lock for this session.

  Parameters:
    `s` - the session

### addIndex

    public abstract Index addIndex(Session session,
                                   java.lang.String indexName,
                                   int indexId,
                                   IndexColumn[] cols,
                                   IndexType indexType,
                                   boolean create,
                                   java.lang.String indexComment)

  Create an index for this table

  Parameters:
    `session` - the session
    `indexName` - the name of the index
    `indexId` - the id
    `cols` - the index columns
    `indexType` - the index type
    `create` - whether this is a new index
    `indexComment` - the comment
  Returns:
    the index

### removeRow

    public abstract void removeRow(Session session,
                                   Row row)

  Remove a row from the table and all indexes.

  Parameters:
    `session` - the session
    `row` - the row

### truncate

    public abstract void truncate(Session session)

  Remove all rows from the table and indexes.

  Parameters:
    `session` - the session

### addRow

    public abstract void addRow(Session session,
                                Row row)

  Add a row to the table and all indexes.

  Parameters:
    `session` - the session
    `row` - the row
  Throws:
    `DbException` - if a constraint was violated

### commit

    public void commit(short operation,
                       Row row)

  Commit an operation (when using multi-version concurrency).

  Parameters:
    `operation` - the operation
    `row` - the row

### checkSupportAlter

    public abstract void checkSupportAlter()

  Check if this table supports ALTER TABLE.

  Throws:
    `DbException` - if it is not supported

### getTableType

    public abstract java.lang.String getTableType()

  Get the table type name

  Returns:
    the table type name

### getScanIndex

    public abstract Index getScanIndex(Session session)

  Get the scan index to iterate through all rows.

  Parameters:
    `session` - the session
  Returns:
    the index

### getUniqueIndex

    public abstract Index getUniqueIndex()

  Get any unique index for this table if one exists.

  Returns:
    a unique index

### getIndexes

    public abstract java.util.ArrayList<Index> getIndexes()

  Get all indexes for this table.

  Returns:
    the list of indexes

### isLockedExclusively

    public abstract boolean isLockedExclusively()

  Check if this table is locked exclusively.

  Returns:
    true if it is.

### getMaxDataModificationId

    public abstract long getMaxDataModificationId()

  Get the last data modification id.

  Returns:
    the modification id

### isDeterministic

    public abstract boolean isDeterministic()

  Check if the table is deterministic.

  Returns:
    true if it is

### canGetRowCount

    public abstract boolean canGetRowCount()

  Check if the row count can be retrieved quickly.

  Returns:
    true if it can

### canReference

    public boolean canReference()

  Check if this table can be referenced.

  Returns:
    true if it can

### canDrop

    public abstract boolean canDrop()

  Check if this table can be dropped.

  Returns:
    true if it can

### getRowCount

    public abstract long getRowCount(Session session)

  Get the row count for this table.

  Parameters:
    `session` - the session
  Returns:
    the row count

### getRowCountApproximation

    public abstract long getRowCountApproximation()

  Get the approximated row count for this table.

  Returns:
    the approximated row count

### getDiskSpaceUsed

    public abstract long getDiskSpaceUsed()

### getRowIdColumn

    public Column getRowIdColumn()

  Get the row id column if this table has one.

  Returns:
    the row id column, or null

### getCreateSQLForCopy

    public java.lang.String getCreateSQLForCopy(Table table,
                                                java.lang.String quotedName)

  Description copied from interface: `DbObject`
  Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table

  Parameters:
    `table` - the new table
    `quotedName` - the quoted name
  Returns:
    the SQL statement

### addDependencies

    public void addDependencies(java.util.HashSet<DbObject> dependencies)

  Add all objects that this table depends on to the hash set.

  Parameters:
    `dependencies` - the current set of dependencies

### getChildren

    public java.util.ArrayList<DbObject> getChildren()

  Description copied from interface: `DbObject`
  Get the list of dependent children (for tables, this includes indexes and so on).

  Specified by:
    `getChildren` in interface `DbObject`
  Overrides:
    `getChildren` in class `DbObjectBase`
  Returns:
    the list of children

### setColumns

    protected void setColumns(Column[] columns)

### renameColumn

    public void renameColumn(Column column,
                             java.lang.String newName)

  Rename a column of this table.

  Parameters:
    `column` - the column to rename
    `newName` - the new column name

### isLockedExclusivelyBy

    public boolean isLockedExclusivelyBy(Session session)

  Check if the table is exclusively locked by this session.

  Parameters:
    `session` - the session
  Returns:
    true if it is

### updateRows

    public void updateRows(Prepared prepared,
                           Session session,
                           RowList rows)

  Update a list of rows in this table.

  Parameters:
    `prepared` - the prepared statement
    `session` - the session
    `rows` - a list of row pairs of the form old row, new row, old row, new row,...

### getViews

    public java.util.ArrayList<TableView> getViews()

### removeChildrenAndResources

    public void removeChildrenAndResources(Session session)

  Description copied from class: `DbObjectBase`
  Remove all dependent objects and free all resources (files, blocks in files) of this object.

  Specified by:
    `removeChildrenAndResources` in interface `DbObject`
  Specified by:
    `removeChildrenAndResources` in class `DbObjectBase`
  Parameters:
    `session` - the session

### dropSingleColumnConstraintsAndIndexes

    public void dropSingleColumnConstraintsAndIndexes(Session session,
                                                      Column col)

  Check that this column is not referenced by a multi-column constraint or multi-column index. If it is, an exception is thrown. Single-column references and indexes are dropped.

  Parameters:
    `session` - the session
    `col` - the column
  Throws:
    `DbException` - if the column is referenced by multi-column constraints or indexes

### getTemplateRow

    public Row getTemplateRow()

### getTemplateSimpleRow

    public SearchRow getTemplateSimpleRow(boolean singleColumn)

  Get a new simple row object.

  Parameters:
    `singleColumn` - if only one value need to be stored
  Returns:
    the simple row object

### getColumns

    public Column[] getColumns()

### getType

    public int getType()

  Description copied from interface: `DbObject`
  Get the object type.

  Returns:
    the object type

### getColumn

    public Column getColumn(int index)

  Get the column at the given index.

  Parameters:
    `index` - the column index (0, 1,...)
  Returns:
    the column

### getColumn

    public Column getColumn(java.lang.String columnName)

  Get the column with the given name.

  Parameters:
    `columnName` - the column name
  Returns:
    the column
  Throws:
    `DbException` - if the column was not found

### doesColumnExist

    public boolean doesColumnExist(java.lang.String columnName)

  Does the column with the given name exist?

  Parameters:
    `columnName` - the column name
  Returns:
    true if the column exists

### getBestPlanItem

    public PlanItem getBestPlanItem(Session session,
                                    int[] masks,
                                    SortOrder sortOrder)

  Get the best plan for the given search mask.

  Parameters:
    `session` - the session
    `masks` - per-column comparison bit masks, null means 'always false', see constants in IndexCondition
    `sortOrder` - the sort order
  Returns:
    the plan item

### findPrimaryKey

    public Index findPrimaryKey()

  Get the primary key index if there is one, or null if there is none.

  Returns:
    the primary key index or null

### getPrimaryKey

    public Index getPrimaryKey()

### validateConvertUpdateSequence

    public void validateConvertUpdateSequence(Session session,
                                              Row row)

  Validate all values in this row, convert the values if required, and update the sequence values if required. This call will also set the default values if required and set the computed column if there are any.

  Parameters:
    `session` - the session
    `row` - the row

### removeIndex

    public void removeIndex(Index index)

  Remove the given index from the list.

  Parameters:
    `index` - the index to remove

### removeView

    public void removeView(TableView view)

  Remove the given view from the list.

  Parameters:
    `view` - the view to remove

### removeConstraint

    public void removeConstraint(Constraint constraint)

  Remove the given constraint from the list.

  Parameters:
    `constraint` - the constraint to remove

### removeSequence

    public final void removeSequence(Sequence sequence)

  Remove a sequence from the table. Sequences are used as identity columns.

  Parameters:
    `sequence` - the sequence to remove

### removeTrigger

    public void removeTrigger(TriggerObject trigger)

  Remove the given trigger from the list.

  Parameters:
    `trigger` - the trigger to remove

### addView

    public void addView(TableView view)

  Add a view to this table.

  Parameters:
    `view` - the view to add

### addConstraint

    public void addConstraint(Constraint constraint)

  Add a constraint to the table.

  Parameters:
    `constraint` - the constraint to add

### getConstraints

    public java.util.ArrayList<Constraint> getConstraints()

### addSequence

    public void addSequence(Sequence sequence)

  Add a sequence to this table.

  Parameters:
    `sequence` - the sequence to add

### addTrigger

    public void addTrigger(TriggerObject trigger)

  Add a trigger to this table.

  Parameters:
    `trigger` - the trigger to add

### fire

    public void fire(Session session,
                     int type,
                     boolean beforeAction)

  Fire the triggers for this table.

  Parameters:
    `session` - the session
    `type` - the trigger type
    `beforeAction` - whether 'before' triggers should be called

### hasSelectTrigger

    public boolean hasSelectTrigger()

  Check whether this table has a select trigger.

  Returns:
    true if it has

### fireRow

    public boolean fireRow()

  Check if row based triggers or constraints are defined. In this case the fire after and before row methods need to be called.

  Returns:
    if there are any triggers or rows defined

### fireBeforeRow

    public boolean fireBeforeRow(Session session,
                                 Row oldRow,
                                 Row newRow)

  Fire all triggers that need to be called before a row is updated.

  Parameters:
    `session` - the session
    `oldRow` - the old data or null for an insert
    `newRow` - the new data or null for a delete
  Returns:
    true if no further action is required (for 'instead of' triggers)

### fireAfterRow

    public void fireAfterRow(Session session,
                             Row oldRow,
                             Row newRow,
                             boolean rollback)

  Fire all triggers that need to be called after a row is updated.

  Parameters:
    `session` - the session
    `oldRow` - the old data or null for an insert
    `newRow` - the new data or null for a delete
    `rollback` - when the operation occurred within a rollback

### isGlobalTemporary

    public boolean isGlobalTemporary()

### canTruncate

    public boolean canTruncate()

  Check if this table can be truncated.

  Returns:
    true if it can

### setCheckForeignKeyConstraints

    public void setCheckForeignKeyConstraints(Session session,
                                              boolean enabled,
                                              boolean checkExisting)

  Enable or disable foreign key constraint checking for this table.

  Parameters:
    `session` - the session
    `enabled` - true if checking should be enabled
    `checkExisting` - true if existing rows must be checked during this call

### getCheckForeignKeyConstraints

    public boolean getCheckForeignKeyConstraints()

### getIndexForColumn

    public Index getIndexForColumn(Column column)

  Get the index that has the given column as the first element. This method returns null if no matching index is found.

  Parameters:
    `column` - the column
  Returns:
    the index or null

### getOnCommitDrop

    public boolean getOnCommitDrop()

### setOnCommitDrop

    public void setOnCommitDrop(boolean onCommitDrop)

### getOnCommitTruncate

    public boolean getOnCommitTruncate()

### setOnCommitTruncate

    public void setOnCommitTruncate(boolean onCommitTruncate)

### removeIndexOrTransferOwnership

    public void removeIndexOrTransferOwnership(Session session,
                                               Index index)

  If the index is still required by a constraint, transfer the ownership to it. Otherwise, the index is removed.

  Parameters:
    `session` - the session
    `index` - the index that is no longer required

### checkDeadlock

    public java.util.ArrayList<Session> checkDeadlock(Session session,
                                                      Session clash,
                                                      java.util.Set<Session> visited)

  Check if a deadlock occurred. This method is called recursively. There is a circle if the session to be tested has already being visited. If this session is part of the circle (if it is the clash session), the method must return an empty object array. Once a deadlock has been detected, the methods must add the session to the list. If this session is not part of the circle, or if no deadlock is detected, this method returns null.

  Parameters:
    `session` - the session to be tested for
    `clash` - set with sessions already visited, and null when starting verification
    `visited` - set with sessions already visited, and null when starting verification
  Returns:
    an object array with the sessions involved in the deadlock, or null

### isPersistIndexes

    public boolean isPersistIndexes()

### isPersistData

    public boolean isPersistData()

### compareTypeSave

    public int compareTypeSave(Value a,
                               Value b)

  Compare two values with the current comparison mode. The values may be of different type.

  Parameters:
    `a` - the first value
    `b` - the second value
  Returns:
    0 if both values are equal, -1 if the first value is smaller, and 1 otherwise

### getCompareMode

    public CompareMode getCompareMode()

### checkWritingAllowed

    public void checkWritingAllowed()

  Tests if the table can be written. Usually, this depends on the database.checkWritingAllowed method, but some tables (eg. TableLink) overwrite this default behaviour.

### getDefaultValue

    public Value getDefaultValue(Session session,
                                 Column column)

  Get or generate a default value for the given column.

  Parameters:
    `session` - the session
    `column` - the column
  Returns:
    the value

### isHidden

    public boolean isHidden()

  Description copied from interface: `SchemaObject`
  Check whether this is a hidden object that doesn't appear in the meta data and in the script, and is not dropped on DROP ALL OBJECTS.

  Specified by:
    `isHidden` in interface `SchemaObject`
  Overrides:
    `isHidden` in class `SchemaObjectBase`
  Returns:
    true if it is hidden

### setHidden

    public void setHidden(boolean hidden)

### isMVStore

    public boolean isMVStore()