org.h2.table
Class TableLink

java.lang.Object
  extended by org.h2.engine.DbObjectBase
      extended by org.h2.schema.SchemaObjectBase
          extended by org.h2.table.Table
              extended by org.h2.table.TableLink
All Implemented Interfaces:
DbObject, SchemaObject

public class TableLink
extends Table

A linked table contains connection information for a table accessible by JDBC. The table may be stored in a different database.


Field Summary
 
Fields inherited from class org.h2.table.Table
columns, compareMode, EXTERNAL_TABLE_ENGINE, isHidden, SYSTEM_TABLE, TABLE, TABLE_LINK, TYPE_CACHED, TYPE_MEMORY, VIEW
 
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
TableLink(Schema schema, int id, java.lang.String name, java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String originalSchema, java.lang.String originalTable, boolean emitUpdates, boolean force)
           
 
Method Summary
 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
 void addRow(Session session, Row row)
          Add a row to the table and all indexes.
 boolean canDrop()
          Check if this table can be dropped.
 boolean canGetRowCount()
          Check if the row count can be retrieved quickly.
 void checkRename()
          Check if this object can be renamed.
 void checkSupportAlter()
          Check if this table supports ALTER TABLE.
 void checkWritingAllowed()
          Linked tables don't know if they are readonly.
 void close(Session session)
          Close the table object and flush changes.
 TableLinkConnection getConnection()
           
 java.lang.String getCreateSQL()
          Build a SQL statement to re-create this object.
 Value getDefaultValue(Session session, Column column)
          Get or generate a default value for the given column.
 java.lang.String getDropSQL()
          Build a SQL statement to drop this object.
 java.util.ArrayList<Index> getIndexes()
          Get all indexes for this table.
 long getMaxDataModificationId()
          Get the last data modification id.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String sql, boolean exclusive)
          Get a prepared statement object for the given statement.
 java.lang.String getQualifiedTable()
           
 long getRowCount(Session session)
          Get the row count for this table.
 long getRowCountApproximation()
          Get the approximated row count for this table.
 Index getScanIndex(Session session)
          Get the scan index to iterate through all rows.
 java.lang.String getTableType()
          Get the table type name
 Index getUniqueIndex()
          Get any unique index for this table if one exists.
 boolean isDeterministic()
          Check if the table is deterministic.
 boolean isLockedExclusively()
          Check if this table is locked exclusively.
 boolean isOracle()
           
 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 removeRow(Session session, Row row)
          Remove a row from the table and all indexes.
 void reusePreparedStatement(java.sql.PreparedStatement prep, java.lang.String sql)
          Add this prepared statement to the list of cached statements.
 void setGlobalTemporary(boolean globalTemporary)
           
 void setReadOnly(boolean readOnly)
           
 void truncate(Session session)
          Remove all rows from the table and indexes.
 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)
          Convert the values if required.
 DbException wrapException(java.lang.String sql, java.lang.Exception ex)
          Wrap a SQL exception that occurred while accessing a linked table.
 
Methods inherited from class org.h2.table.Table
addConstraint, addDependencies, addSequence, addTrigger, addView, canReference, canTruncate, checkColumnIsNotReferenced, checkDeadlock, compareTypeSave, findPrimaryKey, fire, fireAfterRow, fireBeforeRow, fireRow, getBestPlanItem, getCheckForeignKeyConstraints, getChildren, getColumn, getColumn, getColumns, getCompareMode, getConstraints, getCreateSQLForCopy, getIndexForColumn, getOnCommitDrop, getOnCommitTruncate, getPrimaryKey, getTemplateRow, getTemplateSimpleRow, getType, getViews, hasSelectTrigger, isGlobalTemporary, isHidden, isLockedExclusivelyBy, isPersistData, isPersistIndexes, removeConstraint, removeIndex, removeIndexOrTransferOwnership, removeSequence, removeTrigger, rename, renameColumn, setCheckForeignKeyConstraints, setColumns, setOnCommitDrop, setOnCommitTruncate
 
Methods inherited from class org.h2.schema.SchemaObjectBase
getSchema, getSQL, initSchemaObjectBase
 
Methods inherited from class org.h2.engine.DbObjectBase
getComment, getDatabase, 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
getComment, getDatabase, getId, getModificationId, getName, isTemporary, setComment, setModified, setTemporary
 

Constructor Detail

TableLink

public TableLink(Schema schema,
                 int id,
                 java.lang.String name,
                 java.lang.String driver,
                 java.lang.String url,
                 java.lang.String user,
                 java.lang.String password,
                 java.lang.String originalSchema,
                 java.lang.String originalTable,
                 boolean emitUpdates,
                 boolean force)
Method Detail

getDropSQL

public java.lang.String getDropSQL()
Description copied from class: DbObjectBase
Build a SQL statement to drop this object.

Specified by:
getDropSQL in interface DbObject
Specified by:
getDropSQL in class DbObjectBase
Returns:
the SQL statement

getCreateSQL

public java.lang.String getCreateSQL()
Description copied from class: DbObjectBase
Build a SQL statement to re-create this object.

Specified by:
getCreateSQL in interface DbObject
Specified by:
getCreateSQL in class DbObjectBase
Returns:
the SQL statement

addIndex

public Index addIndex(Session session,
                      java.lang.String indexName,
                      int indexId,
                      IndexColumn[] cols,
                      IndexType indexType,
                      boolean create,
                      java.lang.String indexComment)
