Top Description Fields Constructors Methods
org.h2.table

public abstract Class Table

extends SchemaObject
Class Inheritance
Known Direct Subclasses
org.h2.table.TableBase, org.h2.table.TableLink, org.h2.table.VirtualTable, org.h2.table.MaterializedView, org.h2.table.MetaTable, org.h2.table.QueryExpressionTable
Imports
java.util.ArrayList, .Arrays, .HashMap, .HashSet, .Set, java.util.concurrent.CopyOnWriteArrayList, org.h2.api.ErrorCode, org.h2.command.Prepared, org.h2.command.query.AllColumnsForPlan, org.h2.constraint.Constraint, .Constraint.Type, org.h2.engine.CastDataProvider, .Constants, .DbObject, .Right, .SessionLocal, org.h2.expression.ExpressionVisitor, org.h2.index.Index, .IndexType, org.h2.message.DbException, .Trace, org.h2.result.DefaultRow, .LocalResult, .Row, .RowFactory, .SearchRow, .SimpleRowValue, .SortOrder, org.h2.schema.Schema, .SchemaObject, .Sequence, .TriggerObject, org.h2.util.Utils, org.h2.value.CompareMode, .Value, .ValueNull

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

Field Summary

Modifier and TypeField and Description
private boolean
checkForeignKeyConstraints

Is foreign key constraint checking enabled for this table.

private final HashMap<String, Column>
protected Column[]
columns

The columns of this table.

protected CompareMode
compareMode

The compare mode used for this table.

private ArrayList<Constraint>
private final CopyOnWriteArrayList<MaterializedView>
dependentMaterializedViews

materialized views that depend on this table

private final CopyOnWriteArrayList<TableView>
dependentViews

views that depend on this table

public static final int
EXCLUSIVE_LOCK

Exclusive lock.

private volatile Row
private boolean
private boolean
private final boolean
private final boolean
public static final int
READ_LOCK

Read lock.

private RowFactory
private ArrayList<Sequence>
private ArrayList<TableSynonym>
private ArrayList<TriggerObject>
public static final int
TYPE_CACHED

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

public static final int
TYPE_MEMORY

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

public static final int
WRITE_LOCK

Write lock.

Constructor Summary

AccessConstructor and Description
protected
Table(Schema schema, int id, String name, boolean persistIndexes, boolean persistData)

Method Summary

Modifier and TypeMethod and Description
private static <T> ArrayList<T>
add(ArrayList<T> list, T obj)

public void
addConstraint(Constraint
the constraint to add
constraint
)

Add a constraint to the table.

public void
addDependencies(HashSet<DbObject>
the current set of dependencies
dependencies
)

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

public void
addDependentMaterializedView(MaterializedView
the view to add
view
)

Add a materialized view to this table.

public void
addDependentView(TableView
the view to add
view
)

Add a view to this table.

public abstract Index

Returns:

the index
addIndex
(SessionLocal
the session
session
,
String
the name of the index
indexName
,
int
the id
indexId
,
IndexColumn[]
the index columns
cols
,
int
the count of unique columns
uniqueColumnCount
,
IndexType
the index type
indexType
,
boolean
whether this is a new index
create
,
String
the comment
indexComment
)

Create an index for this table

public abstract void
addRow(SessionLocal
the session
session
,
Row
the row
row
)

Add a row to the table and all indexes.

public void
addSequence(Sequence
the sequence to add
sequence
)

Add a sequence to this table.

public void
addSynonym(TableSynonym
the synonym to add
synonym
)

Add a synonym to this table.

public void
addTrigger(TriggerObject
the trigger to add
trigger
)

Add a trigger to this table.

public abstract boolean

Returns:

true if it can
canDrop
()

Check if this table can be dropped.

public abstract boolean

Returns:

true if it can
canGetRowCount
(SessionLocal
the session
session
)

Check if the row count can be retrieved quickly.

public boolean

Returns:

true if it can
canReference
()

Check if this table can be referenced.

public boolean

Returns:

true if it can
canTruncate
()

Check if this table can be truncated.

public ArrayList<SessionLocal>

Returns:

an object array with the sessions involved in the deadlock, or null
checkDeadlock
(SessionLocal
the session to be tested for
session
,
SessionLocal
set with sessions already visited, and null when starting verification
clash
,
Set<SessionLocal>
set with sessions already visited, and null when starting verification
visited
)

Check if a deadlock occurred.

public abstract void
checkSupportAlter()

Check if this table supports ALTER TABLE.

public void
checkWritingAllowed()

Tests if the table can be written.

public abstract void
close(SessionLocal
the session
session
)

Close the table object and flush changes.

public int

Returns:

0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
compareValues
(CastDataProvider
the cast information provider
provider
,
Value
the first value
a
,
Value
the second value
b
)

Compare two values with the current comparison mode.

public void
convertInsertRow(SessionLocal
the session
session
,
Row
the row
row
,
Boolean
Boolean#TRUE for OVERRIDING SYSTEM VALUES, Boolean#FALSE for OVERRIDING USER VALUES, null if override clause is not specified
overridingSystem
)

