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, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters, Supplier<ClassLoader> classLoaderSupplier, Set<Envelope.Operation> skippedOperations, boolean multiPartitionMode)Creates a new connection using the supplied configuration.
-
Method Summary
All Methods Static 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)Connectionconnection(boolean executeOnConnect)StringconnectionString()Returns a JDBC connection string for the current configuration.private static JdbcConnection.ConnectionFactorycreateConnectionFactory(boolean multiPartitionMode)private static StringcreateUrlPattern(boolean multiPartitionMode)voidgetChangesForTables(String databaseName, 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(String databaseName, SqlServerChangeTable changeTable, Lsn intervalFromLsn)LsngetMaxLsn(String databaseName)LsngetMaxTransactionLsn(String databaseName)LsngetMinLsn(String databaseName, String changeTableName)StringgetNameOfChangeTable(String captureName)LsngetNthTransactionLsnFromBeginning(String databaseName, int maxOffset)LsngetNthTransactionLsnFromLast(String databaseName, Lsn lastLsn, int maxOffset)TablegetTableSchemaFromTable(String databaseName, SqlServerChangeTable changeTable)LsnincrementLsn(String databaseName, Lsn lsn)Obtain the next available position in the database log.protected booleanisTableUniqueIndexIncluded(String indexName, String columnName)Set<SqlServerChangeTable>listOfChangeTables(String databaseName)Set<SqlServerChangeTable>listOfNewChangeTables(String databaseName, Lsn fromLsn, Lsn toLsn)voidlockTable(TableId tableId)Creates an exclusive lock for a given table.StringquotedTableIdString(TableId tableId)private StringreplaceDatabaseNamePlaceholder(String sql, String databaseName)StringretrieveRealDatabaseName(String databaseName)Retrieve the name of the database in the original case as it's defined on the server.-
Methods inherited from class io.debezium.jdbc.JdbcConnection
call, close, commit, config, connect, connection, connectionString, database, execute, execute, executeWithoutCommitting, isConnected, isNullable, isValid, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, quotedColumnIdString, 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
@Deprecated public static final String SERVER_TIMEZONE_PROP_NAME
Deprecated.The connector will determine the database server timezone offset automatically.- 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
-
DATABASE_NAME_PLACEHOLDER
private static final String DATABASE_NAME_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
-
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
-
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
-
BRACKET_PATTERN
private static final Pattern BRACKET_PATTERN
-
OPENING_QUOTING_CHARACTER
private static final String OPENING_QUOTING_CHARACTER
- See Also:
- Constant Field Values
-
CLOSING_QUOTING_CHARACTER
private static final String CLOSING_QUOTING_CHARACTER
- See Also:
- Constant Field Values
-
URL_PATTERN
private static final String URL_PATTERN
-
multiPartitionMode
private final boolean multiPartitionMode
-
getAllChangesForTable
private final String getAllChangesForTable
-
queryFetchSize
private final int queryFetchSize
-
defaultValueConverter
private final SqlServerDefaultValueConverter defaultValueConverter
-
-
Constructor Detail
-
SqlServerConnection
public SqlServerConnection(Configuration config, SourceTimestampMode sourceTimestampMode, SqlServerValueConverters valueConverters, Supplier<ClassLoader> classLoaderSupplier, Set<Envelope.Operation> skippedOperations, boolean multiPartitionMode)
Creates a new connection using the supplied configuration.- Parameters:
config-Configurationinstance, may not be null.sourceTimestampMode- strategy for populatingsource.ts_ms.valueConverters-SqlServerValueConvertersinstanceclassLoaderSupplier- class loader supplierskippedOperations- a set ofEnvelope.Operationto skip in streaming
-
-
Method Detail
-
createUrlPattern
private static String createUrlPattern(boolean multiPartitionMode)
-
createConnectionFactory
private static JdbcConnection.ConnectionFactory createConnectionFactory(boolean multiPartitionMode)
-
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
-
connection
public Connection connection(boolean executeOnConnect) throws SQLException
- Overrides:
connectionin classJdbcConnection- Throws:
SQLException
-
getMaxLsn
public Lsn getMaxLsn(String databaseName) throws SQLException
- Returns:
- the current largest log sequence number
- Throws:
SQLException
-
getNthTransactionLsnFromBeginning
public Lsn getNthTransactionLsnFromBeginning(String databaseName, 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(String databaseName, 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(String databaseName) throws SQLException
- Returns:
- the log sequence number of the most recent transaction.
- Throws:
SQLException
-
getMinLsn
public Lsn getMinLsn(String databaseName, String changeTableName) throws SQLException
- Returns:
- the smallest log sequence number of table
- Throws:
SQLException
-
getChangesForTables
public void getChangesForTables(String databaseName, 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:
databaseName- - the name of the database to querychangeTables- - 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(String databaseName, SqlServerChangeTable changeTable, Lsn intervalFromLsn) throws SQLException
- Throws:
SQLException
-
incrementLsn
public Lsn incrementLsn(String databaseName, Lsn lsn) throws SQLException
Obtain the next available position in the database log.- Parameters:
databaseName- - the name of the database that the LSN belongs tolsn- - 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(String databaseName) throws SQLException
- Throws:
SQLException
-
listOfNewChangeTables
public Set<SqlServerChangeTable> listOfNewChangeTables(String databaseName, Lsn fromLsn, Lsn toLsn) throws SQLException
- Throws:
SQLException
-
getTableSchemaFromTable
public Table getTableSchemaFromTable(String databaseName, SqlServerChangeTable changeTable) throws SQLException
- Throws:
SQLException
-
retrieveRealDatabaseName
public String retrieveRealDatabaseName(String databaseName)
Retrieve the name of the database in the original case as it's defined on the server. Although SQL Server supports case-insensitive collations, the connector uses the database name to build the produced records' source info and, subsequently, the keys of its committed offset messages. This value must remain the same during the lifetime of the connector regardless of the case used in the connector configuration.
-
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
-
-