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 boolean
autocommit
private TableLinkConnection
conn
private DbException
connectException
private java.lang.String
driver
private boolean
emitUpdates
private int
fetchSize
private boolean
globalTemporary
private java.util.ArrayList<Index>
indexes
private LinkedIndex
linkedIndex
private static int
MAX_RETRY
private java.lang.String
originalSchema
private java.lang.String
originalTable
private java.lang.String
password
private java.util.HashMap<java.lang.String,java.sql.PreparedStatement>
preparedMap
private java.lang.String
qualifiedTableName
private boolean
readOnly
private static long
ROW_COUNT_APPROXIMATION
private boolean
storesLowerCase
private boolean
storesMixedCase
private boolean
storesMixedCaseQuoted
private boolean
supportsMixedCaseIdentifiers
private boolean
targetsMySql
private java.lang.String
url
private java.lang.String
user
-
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 void
addIndex(java.util.List<Column> list, int uniqueColumnCount, IndexType indexType)
Index
addIndex(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 tablevoid
addRow(SessionLocal session, Row row)
Add a row to the table and all indexes.boolean
canDrop()
Check if this table can be dropped.boolean
canGetRowCount(SessionLocal session)
Check if the row count can be retrieved quickly.private void
checkReadOnly()
void
checkSupportAlter()
Check if this table supports ALTER TABLE.void
checkWritingAllowed()
Linked tables don't know if they are readonly.void
close(SessionLocal session)
Close the table object and flush changes.private void
connect()
private java.lang.String
convertColumnName(java.lang.String columnName)
void
convertInsertRow(SessionLocal session, Row row, java.lang.Boolean overridingSystem)
Prepares the specified row for INSERT operation.private static long
convertPrecision(int sqlType, long precision)
private void
convertRow(SessionLocal session, Row row)
private static int
convertScale(int sqlType, int scale)
void
convertUpdateRow(SessionLocal session, Row row, boolean fromTrigger)
Prepares the specified row for UPDATE operation.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.boolean
getAutocommit()
The autocommit modejava.lang.String
getCreateSQL()
Construct the CREATE ...java.lang.String
getDropSQL()
Construct a DROP ...int
getFetchSize()
The number of rows to fetch default is 0java.util.ArrayList<Index>
getIndexes()
Get all indexes for this table.long
getMaxDataModificationId()
Get the last data modification id.java.lang.String
getQualifiedTable()
long
getRowCount(SessionLocal session)
Get the row count for this table.long
getRowCountApproximation(SessionLocal session)
Get the approximated row count for this table.Index
getScanIndex(SessionLocal session)
Get the scan index to iterate through all rows.TableType
getTableType()
Get the table type nameboolean
isDeterministic()
Check if the table is deterministic.boolean
isInsertable()
Returns whether this table is insertable.private static boolean
isMySqlUrl(java.lang.String url)
boolean
isOracle()
private void
readIndexes(java.sql.DatabaseMetaData meta, java.util.HashMap<java.lang.String,Column> columnMap)
private void
readIndexes(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap, java.lang.String pkName)
private void
readMetaData()
private java.lang.String
readPrimaryKey(java.sql.ResultSet rs, java.util.HashMap<java.lang.String,Column> columnMap)
void
removeChildrenAndResources(SessionLocal session)
Delete all dependent children objects and resources of this object.void
removeRow(SessionLocal 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
setAutoCommit(boolean mode)
Specify if the autocommit mode is activated or notvoid
setFetchSize(int fetchSize)
Specify the number of rows fetched by the linked table commandvoid
setGlobalTemporary(boolean globalTemporary)
void
setReadOnly(boolean readOnly)
long
truncate(SessionLocal session)
Remove all rows from the table and indexes.void
updateRows(Prepared prepared, SessionLocal session, LocalResult rows)
Update a list of rows in this table.static 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, 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:DbObject
Construct a DROP ... SQL statement for this object.- Overrides:
getDropSQL
in classDbObject
- 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 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:Table
Create an index for this table- Specified by:
addIndex
in 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:Table
Get the scan index to iterate through all rows.- Specified by:
getScanIndex
in classTable
- Parameters:
session
- the session- Returns:
- the index
-
isInsertable
public boolean isInsertable()
Description copied from class:Table
Returns whether this table is insertable.- Overrides:
isInsertable
in classTable
- Returns:
- whether this table is insertable
-
checkReadOnly
private void checkReadOnly()
-
removeRow
public void removeRow(SessionLocal session, Row row)
Description copied from class:Table
Remove a row from the table and all indexes.
-
addRow
public void addRow(SessionLocal session, Row row)
Description copied from class:Table
Add a row to the table and all indexes.
-
close
public void close(SessionLocal session)
Description copied from class:Table
Close the table object and flush changes.
-
getRowCount
public long getRowCount(SessionLocal session)
Description copied from class:Table
Get the row count for this table.- Specified by:
getRowCount
in 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:Table
Check if this table supports ALTER TABLE.- Specified by:
checkSupportAlter
in classTable
-
truncate
public long truncate(SessionLocal session)
Description copied from class:Table
Remove all rows from the table and indexes.
-
canGetRowCount
public boolean canGetRowCount(SessionLocal session)
Description copied from class:Table
Check if the row count can be retrieved quickly.- Specified by:
canGetRowCount
in classTable
- Parameters:
session
- the session- Returns:
- true if it can
-
canDrop
public boolean canDrop()
Description copied from class:Table
Check if this table can be dropped.
-
getTableType
public TableType getTableType()
Description copied from class:Table
Get the table type name- Specified by:
getTableType
in classTable
- 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 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:Table
Get all indexes for this table.- Specified by:
getIndexes
in classTable
- Returns:
- the list of indexes
-
getMaxDataModificationId
public long getMaxDataModificationId()
Description copied from class:Table
Get the last data modification id.- Specified by:
getMaxDataModificationId
in classTable
- Returns:
- the modification id
-
updateRows
public void updateRows(Prepared prepared, SessionLocal session, LocalResult rows)
Description copied from class:Table
Update a list of rows in this table.- Overrides:
updateRows
in 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:Table
Get the approximated row count for this table.- Specified by:
getRowCountApproximation
in 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:Table
Check if the table is deterministic.- Specified by:
isDeterministic
in 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:
checkWritingAllowed
in classTable
-
convertInsertRow
public void convertInsertRow(SessionLocal session, Row row, java.lang.Boolean overridingSystem)
Description copied from class:Table
Prepares 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:
convertInsertRow
in classTable
- Parameters:
session
- the sessionrow
- the rowoverridingSystem
-Boolean.TRUE
forOVERRIDING SYSTEM VALUES
,Boolean.FALSE
forOVERRIDING USER VALUES
,null
if override clause is not specified
-
convertUpdateRow
public void convertUpdateRow(SessionLocal session, Row row, boolean fromTrigger)
Description copied from class:Table
Prepares 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:
convertUpdateRow
in classTable
- Parameters:
session
- the sessionrow
- the rowfromTrigger
-true
if 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
-
-