Package org.h2.table
Class TableLink
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.table.Table
-
- org.h2.table.TableLink
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautocommitprivate TableLinkConnectionconnprivate DbExceptionconnectExceptionprivate java.lang.Stringdriverprivate booleanemitUpdatesprivate intfetchSizeprivate booleanglobalTemporaryprivate java.util.ArrayList<Index>indexesprivate LinkedIndexlinkedIndexprivate static intMAX_RETRYprivate java.lang.StringoriginalSchemaprivate java.lang.StringoriginalTableprivate java.lang.Stringpasswordprivate java.util.HashMap<java.lang.String,java.sql.PreparedStatement>preparedMapprivate java.lang.StringqualifiedTableNameprivate booleanreadOnlyprivate static longROW_COUNT_APPROXIMATIONprivate booleanstoresLowerCaseprivate booleanstoresMixedCaseprivate booleanstoresMixedCaseQuotedprivate booleansupportsMixedCaseIdentifiersprivate booleantargetsMySqlprivate java.lang.Stringurlprivate java.lang.Stringuser-
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 Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddIndex(java.util.List<Column> list, int uniqueColumnCount, IndexType indexType)IndexaddIndex(SessionLocal session, java.lang.String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, java.lang.String indexComment)Create an index for this tablevoidaddRow(SessionLocal session, Row row)Add a row to the table and all indexes.booleancanDrop()Check if this table can be dropped.booleancanGetRowCount(SessionLocal session)Check if the row count can be retrieved quickly.private voidcheckReadOnly()voidcheckSupportAlter()Check if this table supports ALTER TABLE.voidcheckWritingAllowed()Linked tables don't know if they are readonly.voidclose(SessionLocal session)Close the table object and flush changes.private voidconnect()private java.lang.StringconvertColumnName(java.lang.String columnName)voidconvertInsertRow(SessionLocal session, Row row, java.lang.Boolean overridingSystem)Prepares the specified row for INSERT operation.private static longconvertPrecision(int sqlType, long precision)private voidconvertRow(SessionLocal session, Row row)private static intconvertScale(int sqlType, int scale)voidconvertUpdateRow(SessionLocal session, Row row, boolean fromTrigger)Prepares the specified row for UPDATE operation.java.sql.PreparedStatementexecute(java.lang.String sql, java.util.ArrayList<Value> params, boolean reusePrepared, SessionLocal session)Execute a SQL statement using the given parameters.booleangetAutocommit()The autocommit modejava.lang.StringgetCreateSQL()Construct the CREATE ...java.lang.StringgetDropSQL()Construct a DROP ...intgetFetchSize()The number of rows to fetch default is 0java.util.ArrayList<Index>getIndexes()Get all indexes for this table.longgetMaxDataModificationId()Get the last data modification id.java.lang.StringgetQualifiedTable()longgetRowCount(SessionLocal session)Get the row count for this table.longgetRowCountApproximation(SessionLocal session)Get the approximated row count for this table.IndexgetScanIndex(SessionLocal session)Get the scan index to iterate through all rows.TableTypegetTableType()Get the table type namebooleanisDeterministic()Check if the table is deterministic.booleanisInsertable()Returns whether this table is insertable.private static booleanisMySqlUrl(java.lang.String url)booleanisOracle()private voidreadIndexes(java.sql.DatabaseMetaData meta, java.util.HashMap<java.lang.String,Column> columnMap)private voidreadIndexes(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap, java.lang.String pkName)private voidreadMetaData()private java.lang.StringreadPrimaryKey(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap)voidremoveChildrenAndResources(SessionLocal session)Delete all dependent children objects and resources of this object.voidremoveRow(SessionLocal session, Row row)Remove a row from the table and all indexes.voidreusePreparedStatement(java.sql.PreparedStatement prep, java.lang.String sql)Add this prepared statement to the list of cached statements.voidsetAutoCommit(boolean mode)Specify if the autocommit mode is activated or notvoidsetFetchSize(int fetchSize)Specify the number of rows fetched by the linked table commandvoidsetGlobalTemporary(boolean globalTemporary)voidsetReadOnly(boolean readOnly)longtruncate(SessionLocal session)Remove all rows from the table and indexes.voidupdateRows(Prepared prepared, SessionLocal session, LocalResult rows)Update a list of rows in this table.static DbExceptionwrapException(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, addDependentView, addSequence, addSynonym, addTrigger, canReference, canTruncate, checkDeadlock, compareValues, createRow, doesColumnExist, dropMultipleColumnsConstraintsAndIndexes, findColumn, findPrimaryKey, fire, fireAfterRow, fireBeforeRow, fireRow, getBestPlanItem, getCheckForeignKeyConstraints, getChildren, getColumn, getColumn, getColumn, getColumns, getCompareMode, getConstraints, getCreateSQLForCopy, getDependentViews, getDiskSpaceUsed, getIdentityColumn, getIndex, getIndexForColumn, getMainIndexColumn, getNullRow, getOnCommitDrop, getOnCommitTruncate, getPrimaryKey, getRow, getRowFactory, getRowIdColumn, getScanIndex, getSQLTableType, getTemplateRow, getTemplateSimpleRow, getTriggers, getType, hasSelectTrigger, isGlobalTemporary, isHidden, isLockedExclusively, isLockedExclusivelyBy, isPersistData, isPersistIndexes, isQueryComparable, isRowLockable, isTableExpression, isView, lock, lockRow, removeColumnExpressionsDependencies, removeConstraint, removeDependentView, removeIndex, removeIndexOrTransferOwnership, removeSequence, removeSynonym, removeTrigger, rename, renameColumn, setCheckForeignKeyConstraints, setColumns, setHidden, setOnCommitDrop, setOnCommitTruncate, setTableExpression, unlock, updateRow
-
Methods inherited from class org.h2.schema.SchemaObject
getSchema, getSQL, 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
-
-
-
-
Field Detail
-
MAX_RETRY
private static final int MAX_RETRY
- See Also:
- Constant Field Values
-
ROW_COUNT_APPROXIMATION
private static final long ROW_COUNT_APPROXIMATION
- See Also:
- Constant Field Values
-
originalSchema
private final java.lang.String originalSchema
-
driver
private java.lang.String driver
-
url
private java.lang.String url
-
user
private java.lang.String user
-
password
private java.lang.String password
-
originalTable
private java.lang.String originalTable
-
qualifiedTableName
private java.lang.String qualifiedTableName
-
conn
private TableLinkConnection conn
-
preparedMap
private java.util.HashMap<java.lang.String,java.sql.PreparedStatement> preparedMap
-
indexes
private final java.util.ArrayList<Index> indexes
-
emitUpdates
private final boolean emitUpdates
-
linkedIndex
private LinkedIndex linkedIndex
-
connectException
private DbException connectException
-
storesLowerCase
private boolean storesLowerCase
-
storesMixedCase
private boolean storesMixedCase
-
storesMixedCaseQuoted
private boolean storesMixedCaseQuoted
-
supportsMixedCaseIdentifiers
private boolean supportsMixedCaseIdentifiers
-
globalTemporary
private boolean globalTemporary
-
readOnly
private boolean readOnly
-
targetsMySql
private final boolean targetsMySql
-
fetchSize
private int fetchSize
-
autocommit
private boolean autocommit
-
-
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
-
connect
private void connect()
-
readMetaData
private void readMetaData() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
readIndexes
private void readIndexes(java.sql.DatabaseMetaData meta, java.util.HashMap<java.lang.String,Column> columnMap)
-
readPrimaryKey
private java.lang.String readPrimaryKey(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
readIndexes
private void readIndexes(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap, java.lang.String pkName) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
convertPrecision
private static long convertPrecision(int sqlType, long precision)
-
convertScale
private static int convertScale(int sqlType, int scale)
-
convertColumnName
private java.lang.String convertColumnName(java.lang.String columnName)
-
addIndex
private void addIndex(java.util.List<Column> list, int uniqueColumnCount, IndexType indexType)
-
getDropSQL
public java.lang.String getDropSQL()
Description copied from class:DbObjectConstruct a DROP ... SQL statement for this object.- Overrides:
getDropSQLin classDbObject- Returns:
- the SQL statement
-
getCreateSQL
public java.lang.String getCreateSQL()
Description copied from class:DbObjectConstruct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQLin classDbObject- Returns:
- the SQL statement
-
addIndex
public Index addIndex(SessionLocal session, java.lang.String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, java.lang.String indexComment)
Description copied from class:TableCreate an index for this table- Specified by:
addIndexin classTable- Parameters:
session- the sessionindexName- the name of the indexindexId- the idcols- the index columnsuniqueColumnCount- the count of unique columnsindexType- the index typecreate- whether this is a new indexindexComment- the comment- Returns:
- the index
-
getScanIndex
public Index getScanIndex(SessionLocal session)
Description copied from class:TableGet the scan index to iterate through all rows.- Specified by:
getScanIndexin classTable- Parameters:
session- the session- Returns:
- the index
-
isInsertable
public boolean isInsertable()
Description copied from class:TableReturns whether this table is insertable.- Overrides:
isInsertablein classTable- Returns:
- whether this table is insertable
-
checkReadOnly
private void checkReadOnly()
-
removeRow
public void removeRow(SessionLocal session, Row row)
Description copied from class:TableRemove a row from the table and all indexes.
-
addRow
public void addRow(SessionLocal session, Row row)
Description copied from class:TableAdd a row to the table and all indexes.
-
close
public void close(SessionLocal session)
Description copied from class:TableClose the table object and flush changes.
-
getRowCount
public long getRowCount(SessionLocal session)
Description copied from class:TableGet the row count for this table.- Specified by:
getRowCountin classTable- Parameters:
session- the session- Returns:
- the row count
-
wrapException
public static 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 statementex- the exception from the remote database- Returns:
- the wrapped exception
-
getQualifiedTable
public java.lang.String getQualifiedTable()
-
execute
public java.sql.PreparedStatement execute(java.lang.String sql, java.util.ArrayList<Value> params, boolean reusePrepared, SessionLocal session)Execute a SQL statement using the given parameters. Prepared statements are kept in a hash map to avoid re-creating them.- Parameters:
sql- the SQL statementparams- the parameters or nullreusePrepared- if the prepared statement can be re-used immediatelysession- the session- Returns:
- the prepared statement, or null if it is re-used
-
checkSupportAlter
public void checkSupportAlter()
Description copied from class:TableCheck if this table supports ALTER TABLE.- Specified by:
checkSupportAlterin classTable
-
truncate
public long truncate(SessionLocal session)
Description copied from class:TableRemove all rows from the table and indexes.
-
canGetRowCount
public boolean canGetRowCount(SessionLocal session)
Description copied from class:TableCheck if the row count can be retrieved quickly.- Specified by:
canGetRowCountin classTable- Parameters:
session- the session- Returns:
- true if it can
-
canDrop
public boolean canDrop()
Description copied from class:TableCheck if this table can be dropped.
-
getTableType
public TableType getTableType()
Description copied from class:TableGet the table type name- Specified by:
getTableTypein classTable- Returns:
- the table type name
-
removeChildrenAndResources
public void removeChildrenAndResources(SessionLocal session)
Description copied from class:DbObjectDelete all dependent children objects and resources of this object.- Overrides:
removeChildrenAndResourcesin classTable- Parameters:
session- the session
-
isOracle
public boolean isOracle()
-
isMySqlUrl
private static boolean isMySqlUrl(java.lang.String url)
-
getIndexes
public java.util.ArrayList<Index> getIndexes()
Description copied from class:TableGet all indexes for this table.- Specified by:
getIndexesin classTable- Returns:
- the list of indexes
-
getMaxDataModificationId
public long getMaxDataModificationId()
Description copied from class:TableGet the last data modification id.- Specified by:
getMaxDataModificationIdin classTable- Returns:
- the modification id
-
updateRows
public void updateRows(Prepared prepared, SessionLocal session, LocalResult rows)
Description copied from class:TableUpdate a list of rows in this table.- Overrides:
updateRowsin classTable- Parameters:
prepared- the prepared statementsession- the sessionrows- 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)
-
getRowCountApproximation
public long getRowCountApproximation(SessionLocal session)
Description copied from class:TableGet the approximated row count for this table.- Specified by:
getRowCountApproximationin classTable- Parameters:
session- the session- 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 statementsql- the SQL statement
-
isDeterministic
public boolean isDeterministic()
Description copied from class:TableCheck if the table is deterministic.- Specified by:
isDeterministicin classTable- Returns:
- true if it is
-
checkWritingAllowed
public void checkWritingAllowed()
Linked tables don't know if they are readonly. This overwrites the default handling.- Overrides:
checkWritingAllowedin classTable
-
convertInsertRow
public void convertInsertRow(SessionLocal session, Row row, java.lang.Boolean overridingSystem)
Description copied from class:TablePrepares the specified row for INSERT operation. Identity, default, and generated values are evaluated, all values are converted to target data types and validated. Base value of identity column is updated when required by compatibility mode.- Overrides:
convertInsertRowin classTable- Parameters:
session- the sessionrow- the rowoverridingSystem-Boolean.TRUEforOVERRIDING SYSTEM VALUES,Boolean.FALSEforOVERRIDING USER VALUES,nullif override clause is not specified
-
convertUpdateRow
public void convertUpdateRow(SessionLocal session, Row row, boolean fromTrigger)
Description copied from class:TablePrepares the specified row for UPDATE operation. Default and generated values are evaluated, all values are converted to target data types and validated. Base value of identity column is updated when required by compatibility mode.- Overrides:
convertUpdateRowin classTable- Parameters:
session- the sessionrow- the rowfromTrigger-trueif row was modified by INSERT or UPDATE trigger
-
convertRow
private void convertRow(SessionLocal session, Row row)
-
setFetchSize
public void setFetchSize(int fetchSize)
Specify the number of rows fetched by the linked table command- Parameters:
fetchSize- to set
-
setAutoCommit
public void setAutoCommit(boolean mode)
Specify if the autocommit mode is activated or not- Parameters:
mode- to set
-
getAutocommit
public boolean getAutocommit()
The autocommit mode- Returns:
- true if autocommit is on
-
getFetchSize
public int getFetchSize()
The number of rows to fetch default is 0- Returns:
- number of rows to fetch
-
-