org.h2.table

## Class TableView

- java.lang.Object
- - org.h2.engine.DbObject
  - - org.h2.schema.SchemaObject
    - - org.h2.table.Table
      - - org.h2.table.QueryExpressionTable
        - - org.h2.table.TableView

All Implemented Interfaces:
  HasSQL

    public final class TableView
    extends QueryExpressionTable

A view is a virtual table that is defined by a query.

### Field Summary

### Fields inherited from class org.h2.table.Table

`columns, compareMode, EXCLUSIVE_LOCK, isHidden, READ_LOCK, TYPE_CACHED, TYPE_MEMORY, WRITE_LOCK`

### Fields inherited from class org.h2.engine.DbObject

`AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER`

### Fields inherited from interface org.h2.util.HasSQL

`ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS`

### Constructor Summary

Constructors
Constructor and Description
`TableView(Schema schema, int id, java.lang.String name, java.lang.String querySQL, java.util.ArrayList<Parameter> params, Column[] columnTemplates, SessionLocal session, boolean allowRecursive, boolean literalsChecked, boolean isTableExpression, boolean isTemporary)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`boolean` `canDrop()` Check if this table can be dropped.
`static void` `clearIndexCaches(Database database)` Clear the cached indexes for all sessions.
`static Table` `createShadowTableForRecursiveTableExpression(boolean isTemporary, SessionLocal targetSession, java.lang.String cteViewName, Schema schema, java.util.List<Column> columns, Database db)` Create a table for a recursive query.
`static TableView` `createTableViewMaybeRecursive(Schema schema, int id, java.lang.String name, java.lang.String querySQL, java.util.ArrayList<Parameter> parameters, Column[] columnTemplates, SessionLocal session, boolean literalsChecked, boolean isTableExpression, boolean isTemporary, Database db)` Create a view.
`static void` `destroyShadowTableForRecursiveExpression(boolean isTemporary, SessionLocal targetSession, Table recursiveTable)` Remove a table for a recursive query.
`java.lang.String` `getCreateSQL()` Construct the CREATE ...
`java.lang.String` `getCreateSQL(boolean orReplace, boolean force)` Generate "CREATE" SQL statement for the view.
`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
`java.lang.String` `getDropSQL()` Construct a DROP ...
`long` `getMaxDataModificationId()` Get the last data modification id.
`java.lang.String` `getQuerySQL()`
`ResultInterface` `getRecursiveResult()`
`Index` `getScanIndex(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)` Get the scan index for this table.
`java.lang.StringBuilder` `getSQL(java.lang.StringBuilder builder, int sqlFlags)` Appends the SQL statement of this object to the specified builder.
`java.util.List<Table>` `getTables()`
`TableType` `getTableType()` Get the table type name
`Query` `getTopQuery()`
`boolean` `isDeterministic()` Check if the table is deterministic.
`boolean` `isInvalid()` Check if this view is currently invalid.
`boolean` `isRecursive()`
`boolean` `isRecursiveQueryDetected()` Was query recursion detected during compiling.
`DbException` `recompile(SessionLocal session, boolean force, boolean clearIndexCache)` Re-compile the view query and all views that depend on this object.
`void` `removeChildrenAndResources(SessionLocal session)` Delete all dependent children objects and resources of this object.
`void` `replace(java.lang.String querySQL, Column[] newColumnTemplates, SessionLocal session, boolean recursive, boolean force, boolean literalsChecked)` Try to replace the SQL statement of the view and re-compile this and all dependent views.
`void` `setRecursiveResult(ResultInterface value)`

### Methods inherited from class org.h2.table.QueryExpressionTable

`addDependencies, addIndex, addRow, canGetRowCount, canReference, checkSupportAlter, close, createQueryColumnTemplateList, getBestPlanItem, getIndexes, getParameterOffset, getQuery, getRowCount, getRowCountApproximation, getScanIndex, isInsertable, isQueryComparable, isView, removeRow, truncate`

### Methods inherited from class org.h2.table.Table