Description copied from class: Table
Create an index for this table

Specified by:
addIndex in class 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

lock

public void lock(Session session,
                 boolean exclusive,
                 boolean force)
Description copied from class: Table
Lock the table for the given session. This method waits until the lock is granted.

Specified by:
lock in class Table
Parameters:
session - the session
exclusive - true for write locks, false for read locks
force - lock even in the MVCC mode

isLockedExclusively

public boolean isLockedExclusively()
Description copied from class: Table
Check if this table is locked exclusively.

Specified by:
isLockedExclusively in class Table
Returns:
true if it is.

getScanIndex

public Index getScanIndex(Session session)
Description copied from class: Table
Get the scan index to iterate through all rows.

Specified by:
getScanIndex in class Table
Parameters:
session - the session
Returns:
the index

removeRow

public void removeRow(Session session,
                      Row row)
Description copied from class: Table
Remove a row from the table and all indexes.

Specified by:
removeRow in class Table
Parameters:
session - the session
row - the row

addRow

public void addRow(Session session,
                   Row row)
Description copied from class: Table
Add a row to the table and all indexes.

Specified by:
addRow in class Table
Parameters:
session - the session
row - the row

close

public void close(Session session)
Description copied from class: Table
Close the table object and flush changes.

Specified by:
close in class Table
Parameters:
session - the session

getRowCount

public long getRowCount(Session session)
Description copied from class: Table
Get the row count for this table.

Specified by:
getRowCount in class Table
Parameters:
session - the session
Returns:
the row count

wrapException

public DbException wrapException(java.lang.String sql,
                                 java.lang.Exception ex)
Wrap a SQL exception that occurred while accessing a linked table.

Parameters:
sql - the SQL statement
ex - the exception from the remote database
Returns:
the wrapped exception

getQualifiedTable

public java.lang.String getQualifiedTable()

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String sql,
                                                       boolean exclusive)
Get a prepared statement object for the given statement. Prepared statements are kept in a hash map to avoid re-creating them.

Parameters:
sql - the SQL statement
exclusive - if the prepared statement must be removed from the map until reusePreparedStatement is called (only required for queries)
Returns:
the prepared statement

unlock

public void unlock(Session s)
Description copied from class: Table
Release the lock for this session.

Specified by:
unlock in class Table
Parameters:
s - the session

checkRename

public void checkRename()
Description copied from class: DbObjectBase
Check if this object can be renamed. System objects may not be renamed.

Specified by:
checkRename in interface DbObject
Specified by:
checkRename in class DbObjectBase

checkSupportAlter

public void checkSupportAlter()
Description copied from class: Table
Check if this table supports ALTER TABLE.

Specified by:
checkSupportAlter in class Table

truncate

public void truncate(Session session)
Description copied from class: Table
Remove all rows from the table and indexes.

Specified by:
truncate in class Table
Parameters:
session - the session

canGetRowCount

public boolean canGetRowCount()
Description copied from class: Table
Check if the row count can be retrieved quickly.

Specified by:
canGetRowCount in class Table
Returns:
true if it can

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 java.lang.String 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(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
Overrides:
removeChildrenAndResources in class Table
Parameters:
session - the session

isOracle

public boolean isOracle()

getIndexes

public java.util.ArrayList<Index> getIndexes()
Description copied from class: Table
Get all indexes for this table.

Specified by:
getIndexes in class Table
Returns:
the list of indexes

getMaxDataModificationId

public long getMaxDataModificationId()
Description copied from class: Table
Get the last data modification id.

Specified by:
getMaxDataModificationId in class Table
Returns:
the modification id

getUniqueIndex

public Index getUniqueIndex()
Description copied from class: Table
Get any unique index for this table if one exists.

Specified by:
getUniqueIndex in class Table
Returns:
a unique index

updateRows

public void updateRows(Prepared prepared,
                       Session session,
                       RowList rows)
Description copied from class: Table
Update a list of rows in this table.

Overrides:
updateRows in class 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,...

setGlobalTemporary

public void setGlobalTemporary(boolean globalTemporary)

setReadOnly

public void setReadOnly(boolean readOnly)

getConnection

public TableLinkConnection getConnection()

getRowCountApproximation

public long getRowCountApproximation()
Description copied from class: Table
Get the approximated row count for this table.

Specified by:
getRowCountApproximation in class Table
Returns:
the approximated row count

reusePreparedStatement

public void reusePreparedStatement(java.sql.PreparedStatement prep,
                                   java.lang.String sql)
Add this prepared statement to the list of cached statements.

Parameters:
prep - the prepared statement
sql - the SQL statement

isDeterministic

public boolean isDeterministic()
Description copied from class: Table
Check if the table is deterministic.

Specified by:
isDeterministic in class Table
Returns:
true if it is

checkWritingAllowed

public void checkWritingAllowed()
Linked tables don't know if they are readonly. This overwrites the default handling.

Overrides:
checkWritingAllowed in class Table

validateConvertUpdateSequence

public void validateConvertUpdateSequence(Session session,
                                          Row row)
Convert the values if required. Default values are not set (kept as null).

Overrides:
validateConvertUpdateSequence in class Table
Parameters:
session - the session
row - the row

getDefaultValue

public Value getDefaultValue(Session session,
                             Column column)
Get or generate a default value for the given column. Default values are not set (kept as null).

Overrides:
getDefaultValue in class Table
Parameters:
session - the session
column - the column
Returns:
the value