Class Db2Connection

java.lang.Object
io.debezium.jdbc.JdbcConnection
io.debezium.connector.db2.Db2Connection
All Implemented Interfaces:
AutoCloseable

public class Db2Connection extends io.debezium.jdbc.JdbcConnection
JdbcConnection extension to be used with IBM Db2
Author:
Horia Chiorean (hchiorea@redhat.com), Jiri Pechanec, Peter Urbanetz
  • Field Details

    • GET_DATABASE_NAME

      private static final String GET_DATABASE_NAME
      See Also:
    • LOGGER

      private static org.slf4j.Logger LOGGER
    • CDC_SCHEMA

      private static final String CDC_SCHEMA
      See Also:
    • STATEMENTS_PLACEHOLDER

      private static final String STATEMENTS_PLACEHOLDER
      See Also:
    • GET_MAX_LSN

      private static final String GET_MAX_LSN
      See Also:
    • LOCK_TABLE

      private static final String LOCK_TABLE
      See Also:
    • LSN_TO_TIMESTAMP

      private static final String LSN_TO_TIMESTAMP
      See Also:
    • GET_ALL_CHANGES_FOR_TABLE

      private static final String GET_ALL_CHANGES_FOR_TABLE
      See Also:
    • GET_LIST_OF_CDC_ENABLED_TABLES

      private static final String GET_LIST_OF_CDC_ENABLED_TABLES
      See Also:
    • GET_LIST_OF_NEW_CDC_ENABLED_TABLES

      private static final String GET_LIST_OF_NEW_CDC_ENABLED_TABLES
      See Also:
    • GET_LIST_OF_KEY_COLUMNS

      private static final String GET_LIST_OF_KEY_COLUMNS
      See Also:
    • CHANGE_TABLE_DATA_COLUMN_OFFSET

      private static final int CHANGE_TABLE_DATA_COLUMN_OFFSET
      See Also:
    • QUOTED_CHARACTER

      private static final String QUOTED_CHARACTER
      See Also:
    • URL_PATTERN

      private static final String URL_PATTERN
    • FACTORY

      private static final io.debezium.jdbc.JdbcConnection.ConnectionFactory FACTORY
    • realDatabaseName

      private final String realDatabaseName
      actual name of the database, which could differ in casing from the database name given in the connector config.
    • lsnToInstantCache

      private final io.debezium.util.BoundedConcurrentHashMap<Lsn,Instant> lsnToInstantCache
  • Constructor Details

    • Db2Connection

      public Db2Connection(io.debezium.jdbc.JdbcConfiguration config)
      Creates a new connection using the supplied configuration.
      Parameters:
      config - Configuration instance, may not be null.
  • Method Details

    • getMaxLsn

      public Lsn getMaxLsn() throws SQLException
      Returns:
      the current largest log sequence number
      Throws:
      SQLException
    • getChangesForTable

      public void getChangesForTable(io.debezium.relational.TableId tableId, Lsn fromLsn, Lsn toLsn, io.debezium.jdbc.JdbcConnection.ResultSetConsumer consumer) throws SQLException
      Provides all changes recorded by the DB2 CDC capture process for a given table.
      Parameters:
      tableId - - the requested table changes
      fromLsn - - closed lower bound of interval of changes to be provided
      toLsn - - closed upper bound of interval of changes to be provided
      consumer - - the change processor
      Throws:
      SQLException
    • getChangesForTables

      public void getChangesForTables(Db2ChangeTable[] changeTables, Lsn intervalFromLsn, Lsn intervalToLsn, io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer consumer) throws SQLException, InterruptedException
      Provides all changes recorder by the DB2 CDC capture process for a set of tables.
      Parameters:
      changeTables - - the requested tables to obtain changes for
      intervalFromLsn - - closed lower bound of interval of changes to be provided
      intervalToLsn - - closed upper bound of interval of changes to be provided
      consumer - - the change processor
      Throws:
      SQLException
      InterruptedException
    • incrementLsn

      public Lsn incrementLsn(Lsn lsn) throws SQLException
      Obtain the next available position in the database log.
      Parameters:
      lsn - - LSN of the current position
      Returns:
      LSN of the next position in the database
      Throws:
      SQLException
    • timestampOfLsn

      public Instant timestampOfLsn(Lsn lsn) throws SQLException
      Map a commit LSN to a point in time when the commit happened.
      Parameters:
      lsn - - LSN of the commit
      Returns:
      time when the commit was recorded into the database log
      Throws:
      SQLException
    • getCurrentTimestamp

      public Optional<Timestamp> getCurrentTimestamp() throws SQLException
      Overrides:
      getCurrentTimestamp in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • lockTable

      public void lockTable(io.debezium.relational.TableId tableId) throws SQLException
      Creates an exclusive lock for a given table.
      Parameters:
      tableId - to be locked
      Throws:
      SQLException
    • cdcNameForTable

      private String cdcNameForTable(io.debezium.relational.TableId tableId)
    • listOfChangeTables

      public Set<Db2ChangeTable> listOfChangeTables() throws SQLException
      Throws:
      SQLException
    • listOfNewChangeTables

      public Set<Db2ChangeTable> listOfNewChangeTables(Lsn fromLsn, Lsn toLsn) throws SQLException
      Throws:
      SQLException
    • getTableSchemaFromTable

      public io.debezium.relational.Table getTableSchemaFromTable(Db2ChangeTable changeTable) throws SQLException
      Throws:
      SQLException
    • getTableSchemaFromChangeTable

      public io.debezium.relational.Table getTableSchemaFromChangeTable(Db2ChangeTable changeTable) throws SQLException
      Throws:
      SQLException
    • getNameOfChangeTable

      public String getNameOfChangeTable(String captureName)
    • getRealDatabaseName

      public String getRealDatabaseName()
    • isTableUniqueIndexIncluded

      protected boolean isTableUniqueIndexIncluded(String indexName, String columnName)
      Overrides:
      isTableUniqueIndexIncluded in class io.debezium.jdbc.JdbcConnection
    • retrieveRealDatabaseName

      private String retrieveRealDatabaseName()
    • connectionString

      public String connectionString()
      Returns a JDBC connection string for the current configuration.
      Returns:
      a String where the variables in urlPattern are replaced with values from the configuration
    • quotedTableIdString

      public String quotedTableIdString(io.debezium.relational.TableId tableId)
      Overrides:
      quotedTableIdString in class io.debezium.jdbc.JdbcConnection
    • prepareQuery

      public io.debezium.jdbc.JdbcConnection prepareQuery(String[] multiQuery, io.debezium.jdbc.JdbcConnection.StatementPreparer[] preparers, io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer resultConsumer) throws SQLException, InterruptedException
      Overrides:
      prepareQuery in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
      InterruptedException
    • prepareQueryWithBlockingConsumer

      public io.debezium.jdbc.JdbcConnection prepareQueryWithBlockingConsumer(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.BlockingResultSetConsumer resultConsumer) throws SQLException, InterruptedException
      Overrides:
      prepareQueryWithBlockingConsumer in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
      InterruptedException
    • prepareQuery

      public io.debezium.jdbc.JdbcConnection prepareQuery(String preparedQueryString) throws SQLException
      Overrides:
      prepareQuery in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • prepareQuery

      public io.debezium.jdbc.JdbcConnection prepareQuery(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.ResultSetConsumer resultConsumer) throws SQLException
      Overrides:
      prepareQuery in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • prepareQueryAndMap

      public <T> T prepareQueryAndMap(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.ResultSetMapper<T> mapper) throws SQLException
      Overrides:
      prepareQueryAndMap in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • prepareUpdate

      public io.debezium.jdbc.JdbcConnection prepareUpdate(String stmt, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer) throws SQLException
      Overrides:
      prepareUpdate in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • prepareQuery

      public io.debezium.jdbc.JdbcConnection prepareQuery(String preparedQueryString, List<?> parameters, io.debezium.jdbc.JdbcConnection.ParameterResultSetConsumer resultConsumer) throws SQLException
      Overrides:
      prepareQuery in class io.debezium.jdbc.JdbcConnection
      Throws:
      SQLException
    • createPreparedStatement

      private PreparedStatement createPreparedStatement(String query)
    • closePreparedStatement

      private void closePreparedStatement(PreparedStatement statement)