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 Details

    • MAX_RETRY

      private static final int MAX_RETRY
      See Also:
    • ROW_COUNT_APPROXIMATION

      private static final long ROW_COUNT_APPROXIMATION
      See Also:
    • originalSchema

      private final String originalSchema
    • driver

      private String driver
    • url

      private String url
    • user

      private String user
    • password

      private String password
    • originalTable

      private String originalTable
    • qualifiedTableName

      private String qualifiedTableName
    • conn

      private TableLinkConnection conn
    • preparedMap

      private HashMap<String,PreparedStatement> preparedMap
    • indexes

      private final 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 Details

  • Method Details

    • connect

      private void connect()
    • readMetaData

      private void readMetaData() throws SQLException
      Throws:
      SQLException
    • readIndexes

      private void readIndexes(DatabaseMetaData meta, HashMap<String,Column> columnMap)
    • readPrimaryKey

      private String readPrimaryKey(ResultSet rs, HashMap<String,Column> columnMap) throws SQLException
      Throws:
      SQLException
    • readIndexes

      private void readIndexes(ResultSet rs, HashMap<String,Column> columnMap, String pkName) throws SQLException
      Throws:
      SQLException
    • convertPrecision

      private static long convertPrecision(int sqlType, long precision)
    • convertScale

      private static int convertScale(int sqlType, int scale)
    • convertColumnName

      private String convertColumnName(String columnName)
    • addIndex

      private void addIndex(List<Column> list, int uniqueColumnCount, IndexType indexType)
    • getDropSQL

      public 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 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, String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, 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(String sql, 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 String getQualifiedTable()
    • execute

      public PreparedStatement execute(String sql, 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(String url)
    • getIndexes

      public 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(PreparedStatement prep, 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, 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
    • 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