Package io.debezium.connector.sqlserver
Class SqlServerConnection
- java.lang.Object
-
- io.debezium.jdbc.JdbcConnection
-
- io.debezium.connector.sqlserver.SqlServerConnection
-
- All Implemented Interfaces:
AutoCloseable
public class SqlServerConnection extends JdbcConnection
JdbcConnectionextension to be used with Microsoft SQL Server- Author:
- Horia Chiorean (hchiorea@redhat.com), Jiri Pechanec
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSqlServerConnection.CdcEnabledTable-
Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetExtractor<T extends Object>, JdbcConnection.ResultSetMapper<T extends Object>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description SqlServerConnection(Configuration config, Clock clock, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters)Creates a new connection using the supplied configuration.SqlServerConnection(Configuration config, Clock clock, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters, Supplier<ClassLoader> classLoaderSupplier, Set<Envelope.Operation> skippedOperations)Creates a new connection using the supplied configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, String orderBy)private StringcdcNameForTable(TableId tableId)StringconnectionString()Returns a JDBC connection string for the current configuration.voidgetChangesForTable(TableId tableId, Lsn fromLsn, Lsn toLsn, JdbcConnection.ResultSetConsumer consumer)Provides all changes recorded by the SQL Server CDC capture process for a given table.voidgetChangesForTables(SqlServerChangeTable[] changeTables, Lsn intervalFromLsn, Lsn intervalToLsn, JdbcConnection.BlockingMultiResultSetConsumer consumer)Provides all changes recorder by the SQL Server CDC capture process for a set of tables.<T extends DatabaseSchema<TableId>>
ObjectgetColumnValue(ResultSet rs, int columnIndex, Column column, Table table, T schema)protected Optional<Object>getDefaultValue(Column column, String defaultValue)private LsngetFromLsn(SqlServerChangeTable changeTable, Lsn intervalFromLsn)LsngetMaxLsn()LsngetMaxTransactionLsn()LsngetMinLsn(String changeTableName)StringgetNameOfChangeTable(String captureName)LsngetNthTransactionLsnFromBeginning(int maxOffset)LsngetNthTransactionLsnFromLast(Lsn lastLsn, int maxOffset)StringgetRealDatabaseName()private Optional<Integer>getSqlServerVersion()TablegetTableSchemaFromChangeTable(SqlServerChangeTable changeTable)TablegetTableSchemaFromTable(SqlServerChangeTable changeTable)LsnincrementLsn(Lsn lsn)Obtain the next available position in the database log.protected booleanisTableUniqueIndexIncluded(String indexName, String columnName)Set<SqlServerChangeTable>listOfChangeTables()Set<SqlServerChangeTable>listOfNewChangeTables(Lsn fromLsn, Lsn toLsn)voidlockTable(TableId tableId)Creates an exclusive lock for a given table.protected Instantnormalize(Timestamp timestamp)StringquotedTableIdString(TableId tableId)private StringretrieveRealDatabaseName()private ZoneIdretrieveTransactionTimezone(boolean supportsAtTimeZone)private booleansupportsAtTimeZone()SELECT ...-
Methods inherited from class io.debezium.jdbc.JdbcConnection
call, close, commit, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, isConnected, isNullable, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTablePreparedStatement, readTableStatement, readTableUniqueIndices, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, singleResultMapper, tableTypes, username
-
-
-
-
Field Detail
-
SERVER_TIMEZONE_PROP_NAME
public static final String SERVER_TIMEZONE_PROP_NAME
- See Also:
- Constant Field Values
-
INSTANCE_NAME
public static final String INSTANCE_NAME
- See Also:
- Constant Field Values
-
GET_DATABASE_NAME
private static final String GET_DATABASE_NAME
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
STATEMENTS_PLACEHOLDER
private static final String STATEMENTS_PLACEHOLDER
- See Also:
- Constant Field Values
-
GET_MAX_LSN
private static final String GET_MAX_LSN
- See Also:
- Constant Field Values
-
GET_MAX_TRANSACTION_LSN
private static final String GET_MAX_TRANSACTION_LSN
- See Also:
- Constant Field Values
-
GET_NTH_TRANSACTION_LSN_FROM_BEGINNING
private static final String GET_NTH_TRANSACTION_LSN_FROM_BEGINNING
- See Also:
- Constant Field Values
-
GET_NTH_TRANSACTION_LSN_FROM_LAST
private static final String GET_NTH_TRANSACTION_LSN_FROM_LAST
- See Also:
- Constant Field Values
-
GET_MIN_LSN
private static final String GET_MIN_LSN
- See Also:
- Constant Field Values
-
LOCK_TABLE
private static final String LOCK_TABLE
- See Also:
- Constant Field Values
-
SQL_SERVER_VERSION
private static final String SQL_SERVER_VERSION
- See Also:
- Constant Field Values
-
INCREMENT_LSN
private static final String INCREMENT_LSN
- See Also:
- Constant Field Values
-
GET_ALL_CHANGES_FOR_TABLE
private static final String GET_ALL_CHANGES_FOR_TABLE
- See Also:
- Constant Field Values
-
get_all_changes_for_table
private final String get_all_changes_for_table
-
LSN_TIMESTAMP_SELECT_STATEMENT
protected static final String LSN_TIMESTAMP_SELECT_STATEMENT
- See Also:
- Constant Field Values
-
AT_TIME_ZONE_UTC
protected static final String AT_TIME_ZONE_UTC
- See Also:
- Constant Field Values
-
GET_LIST_OF_CDC_ENABLED_TABLES
private static final String GET_LIST_OF_CDC_ENABLED_TABLES
- See Also:
- Constant Field Values
-
GET_LIST_OF_NEW_CDC_ENABLED_TABLES
private static final String GET_LIST_OF_NEW_CDC_ENABLED_TABLES
- See Also:
- Constant Field Values
-
GET_LIST_OF_KEY_COLUMNS
private static final String GET_LIST_OF_KEY_COLUMNS
- See Also:
- Constant Field Values
-
BRACKET_PATTERN
private static final Pattern BRACKET_PATTERN
-
CHANGE_TABLE_DATA_COLUMN_OFFSET
private static final int CHANGE_TABLE_DATA_COLUMN_OFFSET
- See Also:
- Constant Field Values
-
URL_PATTERN
private static final String URL_PATTERN
-
FACTORY
private static final 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.
-
transactionTimezone
private final ZoneId transactionTimezone
-
getAllChangesForTable
private final String getAllChangesForTable
-
queryFetchSize
private final int queryFetchSize
-
defaultValueConverter
private final SqlServerDefaultValueConverter defaultValueConverter
-
-
Constructor Detail
-
SqlServerConnection
public SqlServerConnection(Configuration config, Clock clock, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters)
Creates a new connection using the supplied configuration.- Parameters:
config-Configurationinstance, may not be null.clock- the clocksourceTimestampMode- strategy for populatingsource.ts_ms.valueConverters-SqlServerValueConvertersinstance
-
SqlServerConnection
public SqlServerConnection(Configuration config, Clock clock, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters, Supplier<ClassLoader> classLoaderSupplier, Set<Envelope.Operation> skippedOperations)
Creates a new connection using the supplied configuration.- Parameters:
config-Configurationinstance, may not be null.clock- the clocksourceTimestampMode- strategy for populatingsource.ts_ms.valueConverters-SqlServerValueConvertersinstanceclassLoaderSupplier- class loader supplierskippedOperations- a set ofEnvelope.Operationto skip in streaming
-
-
Method Detail
-
connectionString
public String connectionString()
Returns a JDBC connection string for the current configuration.- Returns:
- a
Stringwhere the variables inurlPatternare replaced with values from the configuration
-
getMaxLsn
public Lsn getMaxLsn() throws SQLException
- Returns:
- the current largest log sequence number
- Throws:
SQLException
-
getNthTransactionLsnFromBeginning
public Lsn getNthTransactionLsnFromBeginning(int maxOffset) throws SQLException
- Returns:
- the log sequence number of the most recent transaction
that isn't further than
maxOffsetfrom the beginning. - Throws:
SQLException
-
getNthTransactionLsnFromLast
public Lsn getNthTransactionLsnFromLast(Lsn lastLsn, int maxOffset) throws SQLException
- Returns:
- the log sequence number of the most recent transaction
that isn't further than
maxOffsetfromlastLsn. - Throws:
SQLException
-
getMaxTransactionLsn
public Lsn getMaxTransactionLsn() throws SQLException
- Returns:
- the log sequence number of the most recent transaction.
- Throws:
SQLException
-
getMinLsn
public Lsn getMinLsn(String changeTableName) throws SQLException
- Returns:
- the smallest log sequence number of table
- Throws:
SQLException
-
getChangesForTable
public void getChangesForTable(TableId tableId, Lsn fromLsn, Lsn toLsn, JdbcConnection.ResultSetConsumer consumer) throws SQLException
Provides all changes recorded by the SQL Server CDC capture process for a given table.- Parameters:
tableId- - the requested table changesfromLsn- - closed lower bound of interval of changes to be providedtoLsn- - closed upper bound of interval of changes to be providedconsumer- - the change processor- Throws:
SQLException
-
getChangesForTables
public void getChangesForTables(SqlServerChangeTable[] changeTables, Lsn intervalFromLsn, Lsn intervalToLsn, JdbcConnection.BlockingMultiResultSetConsumer consumer) throws SQLException, InterruptedException
Provides all changes recorder by the SQL Server CDC capture process for a set of tables.- Parameters:
changeTables- - the requested tables to obtain changes forintervalFromLsn- - closed lower bound of interval of changes to be providedintervalToLsn- - closed upper bound of interval of changes to be providedconsumer- - the change processor- Throws:
SQLExceptionInterruptedException
-
getFromLsn
private Lsn getFromLsn(SqlServerChangeTable changeTable, Lsn intervalFromLsn) throws SQLException
- Throws:
SQLException
-
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
-
lockTable
public void lockTable(TableId tableId) throws SQLException
Creates an exclusive lock for a given table.- Parameters:
tableId- to be locked- Throws:
SQLException
-
listOfChangeTables
public Set<SqlServerChangeTable> listOfChangeTables() throws SQLException
- Throws:
SQLException
-
listOfNewChangeTables
public Set<SqlServerChangeTable> listOfNewChangeTables(Lsn fromLsn, Lsn toLsn) throws SQLException
- Throws:
SQLException
-
getTableSchemaFromTable
public Table getTableSchemaFromTable(SqlServerChangeTable changeTable) throws SQLException
- Throws:
SQLException
-
getTableSchemaFromChangeTable
public Table getTableSchemaFromChangeTable(SqlServerChangeTable changeTable) throws SQLException
- Throws:
SQLException
-
getRealDatabaseName
public String getRealDatabaseName()
-
retrieveTransactionTimezone
private ZoneId retrieveTransactionTimezone(boolean supportsAtTimeZone)
-
retrieveRealDatabaseName
private String retrieveRealDatabaseName()
-
supportsAtTimeZone
private boolean supportsAtTimeZone()
SELECT ... AT TIME ZONE only works on SQL Server 2016 and newer.
-
getDefaultValue
protected Optional<Object> getDefaultValue(Column column, String defaultValue)
- Overrides:
getDefaultValuein classJdbcConnection
-
isTableUniqueIndexIncluded
protected boolean isTableUniqueIndexIncluded(String indexName, String columnName)
- Overrides:
isTableUniqueIndexIncludedin classJdbcConnection
-
getColumnValue
public <T extends DatabaseSchema<TableId>> Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table table, T schema) throws SQLException
- Overrides:
getColumnValuein classJdbcConnection- Throws:
SQLException
-
buildSelectWithRowLimits
public String buildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, String orderBy)
- Overrides:
buildSelectWithRowLimitsin classJdbcConnection
-
quotedTableIdString
public String quotedTableIdString(TableId tableId)
- Overrides:
quotedTableIdStringin classJdbcConnection
-
-