Prepares the specified row for INSERT operation.

public void
convertUpdateRow(SessionLocal
the session
session
,
Row
the row
row
,
boolean
true if row was modified by INSERT or UPDATE trigger
fromTrigger
)

Prepares the specified row for UPDATE operation.

public Row

Returns:

the created row
createRow
(Value[]
the values
data
,
int
the estimated memory usage in bytes
memory
)

Create a new row for this table.

public boolean

Returns:

true if the column exists
doesColumnExist
(String
the column name
columnName
)

Does the column with the given name exist?

public void
dropMultipleColumnsConstraintsAndIndexes(SessionLocal
the session
session
,
ArrayList<Column>
the columns to drop
columnsToDrop
)

Check that these columns are not referenced by a multi-column constraint or multi-column index.

private static Column[]
excludeInvisible(Column[] allColumns, int count, int i)

public Column

Returns:

the column
findColumn
(String
the column name, or null
columnName
)

Get the column with the given name if it exists.

public Index

Returns:

the primary key index or null
findPrimaryKey
()

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

public void
fire(SessionLocal
the session
session
,
int
the trigger type
type
,
boolean
whether 'before' triggers should be called
beforeAction
)

Fire the triggers for this table.

public void
fireAfterRow(SessionLocal
the session
session
,
Row
the old data or null for an insert
oldRow
,
Row
the new data or null for a delete
newRow
,
boolean
when the operation occurred within a rollback
rollback
)

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

public boolean

Returns:

true if no further action is required (for 'instead of' triggers)
fireBeforeRow
(SessionLocal
the session
session
,
Row
the old data or null for an insert
oldRow
,
Row
the new data or null for a delete
newRow
)

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

private void
fireConstraints(SessionLocal session, Row oldRow, Row newRow, boolean before)

public boolean

Returns:

if there are any triggers or rows defined
fireRow
()

Check if row based triggers or constraints are defined.

private boolean
fireRow(SessionLocal session, Row oldRow, Row newRow, boolean beforeAction, boolean rollback)

public PlanItem

Returns:

the plan item
getBestPlanItem
(SessionLocal
the session
session
,
int[]
per-column comparison bit masks, null means 'always false', see constants in IndexCondition
masks
,
TableFilter[]
all joined table filters
filters
,
int
the current table filter index
filter
,
SortOrder
the sort order
sortOrder
,
AllColumnsForPlan
the set of all columns
allColumnsSet
)

Get the best plan for the given search mask.

public boolean

Returns:

is foreign key constraint checking enabled for this table.
getCheckForeignKeyConstraints
()

public ArrayList<DbObject>
getChildren()

Overrides org.h2.engine.DbObject.getChildren.

Get the list of dependent children (for tables, this includes indexes and so on).

public Column

Returns:

the column
getColumn
(int
the column index (0, 1,...)
index
)

Get the column at the given index.

public Column

Returns:

the column
getColumn
(String
the column name
columnName
)

Get the column with the given name.

public Column

Returns:

the column
getColumn
(String
the column name
columnName
,
boolean
if true return null if column does not exist
ifExists
)

Get the column with the given name.

public final Column[]
public CompareMode
public ArrayList<Constraint>
public CopyOnWriteArrayList<MaterializedView>
public CopyOnWriteArrayList<TableView>
public long
getDiskSpaceUsed(boolean total, boolean approximate)

public Column

Returns:

first identity column, or null
getIdentityColumn
()

Returns first identity column, or null.

public Index

Returns:

the found index
getIndex
(String
the index name to search for
indexName
)

Get an index by name.

public abstract ArrayList<Index>

Returns:

the list of indexes
getIndexes
()

Get all indexes for this table.

public Index

Returns:

the index or null
getIndexForColumn
(Column
the column
column
,
boolean
if the returned index must be able to do Index#canGetFirstOrLast()
needGetFirstOrLast
,
boolean
if the returned index must be able to do Index#findNext(SessionLocal, SearchRow, SearchRow)
needFindNext
)

Get the index that has the given column as the first element.

private static IndexHints
getIndexHints(TableFilter[] filters, int filter)

public int

Returns:

ID of main index column, or SearchRow#ROWID_INDEX
getMainIndexColumn
()

Returns ID of main index column, or SearchRow#ROWID_INDEX.

public abstract long

Returns:

the modification id
getMaxDataModificationId
()

Get the last data modification id.

public Row
public boolean
public boolean
public Index
public Row

Returns:

the row
getRow
(SessionLocal
the session
session
,
long
the primary key
key
)

Get the given row.

public abstract long

Returns:

the row count
getRowCount
(SessionLocal
the session
session
)

Get the row count for this table.

public abstract long

Returns:

the approximated row count
getRowCountApproximation
(SessionLocal
the session
session
)

Get the approximated row count for this table.

public RowFactory
public Column

Returns:

the row id column, or null
getRowIdColumn
()

Get the row id column if this table has one.

