Search in sources :

Example 1 with ChangeKey

use of com.github.jcustenborder.kafka.connect.cdc.ChangeKey in project kafka-connect-cdc-mssql by jcustenborder.

the class QueryService method changeKey.

ChangeKey changeKey(String changeTrackingTable) {
    Matcher matcher = CHANGE_TRACKING_TABLE_PATTERN.matcher(changeTrackingTable);
    Preconditions.checkState(matcher.matches(), "'%s' is not formatted in properly. Use 'schemaName.databaseName.tableName'.", changeTrackingTable);
    String schemaName = matcher.group(1);
    String tableName = matcher.group(2);
    return new ChangeKey(this.config.initialDatabase, schemaName, tableName);
}
Also used : ChangeKey(com.github.jcustenborder.kafka.connect.cdc.ChangeKey) Matcher(java.util.regex.Matcher)

Example 2 with ChangeKey

use of com.github.jcustenborder.kafka.connect.cdc.ChangeKey in project kafka-connect-cdc-mssql by jcustenborder.

the class QueryService method processTables.

void processTables() throws SQLException {
    for (String changeTrackingTable : Iterables.cycle(this.config.changeTrackingTables)) {
        if (!isRunning()) {
            break;
        }
        rateLimiter.acquire();
        ChangeKey changeKey;
        try {
            changeKey = changeKey(changeTrackingTable);
        } catch (Exception ex) {
            log.error("Exception thrown while parsing table name '{}'", changeTrackingTable, ex);
            continue;
        }
        try {
            queryTable(this.changeWriter, changeKey);
        } catch (Exception ex) {
            log.error("Exception thrown while querying for {}", changeKey, ex);
        }
    }
}
Also used : ChangeKey(com.github.jcustenborder.kafka.connect.cdc.ChangeKey) SQLException(java.sql.SQLException)

Example 3 with ChangeKey

use of com.github.jcustenborder.kafka.connect.cdc.ChangeKey in project kafka-connect-cdc-mssql by jcustenborder.

the class MsSqlTableMetadataProviderIT method tableMetadata.

private void tableMetadata(MsSqlTableMetadataProviderTestData data) throws SQLException {
    assertNotNull(data, "data should not be null.");
    TableMetadataProvider.TableMetadata actual = this.tableMetadataProvider.tableMetadata(new ChangeKey(data.databaseName(), data.schemaName(), data.tableName()));
    assertTableMetadata(data.expected(), actual);
}
Also used : ChangeKey(com.github.jcustenborder.kafka.connect.cdc.ChangeKey) TableMetadataProvider(com.github.jcustenborder.kafka.connect.cdc.TableMetadataProvider)

Example 4 with ChangeKey

use of com.github.jcustenborder.kafka.connect.cdc.ChangeKey in project kafka-connect-cdc-mssql by jcustenborder.

the class QueryServiceIT method queryTable.

@TestFactory
public Stream<DynamicTest> queryTable() throws SQLException {
    List<ChangeKey> changeCaptureTables = new ArrayList<>();
    PooledConnection pooledConnection = null;
    try {
        pooledConnection = JdbcUtils.openPooledConnection(this.config, new ChangeKey(MsSqlTestConstants.DATABASE_NAME, null, null));
        MsSqlQueryBuilder queryBuilder = new MsSqlQueryBuilder(pooledConnection.getConnection());
        try (PreparedStatement statement = queryBuilder.listChangeTrackingTablesStatement()) {
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    String databaseName = resultSet.getString("databaseName");
                    String schemaName = resultSet.getString("schemaName");
                    String tableName = resultSet.getString("tableName");
                    ChangeKey changeKey = new ChangeKey(databaseName, schemaName, tableName);
                    changeCaptureTables.add(changeKey);
                    log.trace("Found Change Tracking Enabled Table {}", changeKey);
                }
            }
        }
    } finally {
        JdbcUtils.closeConnection(pooledConnection);
    }
    return changeCaptureTables.stream().map(data -> dynamicTest(data.tableName, () -> queryTable(data)));
}
Also used : ChangeKey(com.github.jcustenborder.kafka.connect.cdc.ChangeKey) PooledConnection(javax.sql.PooledConnection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TestFactory(org.junit.jupiter.api.TestFactory)

Aggregations

ChangeKey (com.github.jcustenborder.kafka.connect.cdc.ChangeKey)4 TableMetadataProvider (com.github.jcustenborder.kafka.connect.cdc.TableMetadataProvider)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PooledConnection (javax.sql.PooledConnection)1 TestFactory (org.junit.jupiter.api.TestFactory)1