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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     

    Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection

    io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer, io.debezium.jdbc.JdbcConnection.BlockingResultSetConsumer, io.debezium.jdbc.JdbcConnection.CallPreparer, io.debezium.jdbc.JdbcConnection.ConnectionFactory, io.debezium.jdbc.JdbcConnection.MultiResultSetConsumer, io.debezium.jdbc.JdbcConnection.Operations, io.debezium.jdbc.JdbcConnection.ParameterResultSetConsumer, io.debezium.jdbc.JdbcConnection.ResultSetConsumer, io.debezium.jdbc.JdbcConnection.ResultSetExtractor<T extends Object>, io.debezium.jdbc.JdbcConnection.ResultSetMapper<T extends Object>, io.debezium.jdbc.JdbcConnection.StatementFactory, io.debezium.jdbc.JdbcConnection.StatementPreparer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
     
    private final Db2ConnectorConfig
     
    private static final io.debezium.jdbc.JdbcConnection.ConnectionFactory
     
    private static final String
     
    private static final String
     
    private static final String
     
    private static org.slf4j.Logger
     
    private static final String
     
    private final io.debezium.util.BoundedConcurrentHashMap<Lsn,Instant>
     
    private final Db2PlatformAdapter
     
    private static final String
     
    private final String
    actual name of the database, which could differ in casing from the database name given in the connector config.
    private static final String
     
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new connection using the supplied configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    cdcNameForTable(io.debezium.relational.TableId tableId)
     
    private void
     
    Returns a JDBC connection string for the current configuration.
     
    io.debezium.relational.TableId
    createTableId(String databaseName, String schemaName, String tableName)
     
    void
    getChangesForTable(io.debezium.relational.TableId tableId, Lsn fromLsn, Lsn toLsn, io.debezium.jdbc.JdbcConnection.ResultSetConsumer consumer)
    Provides all changes recorded by the DB2 CDC capture process for a given table.
    void
    getChangesForTables(Db2ChangeTable[] changeTables, Lsn intervalFromLsn, Lsn intervalToLsn, io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer consumer)
    Provides all changes recorder by the DB2 CDC capture process for a set of tables.
     
     
     
     
    io.debezium.relational.Table
     
    io.debezium.relational.Table
     
    Obtain the next available position in the database log.
    protected boolean
    isTableUniqueIndexIncluded(String indexName, String columnName)
     
     
    listOfNewChangeTables(Lsn fromLsn, Lsn toLsn)
     
    void
    lockTable(io.debezium.relational.TableId tableId)
    Creates an exclusive lock for a given table.
     
    io.debezium.jdbc.JdbcConnection
    prepareQuery(String preparedQueryString)
     
    io.debezium.jdbc.JdbcConnection
    prepareQuery(String[] multiQuery, io.debezium.jdbc.JdbcConnection.StatementPreparer[] preparers, io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer resultConsumer)
     
    io.debezium.jdbc.JdbcConnection
    prepareQuery(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.ResultSetConsumer resultConsumer)
     
    io.debezium.jdbc.JdbcConnection
    prepareQuery(String preparedQueryString, List<?> parameters, io.debezium.jdbc.JdbcConnection.ParameterResultSetConsumer resultConsumer)
     
    <T> T
    prepareQueryAndMap(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.ResultSetMapper<T> mapper)
     
    io.debezium.jdbc.JdbcConnection
    prepareQueryWithBlockingConsumer(String preparedQueryString, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer, io.debezium.jdbc.JdbcConnection.BlockingResultSetConsumer resultConsumer)
     
    io.debezium.jdbc.JdbcConnection
    prepareUpdate(String stmt, io.debezium.jdbc.JdbcConnection.StatementPreparer preparer)
     
    quotedTableIdString(io.debezium.relational.TableId tableId)
     
    private String
     
    <T> T
    singleOptionalValue(String query, io.debezium.jdbc.JdbcConnection.ResultSetExtractor<T> extractor)
     
    Map a commit LSN to a point in time when the commit happened.
    boolean
    validateLogPosition(io.debezium.pipeline.spi.Partition partition, io.debezium.pipeline.spi.OffsetContext offset, io.debezium.config.CommonConnectorConfig config)
     

    Methods inherited from class io.debezium.jdbc.JdbcConnection

    buildSelectWithRowLimits, call, chunkQueryBuilder, close, commit, config, connect, connection, connection, connectionString, database, escapeEscapeSequence, execute, execute, executeWithoutCommitting, getAttributeDetails, getColumnsDetails, getColumnValue, getQualifiedTableName, isConnected, isNullable, isTableType, isValid, loadKeyStore, overrideColumn, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, quotedColumnIdString, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTablePreparedStatement, readTableStatement, readTableUniqueIndices, reselectColumns, reselectColumns, resolveCatalogName, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, setQueryColumnValue, singleResultMapper, supportedTableTypes, tableTypes, username

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GET_DATABASE_NAME

      private static final String GET_DATABASE_NAME
      See Also:
    • LOGGER

      private static org.slf4j.Logger LOGGER
    • STATEMENTS_PLACEHOLDER

      private static final String STATEMENTS_PLACEHOLDER
      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_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
    • connectorConfig

      private final Db2ConnectorConfig connectorConfig
    • platform

      private final Db2PlatformAdapter platform
  • Constructor Details

    • Db2Connection

      public Db2Connection(Db2ConnectorConfig 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<Instant> 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
    • nullsSortLast

      public Optional<Boolean> nullsSortLast()
      Overrides:
      nullsSortLast in class io.debezium.jdbc.JdbcConnection
    • 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
    • createTableId

      public io.debezium.relational.TableId createTableId(String databaseName, String schemaName, String tableName)
      Overrides:
      createTableId in class io.debezium.jdbc.JdbcConnection
    • validateLogPosition

      public boolean validateLogPosition(io.debezium.pipeline.spi.Partition partition, io.debezium.pipeline.spi.OffsetContext offset, io.debezium.config.CommonConnectorConfig config)
    • singleOptionalValue

      public <T> T singleOptionalValue(String query, io.debezium.jdbc.JdbcConnection.ResultSetExtractor<T> extractor) throws SQLException
      Throws:
      SQLException
    • createPreparedStatement

      private PreparedStatement createPreparedStatement(String query)
    • closePreparedStatement

      private void closePreparedStatement(PreparedStatement statement)