Package org.h2.table

Class TableLink

  • All Implemented Interfaces:
    HasSQL

    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 Detail

      • 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
      • 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
      • 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 class DbObject
        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
      • 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 class Table
        Parameters:
        session - the session
        indexName - the name of the index
        indexId - the id
        cols - the index columns
        uniqueColumnCount - the count of unique columns
        indexType - the index type
        create - whether this is a new index
        indexComment - 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 class Table
        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 class Table
        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.
        Specified by:
        removeRow in class Table
        Parameters:
        session - the session
        row - the row
      • addRow

        public void addRow​(SessionLocal 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​(SessionLocal 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​(SessionLocal 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 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 statement
        ex - 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 statement
        params - the parameters or null
        reusePrepared - if the prepared statement can be re-used immediately
        session - 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 class Table
      • truncate

        public long truncate​(SessionLocal session)
        Description copied from class: Table
        Remove all rows from the table and indexes.
        Specified by:
        truncate in class Table
        Parameters:
        session - the session
        Returns:
        number of removed rows, possibly including uncommitted rows
      • canGetRowCount

        public boolean canGetRowCount​(SessionLocal session)
        Description copied from class: Table
        Check if the row count can be retrieved quickly.
        Specified by:
        canGetRowCount in class Table
        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.
        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
      • 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 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
      • 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 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)
      • getRowCountApproximation

        public long getRowCountApproximation​(SessionLocal session)
        Description copied from class: Table
        Get the approximated row count for this table.
        Specified by:
        getRowCountApproximation in class Table
        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 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
      • 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 class Table
        Parameters:
        session - the session
        row - the row
        overridingSystem - Boolean.TRUE for OVERRIDING SYSTEM VALUES, Boolean.FALSE for OVERRIDING 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 class Table
        Parameters:
        session - the session
        row - the row
        fromTrigger - true if row was modified by INSERT or UPDATE trigger
      • 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