DBZ-7359 incorporate 1st set of review feedback

This commit is contained in:
Ciaran O'Reilly 2024-02-02 20:11:03 +00:00 committed by Jiri Pechanec
parent 1070e5f505
commit d8c323a520
2 changed files with 27 additions and 27 deletions

View File

@ -612,8 +612,6 @@ public Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table
// NOTE: fix for DBZ-7359
@Override
public void setQueryColumnValue(PreparedStatement statement, Column column, int pos, Object value) throws SQLException {
boolean isColumnValueSet = false;
if (column.typeUsesCharset()) {
// For mappings between sqlserver and JDBC types see -
// https://learn.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver16
@ -626,40 +624,49 @@ public void setQueryColumnValue(PreparedStatement statement, Column column, int
case Types.NCHAR:
if (value instanceof String) {
statement.setNString(pos, (String) value);
isColumnValueSet = true;
}
else {
// not set, fall back on default implementation.
super.setQueryColumnValue(statement, column, pos, value);
}
break;
case Types.NVARCHAR:
if (value instanceof String) {
statement.setNCharacterStream(pos, new StringReader((String) value));
isColumnValueSet = true;
}
else if (value instanceof Reader) {
statement.setNCharacterStream(pos, (Reader) value);
isColumnValueSet = true;
}
else {
// not set, fall back on default implementation.
super.setQueryColumnValue(statement, column, pos, value);
}
break;
case Types.LONGNVARCHAR:
if (value instanceof String) {
// we'll fall back on nvarchar handling
statement.setNCharacterStream(pos, new StringReader((String) value));
isColumnValueSet = true;
}
else if (value instanceof Reader) {
// we'll fall back on nvarchar handling
statement.setNCharacterStream(pos, (Reader) value);
isColumnValueSet = true;
}
else if (value instanceof NClob) {
statement.setNClob(pos, (NClob) value);
isColumnValueSet = true;
}
else {
// not set, fall back on default implementation.
super.setQueryColumnValue(statement, column, pos, value);
}
break;
default:
// not set, fall back on default implementation.
super.setQueryColumnValue(statement, column, pos, value);
break;
}
}
// If not set, fall back on default implementation.
if (!isColumnValueSet) {
else {
// not set, fall back on default implementation.
super.setQueryColumnValue(statement, column, pos, value);
}
}

View File

@ -7,15 +7,12 @@
import static org.assertj.core.api.Assertions.assertThat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@ -32,6 +29,7 @@
import io.debezium.connector.sqlserver.util.TestHelper;
import io.debezium.jdbc.JdbcConnection;
import io.debezium.pipeline.source.snapshot.incremental.AbstractSnapshotTest;
import io.debezium.util.IoUtil;
import io.debezium.util.Testing;
/**
@ -52,18 +50,13 @@ public class IncrementalSnapshotCollationSortOrderMismatchIT extends AbstractSna
@BeforeClass
public static void beforeClass() throws IOException {
try (InputStreamReader isr = new InputStreamReader(
Objects.requireNonNull(IncrementalSnapshotCollationSortOrderMismatchIT.class.getClassLoader().getResourceAsStream("dbz-7359-ids.txt")))) {
try (BufferedReader reader = new BufferedReader(isr)) {
String line;
while ((line = reader.readLine()) != null) {
ALL_IDS.add(line);
}
}
IoUtil.readLines("dbz-7359-ids.txt",
IncrementalSnapshotCollationSortOrderMismatchIT.class.getClassLoader(),
IncrementalSnapshotCollationSortOrderMismatchIT.class,
ALL_IDS::add);
// Of the IDS loaded, the 36 records with ids between Y-11-3-4 and Y1-01-1-1 exclusive, would be consistently skipped.
SKIPPED_IDS.addAll(ALL_IDS.subList(ALL_IDS.indexOf("Y-11-3-4") + 1, ALL_IDS.indexOf("Y1-01-1-1")));
}
}
//
// PK CHAR
@ -152,7 +145,7 @@ record -> ((Struct) record.value()).getStruct("after").getInt32(valueFieldName()
var val = dbChanges.get(id);
if (val == null || val != i) {
result = false;
System.err.println(ALL_IDS.get(i) + " value is not = " + i + ", is = " + val);
Testing.printError(ALL_IDS.get(i) + " value is not = " + i + ", is = " + val);
break;
}
}
@ -182,7 +175,7 @@ record -> ((Struct) record.value()).getStruct("after").getString(valueFieldName(
var val = dbChanges.get(ALL_IDS.get(i));
if (!expectedVal.equals(val)) {
result = false;
System.err.println(ALL_IDS.get(i) + " value is not = " + expectedVal + ", is = " + val);
Testing.printError(ALL_IDS.get(i) + " value is not = " + expectedVal + ", is = " + val);
break;
}
}