Class CascadingOrBoundaryConditions

java.lang.Object
io.debezium.pipeline.source.snapshot.CascadingOrBoundaryConditions

public final class CascadingOrBoundaryConditions extends Object
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 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 >= ? or k1 > ?.

      For multiple columns: (k1 > ?) OR (k1 = ? AND k2 > ?) OR ... OR (k1 = ? AND ... AND kN op ?).

      Parameters:
      columnNames - quoted column name strings in key order
      sql - target string builder
      inclusiveFinal - true to use >= on the final (most-specific) term; false to use > throughout
    • buildUpperBound

      public static void buildUpperBound(List<String> columnNames, StringBuilder sql, boolean inclusive)
      Appends the cascading-OR upper-bound condition for the given (already-quoted) column names.

      For a single column: k1 <= ? or k1 < ?.

      For multiple columns: (k1 op ?) OR (k1 = ? AND k2 op ?) OR ....

      Parameters:
      columnNames - quoted column name strings in key order
      sql - target string builder
      inclusive - true to use <=; false to 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 be null.

      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 into
      columns - the key columns, in key order
      values - boundary values, must be non-null and the same length as cols
      startIndex - the 1-based index of the first parameter slot to use
      connection - 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, skipping null entries.

      Used when the SQL was generated with IS NULL / IS NOT NULL literals for null-valued columns (which require no ? placeholder).

      Parameters:
      statement - the prepared statement to bind into
      columns - the key columns, in key order
      values - boundary values; null entries are skipped
      startIndex - the 1-based index of the first parameter slot to use
      connection - connection used for type-aware binding
      Returns:
      the next available (unused) parameter index
      Throws:
      SQLException - if binding fails