public abstract Index

Returns:

the index
getScanIndex
(SessionLocal
the session
session
)

Get the scan index to iterate through all rows.

public Index

Returns:

the scan index
getScanIndex
(SessionLocal
the session
session
,
int[]
the search mask
masks
,
TableFilter[]
the table filters
filters
,
int
the filter index
filter
,
SortOrder
the sort order
sortOrder
,
AllColumnsForPlan
all columns
allColumnsSet
)

Get the scan index for this table.

public String

Returns:

SQL table type for INFORMATION_SCHEMA
getSQLTableType
()

Return SQL table type for INFORMATION_SCHEMA.

public abstract TableType

Returns:

the table type name
getTableType
()

Get the table type name

public Row
public SearchRow

Returns:

the simple row object
getTemplateSimpleRow
(boolean
if only one value need to be stored
singleColumn
)

Get a new simple row object.

public ArrayList<TriggerObject>

Returns:

list of triggers
getTriggers
()

Return list of triggers.

public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

public final Column[]
public boolean

Returns:

true if it has
hasSelectTrigger
()

Check whether this table has a select trigger.

public abstract boolean

Returns:

true if it is
isDeterministic
()

Check if the table is deterministic.

public boolean
private static boolean
public boolean

Returns:

whether this table is insertable
isInsertable
()

Returns whether this table is insertable.

public boolean

Returns:

true if it is.
isLockedExclusively
()

Check if this table is locked exclusively.

public boolean

Returns:

true if it is
isLockedExclusivelyBy
(SessionLocal
the session
session
)

Check if the table is exclusively locked by this session.

public boolean
public boolean
public boolean

Returns:

true if the table contains no query-comparable column
isQueryComparable
()

Check whether the table (or view) contains no columns that prevent index conditions to be used.

public boolean

Returns:

true if table supports row-level locks
isRowLockable
()

Views, function tables, links, etc. do not support locks

public boolean
public boolean

Returns:

true if the table was already exclusively locked by this session.
lock
(SessionLocal
the session
session
,
int
the type of lock
lockType
)

Lock the table for the given session.

public Row

Returns:

locked row, or null if row does not exist anymore or if it was skipped
lockRow
(SessionLocal
the session
session
,
Row
to lock
row
,
int
timeout in milliseconds, -1 for default, -2 to skip locking if row is already locked by another session
timeoutMillis
)

Locks row, preventing any updated to it, except from the session specified.

private static void
remove(ArrayList<? extends DbObject> list, DbObject obj)

public void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

public void
removeColumnExpressionsDependencies(SessionLocal
the session
session
)

Removes dependencies of column expressions, used for tables with circular dependencies.

public void
removeConstraint(Constraint
the constraint to remove
constraint
)

Remove the given constraint from the list.

public void
removeDependentMaterializedView(MaterializedView
the view to remove
view
)

Remove the given view from the dependent views list.

public void
removeDependentView(TableView
the view to remove
view
)

Remove the given view from the dependent views list.

public void
removeIndex(Index
the index to remove
index
)

Remove the given index from the list.

public void
removeIndexOrTransferOwnership(SessionLocal
the session
session
,
Index
the index that is no longer required
index
)

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

public abstract void
removeRow(SessionLocal
the session
session
,
Row
the row
row
)

Remove a row from the table and all indexes.

public final void
removeSequence(Sequence
the sequence to remove
sequence
)

Remove a sequence from the table.

public void
removeSynonym(TableSynonym
the synonym to remove
synonym
)

Remove the given view from the list.

public void
removeTrigger(TriggerObject
the trigger to remove
trigger
)

Remove the given trigger from the list.

public void
rename(String
the new name
newName
)

Overrides org.h2.engine.DbObject.rename.

Rename the object.

public void
renameColumn(Column
the column to rename
column
,
String
the new column name
newName
)

Rename a column of this table.

public void
setCheckForeignKeyConstraints(SessionLocal
the session
session
,
boolean
true if checking should be enabled
enabled
,
boolean
true if existing rows must be checked during this call
checkExisting
)

Enable or disable foreign key constraint checking for this table.

protected void
setColumns(Column[] columns)

public void
setOnCommitDrop(boolean onCommitDrop)

public void
setOnCommitTruncate(boolean onCommitTruncate)

public abstract long

Returns:

number of removed rows, possibly including uncommitted rows
truncate
(SessionLocal
the session
session
)

Remove all rows from the table and indexes.

public void
unlock(SessionLocal
the session
s
)

Release the lock for this session.

public void
updateRow(SessionLocal
the session
session
,
Row
the row to update
oldRow
,
Row
the row with updated values (_rowid_ suppose to be the same)
newRow
)

Update a row to the table and all indexes.

public void
updateRows(Prepared
the prepared statement
prepared
,
SessionLocal
the session
session
,
LocalResult
a list of row pairs of the form old row, new row, old row, new row,...
rows
)

Update a list of rows in this table.

Inherited from org.h2.schema.SchemaObject:
getSchemagetSQLgetSQL