`addConstraint, addDependentView, addSequence, addSynonym, addTrigger, canTruncate, checkDeadlock, checkWritingAllowed, compareValues, convertInsertRow, convertUpdateRow, createRow, doesColumnExist, dropMultipleColumnsConstraintsAndIndexes, findColumn, findPrimaryKey, fire, fireAfterRow, fireBeforeRow, fireRow, getCheckForeignKeyConstraints, getChildren, getColumn, getColumn, getColumn, getColumns, getCompareMode, getConstraints, getDependentViews, getDiskSpaceUsed, getIdentityColumn, getIndex, getIndexForColumn, getMainIndexColumn, getNullRow, getOnCommitDrop, getOnCommitTruncate, getPrimaryKey, getRow, getRowFactory, getRowIdColumn, getSQLTableType, getTemplateRow, getTemplateSimpleRow, getTriggers, getType, hasSelectTrigger, isGlobalTemporary, isHidden, isLockedExclusively, isLockedExclusivelyBy, isPersistData, isPersistIndexes, isRowLockable, isTableExpression, lock, lockRow, removeColumnExpressionsDependencies, removeConstraint, removeDependentView, removeIndex, removeIndexOrTransferOwnership, removeSequence, removeSynonym, removeTrigger, rename, renameColumn, setCheckForeignKeyConstraints, setColumns, setHidden, setOnCommitDrop, setOnCommitTruncate, setTableExpression, unlock, updateRow, updateRows`

### Methods inherited from class org.h2.schema.SchemaObject

`getSchema, getSQL`

### Methods inherited from class org.h2.engine.DbObject

`checkRename, getComment, getCreateSQLForMeta, getDatabase, getId, getModificationId, getName, invalidate, isTemporary, isValid, 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.util.HasSQL

`getTraceSQL`

### Constructor Detail

#### TableView

    public TableView(Schema schema,
                     int id,
                     java.lang.String name,
                     java.lang.String querySQL,
                     java.util.ArrayList<Parameter> params,
                     Column[] columnTemplates,
                     SessionLocal session,
                     boolean allowRecursive,
                     boolean literalsChecked,
                     boolean isTableExpression,
                     boolean isTemporary)

### Method Detail

#### replace

    public void replace(java.lang.String querySQL,
                        Column[] newColumnTemplates,
                        SessionLocal session,
                        boolean recursive,
                        boolean force,
                        boolean literalsChecked)

Try to replace the SQL statement of the view and re-compile this and all dependent views.

Parameters:
  `querySQL` - the SQL statement
  `newColumnTemplates` - the columns
  `session` - the session
  `recursive` - whether this is a recursive view
  `force` - if errors should be ignored
  `literalsChecked` - if literals have been checked

#### recompile

    public DbException recompile(SessionLocal session,
                                 boolean force,
                                 boolean clearIndexCache)

Re-compile the view query and all views that depend on this object.

Parameters:
  `session` - the session
  `force` - if exceptions should be ignored
  `clearIndexCache` - if we need to clear view index cache
Returns:
  the exception if re-compiling this or any dependent view failed (only when force is disabled)

#### isInvalid

    public boolean isInvalid()

Check if this view is currently invalid.

Returns:
  true if it is

#### getTopQuery

    public Query getTopQuery()

Specified by:
  `getTopQuery` in class `QueryExpressionTable`

#### getDropSQL

    public java.lang.String getDropSQL()

Description copied from class: `DbObject`
Construct a DROP ... SQL statement for this object.

Overrides:
  `getDropSQL` in class `DbObject`
Returns:
  the SQL statement

#### getCreateSQLForCopy

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

Description copied from class: `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

Overrides:
  `getCreateSQLForCopy` in class `DbObject`
Parameters:
  `table` - the new table
  `quotedName` - the quoted name
Returns:
  the SQL statement

#### getCreateSQL

    public java.lang.String getCreateSQL()

Description copied from class: `DbObject`
Construct the CREATE ... SQL statement for this object.

Specified by:
  `getCreateSQL` in class `DbObject`
Returns:
  the SQL statement

#### getCreateSQL

    public java.lang.String getCreateSQL(boolean orReplace,
                                         boolean force)

Generate "CREATE" SQL statement for the view.

Parameters:
  `orReplace` - if true, then include the OR REPLACE clause
  `force` - if true, then include the FORCE clause
Returns:
  the SQL statement

#### canDrop

    public boolean canDrop()

Description copied from class: `Table`
Check if this table can be dropped.

Specified by:
  `canDrop` in class `Table`
Returns:
  true if it can

