Class CascadingOrBoundaryConditions
java.lang.Object
io.debezium.pipeline.source.snapshot.CascadingOrBoundaryConditions
Utility methods for building cascading-OR boundary conditions used in chunked SQL queries.
For a composite key (k1, k2, k3), the cascading-OR lower bound pattern is:
(k1 > ?) OR (k1 = ? AND k2 > ?) OR (k1 = ? AND k2 = ? AND k3 op ?)where
op is >= for an inclusive final term or > for exclusive.
The corresponding parameter binding will bind values in a triangular pattern, once per column per OR term, where a 3-column key requires 1+2+3 = 6 parameter slots per boundary.
- Author:
- Chris Cranford
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intbindTriangularParams(PreparedStatement statement, List<Column> columns, Object[] values, int startIndex, JdbcConnection connection) Binds values in the triangular parameter pattern for a cascading-OR boundary condition.static intbindTriangularParamsSkipNulls(PreparedStatement statement, List<Column> columns, Object[] values, int startIndex, JdbcConnection connection) Binds values in the triangular parameter pattern, skippingnullentries.static voidbuildLowerBound(List<String> columnNames, StringBuilder sql, boolean inclusiveFinal) Appends the cascading-OR lower-bound condition for the given (already-quoted) column names.static voidbuildUpperBound(List<String> columnNames, StringBuilder sql, boolean inclusive) Appends the cascading-OR upper-bound condition for the given (already-quoted) column names.
-
Constructor Details
-
CascadingOrBoundaryConditions
private CascadingOrBoundaryConditions()
-
-
Method Details
-
buildLowerBound
public static void buildLowerBound(List<String> columnNames, StringBuilder sql, boolean inclusiveFinal) Appends the cascading-OR lower-bound condition for the given (already-quoted) column names.For a single column:
k1 >= ?ork1 > ?.For multiple columns:
(k1 > ?) OR (k1 = ? AND k2 > ?) OR ... OR (k1 = ? AND ... AND kN op ?).- Parameters:
columnNames- quoted column name strings in key ordersql- target string builderinclusiveFinal-trueto use>=on the final (most-specific) term;falseto use>throughout
-
buildUpperBound
Appends the cascading-OR upper-bound condition for the given (already-quoted) column names.For a single column:
k1 <= ?ork1 < ?.For multiple columns:
(k1 op ?) OR (k1 = ? AND k2 op ?) OR ....- Parameters:
columnNames- quoted column name strings in key ordersql- target string builderinclusive-trueto use<=;falseto use<
-
bindTriangularParams
public static int bindTriangularParams(PreparedStatement statement, List<Column> columns, Object[] values, int startIndex, JdbcConnection connection) throws SQLException Binds values in the triangular parameter pattern for a cascading-OR boundary condition. None of the values may benull.For a 3-column key and
values = [v1, v2, v3], binds in order:v1, v1 v2, v1 v2 v3(six parameters total).- Parameters:
statement- the prepared statement to bind intocolumns- the key columns, in key ordervalues- boundary values, must be non-null and the same length ascolsstartIndex- the 1-based index of the first parameter slot to useconnection- connection used for type-aware binding- Returns:
- the next available (unused) parameter index
- Throws:
SQLException- if binding fails
-
bindTriangularParamsSkipNulls
public static int bindTriangularParamsSkipNulls(PreparedStatement statement, List<Column> columns, Object[] values, int startIndex, JdbcConnection connection) throws SQLException Binds values in the triangular parameter pattern, skippingnullentries.Used when the SQL was generated with
IS NULL/IS NOT NULLliterals for null-valued columns (which require no?placeholder).- Parameters:
statement- the prepared statement to bind intocolumns- the key columns, in key ordervalues- boundary values;nullentries are skippedstartIndex- the 1-based index of the first parameter slot to useconnection- connection used for type-aware binding- Returns:
- the next available (unused) parameter index
- Throws:
SQLException- if binding fails
-