Package io.debezium.connector.sqlserver
Class SqlServerConnection
java.lang.Object
io.debezium.jdbc.JdbcConnection
io.debezium.connector.sqlserver.SqlServerConnection
- All Implemented Interfaces:
AutoCloseable
JdbcConnection extension to be used with Microsoft SQL Server- Author:
- Horia Chiorean (hchiorea@redhat.com), Jiri Pechanec
-
Nested Class Summary
Nested ClassesNested 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
FieldsModifier and TypeFieldDescriptionprivate static final Fieldprivate static final Stringprivate final SqlServerConnectorConfigprivate static final Stringprivate final SqlServerDefaultValueConverterprivate final Stringprivate static final Stringprivate static final StringQueries the list of captured column names and their change table identifiers in the given database.private static final StringQueries the list of capture instances in the given database.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate final Stringprivate static final Stringstatic final Stringprivate static final Stringprivate static final org.slf4j.Loggerprotected static final Stringprivate static final Stringprivate booleanprivate final intprivate static final Stringprivate static final Stringprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionSqlServerConnection(SqlServerConnectorConfig config, SqlServerValueConverters valueConverters, Set<Envelope.Operation> skippedOperations, boolean useSingleDatabase) Creates a new connection using the supplied configuration.SqlServerConnection(SqlServerConnectorConfig config, SqlServerValueConverters valueConverters, Set<Envelope.Operation> skippedOperations, boolean useSingleDatabase, boolean optionRecompile) Creates a new connection using the supplied configuration. -
Method Summary
Modifier and TypeMethodDescriptionbuildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, Optional<String> additionalCondition, String orderBy) private StringcdcNameForTable(TableId tableId) booleancheckIfConnectedUserHasAccessToCDCTable(String databaseName) Check if the user with which connection object is created has access to CDC table.connection(boolean executeOnConnect) Returns a JDBC connection string for the current configuration.private static JdbcConnection.ConnectionFactorycreateConnectionFactory(SqlServerJdbcConfiguration config, boolean useSingleDatabase) protected static StringcreateUrlPattern(SqlServerJdbcConfiguration config, boolean useSingleDatabase) 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.getChangeTables(String databaseName) getChangeTables(String databaseName, Lsn toLsn) getColumnValue(ResultSet rs, int columnIndex, Column column, Table table) private LsngetFromLsn(String databaseName, SqlServerChangeTable changeTable, Lsn intervalFromLsn) getMaxTransactionLsn(String databaseName) getNameOfChangeTable(String captureName) getNewChangeTables(String databaseName, Lsn fromLsn, Lsn toLsn) getNthTransactionLsnFromBeginning(String databaseName, int maxOffset) getNthTransactionLsnFromLast(String databaseName, Lsn lastLsn, int maxOffset) getTableSchemaFromTable(String databaseName, SqlServerChangeTable changeTable) private booleanhasSkippedOperations(Set<Envelope.Operation> skippedOperations) incrementLsn(String databaseName, Lsn lsn) Obtain the next available position in the database log.booleanisAgentRunning(String databaseName) protected booleanisTableUniqueIndexIncluded(String indexName, String columnName) voidCreates an exclusive lock for a given table.quotedTableIdString(TableId tableId) private StringreplaceDatabaseNamePlaceholder(String sql, String databaseName) retrieveRealDatabaseName(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
buildReselectColumnQuery, call, close, commit, config, connect, connection, connectionString, createTableId, database, escapeEscapeSequence, execute, execute, executeWithoutCommitting, getAttributeDetails, getColumnsDetails, getQualifiedTableName, isConnected, isNullable, isTableType, isValid, loadKeyStore, overrideColumn, 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, reselectColumns, resolveCatalogName, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, setQueryColumnValue, singleResultMapper, supportedTableTypes, tableTypes, username
-
Field Details
-
INSTANCE_NAME
- See Also:
-
GET_DATABASE_NAME
- See Also:
-
LOGGER
private static final org.slf4j.Logger LOGGER -
STATEMENTS_PLACEHOLDER
- See Also:
-
DATABASE_NAME_PLACEHOLDER
- See Also:
-
GET_MAX_LSN
- See Also:
-
GET_MAX_TRANSACTION_LSN
- See Also:
-
GET_NTH_TRANSACTION_LSN_FROM_BEGINNING
- See Also:
-
GET_NTH_TRANSACTION_LSN_FROM_LAST
- See Also:
-
GET_MIN_LSN
- See Also:
-
LOCK_TABLE
- See Also:
-
INCREMENT_LSN
- See Also:
-
GET_ALL_CHANGES_FOR_TABLE
- See Also:
-
get_all_changes_for_table
-
LSN_TIMESTAMP_SELECT_STATEMENT
- See Also:
-
GET_CAPTURED_COLUMNS
Queries the list of captured column names and their change table identifiers in the given database.- See Also:
-
GET_CHANGE_TABLES
Queries the list of capture instances in the given database. If two or more capture instances with the same start LSN are available for a given source table, only the newest one will be returned. We use a query instead ofsys.sp_cdc_help_change_data_capturebecause: 1. The stored procedure doesn't allow filtering capture instances by start LSN. 2. There is no way to use the result returned by a stored procedure in a query.- See Also:
-
GET_NEW_CHANGE_TABLES
- See Also:
-
OPENING_QUOTING_CHARACTER
- See Also:
-
CLOSING_QUOTING_CHARACTER
- See Also:
-
URL_PATTERN
-
config
-
useSingleDatabase
private final boolean useSingleDatabase -
getAllChangesForTable
-
queryFetchSize
private final int queryFetchSize -
defaultValueConverter
-
optionRecompile
private boolean optionRecompile -
AGENT_STATUS_QUERY
-
-
Constructor Details
-
SqlServerConnection
public SqlServerConnection(SqlServerConnectorConfig config, SqlServerValueConverters valueConverters, Set<Envelope.Operation> skippedOperations, boolean useSingleDatabase) Creates a new connection using the supplied configuration.- Parameters:
config-Configurationinstance, may not be null.valueConverters-SqlServerValueConvertersinstanceskippedOperations- a set ofEnvelope.Operationto skip in streaming
-
SqlServerConnection
public SqlServerConnection(SqlServerConnectorConfig config, SqlServerValueConverters valueConverters, Set<Envelope.Operation> skippedOperations, boolean useSingleDatabase, boolean optionRecompile) Creates a new connection using the supplied configuration.- Parameters:
config-Configurationinstance, may not be null.valueConverters-SqlServerValueConvertersinstanceskippedOperations- a set ofEnvelope.Operationto skip in streamingoptionRecompile- Includes query option RECOMPILE on incremental snapshots
-
-
Method Details
-
hasSkippedOperations
-
createConnectionFactory
private static JdbcConnection.ConnectionFactory createConnectionFactory(SqlServerJdbcConfiguration config, boolean useSingleDatabase) -
createUrlPattern
@VisibleForTesting protected static String createUrlPattern(SqlServerJdbcConfiguration config, boolean useSingleDatabase) -
connectionString
Returns a JDBC connection string for the current configuration.- Returns:
- a
Stringwhere the variables inurlPatternare replaced with values from the configuration
-
connection
- Overrides:
connectionin classJdbcConnection- Throws:
SQLException
-
getMaxLsn
- 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
- Returns:
- the log sequence number of the most recent transaction.
- Throws:
SQLException
-
getMinLsn
- 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
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
-
checkIfConnectedUserHasAccessToCDCTable
Check if the user with which connection object is created has access to CDC table.- Returns:
- boolean indicating the presence/absence of access
- Throws:
SQLException
-
lockTable
Creates an exclusive lock for a given table.- Parameters:
tableId- to be locked- Throws:
SQLException
-
cdcNameForTable
-
getChangeTables
- Throws:
SQLException
-
getChangeTables
public List<SqlServerChangeTable> getChangeTables(String databaseName, Lsn toLsn) throws SQLException - Throws:
SQLException
-
getNewChangeTables
public List<SqlServerChangeTable> getNewChangeTables(String databaseName, Lsn fromLsn, Lsn toLsn) throws SQLException - Throws:
SQLException
-
getTableSchemaFromTable
public Table getTableSchemaFromTable(String databaseName, SqlServerChangeTable changeTable) throws SQLException - Throws:
SQLException
-
getNameOfChangeTable
-
retrieveRealDatabaseName
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. -
isTableUniqueIndexIncluded
- Overrides:
isTableUniqueIndexIncludedin classJdbcConnection
-
getColumnValue
public Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table table) throws SQLException - Overrides:
getColumnValuein classJdbcConnection- Throws:
SQLException
-
buildSelectWithRowLimits
public String buildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, Optional<String> additionalCondition, String orderBy) - Overrides:
buildSelectWithRowLimitsin classJdbcConnection
-
quotedTableIdString
- Overrides:
quotedTableIdStringin classJdbcConnection
-
replaceDatabaseNamePlaceholder
-
getDefaultValueConverter
-
isAgentRunning
- Throws:
SQLException
-
getCurrentTimestamp
- Overrides:
getCurrentTimestampin classJdbcConnection- Throws:
SQLException
-