#### getTableType

    public TableType getTableType()

Description copied from class: `Table`
Get the table type name

Specified by:
  `getTableType` in class `Table`
Returns:
  the table type name

#### removeChildrenAndResources

    public void removeChildrenAndResources(SessionLocal session)

Description copied from class: `DbObject`
Delete all dependent children objects and resources of this object.

Overrides:
  `removeChildrenAndResources` in class `Table`
Parameters:
  `session` - the session

#### clearIndexCaches

    public static void clearIndexCaches(Database database)

Clear the cached indexes for all sessions.

Parameters:
  `database` - the database

#### getSQL

    public java.lang.StringBuilder getSQL(java.lang.StringBuilder builder,
                                          int sqlFlags)

Description copied from interface: `HasSQL`
Appends the SQL statement of this object to the specified builder.

Specified by:
  `getSQL` in interface `HasSQL`
Overrides:
  `getSQL` in class `SchemaObject`
Parameters:
  `builder` - string builder
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

#### getQuerySQL

    public java.lang.String getQuerySQL()

#### getScanIndex

    public Index getScanIndex(SessionLocal session,
                              int[] masks,
                              TableFilter[] filters,
                              int filter,
                              SortOrder sortOrder,
                              AllColumnsForPlan allColumnsSet)

Description copied from class: `Table`
Get the scan index for this table.

Overrides:
  `getScanIndex` in class `QueryExpressionTable`
Parameters:
  `session` - the session
  `masks` - the search mask
  `filters` - the table filters
  `filter` - the filter index
  `sortOrder` - the sort order
  `allColumnsSet` - all columns
Returns:
  the scan index

#### getMaxDataModificationId

    public long getMaxDataModificationId()

Description copied from class: `Table`
Get the last data modification id.

Overrides:
  `getMaxDataModificationId` in class `QueryExpressionTable`
Returns:
  the modification id

#### isRecursive

    public boolean isRecursive()

#### isDeterministic

    public boolean isDeterministic()

Description copied from class: `Table`
Check if the table is deterministic.

Overrides:
  `isDeterministic` in class `QueryExpressionTable`
Returns:
  true if it is

#### setRecursiveResult

    public void setRecursiveResult(ResultInterface value)

#### getRecursiveResult

    public ResultInterface getRecursiveResult()

#### isRecursiveQueryDetected

    public boolean isRecursiveQueryDetected()

Was query recursion detected during compiling.

Returns:
  true if yes

#### getTables

    public java.util.List<Table> getTables()

#### createTableViewMaybeRecursive

    public static TableView createTableViewMaybeRecursive(Schema schema,
                                                          int id,
                                                          java.lang.String name,
                                                          java.lang.String querySQL,
                                                          java.util.ArrayList<Parameter> parameters,
                                                          Column[] columnTemplates,
                                                          SessionLocal session,
                                                          boolean literalsChecked,
                                                          boolean isTableExpression,
                                                          boolean isTemporary,
                                                          Database db)

Create a view.

Parameters:
  `schema` - the schema
  `id` - the view id
  `name` - the view name
  `querySQL` - the query
  `parameters` - the parameters
  `columnTemplates` - the columns
  `session` - the session
  `literalsChecked` - whether literals in the query are checked
  `isTableExpression` - if this is a table expression
  `isTemporary` - whether the view is persisted
  `db` - the database
Returns:
  the view

#### createShadowTableForRecursiveTableExpression

    public static Table createShadowTableForRecursiveTableExpression(boolean isTemporary,
                                                                     SessionLocal targetSession,
                                                                     java.lang.String cteViewName,
                                                                     Schema schema,
                                                                     java.util.List<Column> columns,
                                                                     Database db)

Create a table for a recursive query.

Parameters:
  `isTemporary` - whether the table is persisted
  `targetSession` - the session
  `cteViewName` - the name
  `schema` - the schema
  `columns` - the columns
  `db` - the database
Returns:
  the table

#### destroyShadowTableForRecursiveExpression

    public static void destroyShadowTableForRecursiveExpression(boolean isTemporary,
                                                                SessionLocal targetSession,
                                                                Table recursiveTable)

Remove a table for a recursive query.

Parameters:
  `isTemporary` - whether the table is persisted
  `targetSession` - the session
  `recursiveTable` - the table