Package st.orm

Interface Operator


public interface Operator
Represents a comparison operator in a SQL query.

Caching contract: Operators may participate in template caching where the operator instance becomes part of the cache key for a compiled SQL shape. Custom operator implementations must therefore implement stable Object.equals(Object) and Object.hashCode() semantics. Two operators must be considered equal (and have the same hash code) if they produce the same SQL shape, so that equivalent templates map to the same cached compilation result.

  • Field Details

    • IN

      static final Operator IN
      The IN operator.
    • NOT_IN

      static final Operator NOT_IN
      The NOT IN operator.
    • EQUALS

      static final Operator EQUALS
      The = operator.
    • NOT_EQUALS

      static final Operator NOT_EQUALS
      The <> operator.
    • LIKE

      static final Operator LIKE
      The LIKE operator.
    • NOT_LIKE

      static final Operator NOT_LIKE
      The NOT LIKE operator.
    • CONTAINS

      static final Operator CONTAINS
      Matches a column that contains the given text anywhere in its value.

      The value is literal text rather than a pattern: Storm escapes the characters the database reads as wildcards, adds the wildcards itself and renders column LIKE ? ESCAPE '!', so 50% matches exactly 50% on every database. Empty text matches every non-null value. Case sensitivity follows the column's collation, as it does for LIKE. The operator applies to a single column holding text.

      Since:
      1.15
    • NOT_CONTAINS

      static final Operator NOT_CONTAINS
      Matches a column that does not contain the given text, the negation of CONTAINS.
      Since:
      1.15
    • STARTS_WITH

      static final Operator STARTS_WITH
      Matches a column whose value starts with the given text. The value is literal text, as for CONTAINS.
      Since:
      1.15
    • NOT_STARTS_WITH

      static final Operator NOT_STARTS_WITH
      Matches a column whose value does not start with the given text, the negation of STARTS_WITH.
      Since:
      1.15
    • ENDS_WITH

      static final Operator ENDS_WITH
      Matches a column whose value ends with the given text. The value is literal text, as for CONTAINS.
      Since:
      1.15
    • NOT_ENDS_WITH

      static final Operator NOT_ENDS_WITH
      Matches a column whose value does not end with the given text, the negation of ENDS_WITH.
      Since:
      1.15
    • EQUALS_IGNORE_CASE

      static final Operator EQUALS_IGNORE_CASE
      Matches a column whose value equals the given text, ignoring case.

      The column and the value are both lowered by the database, LOWER(column) = LOWER(?), so the comparison ignores case on every database, whatever the column's collation. It ignores case and nothing else: accents are compared as they are, and a database lowers the letters it knows, which on SQLite without ICU are the ASCII letters. A plain index on the column does not serve the lowered comparison; index the lowered expression where it must be served by one, and use EQUALS on a column whose collation ignores case already. The operator applies to a single column holding text.

      Since:
      1.15
    • NOT_EQUALS_IGNORE_CASE

      static final Operator NOT_EQUALS_IGNORE_CASE
      Matches a column whose value does not equal the given text, ignoring case, the negation of EQUALS_IGNORE_CASE.
      Since:
      1.15
    • CONTAINS_IGNORE_CASE

      static final Operator CONTAINS_IGNORE_CASE
      Matches a column that contains the given text anywhere in its value, ignoring case.

      The value is literal text, as for CONTAINS, and the column and the pattern are both lowered by the database: LOWER(column) LIKE LOWER(?) ESCAPE '!'. The comparison ignores case on every database, whatever the column's collation, and nothing else, as EQUALS_IGNORE_CASE describes.

      Since:
      1.15
    • NOT_CONTAINS_IGNORE_CASE

      static final Operator NOT_CONTAINS_IGNORE_CASE
      Matches a column that does not contain the given text, ignoring case, the negation of CONTAINS_IGNORE_CASE.
      Since:
      1.15
    • STARTS_WITH_IGNORE_CASE

      static final Operator STARTS_WITH_IGNORE_CASE
      Matches a column whose value starts with the given text, ignoring case, as CONTAINS_IGNORE_CASE matches it anywhere.
      Since:
      1.15
    • NOT_STARTS_WITH_IGNORE_CASE

      static final Operator NOT_STARTS_WITH_IGNORE_CASE
      Matches a column whose value does not start with the given text, ignoring case, the negation of STARTS_WITH_IGNORE_CASE.
      Since:
      1.15
    • ENDS_WITH_IGNORE_CASE

      static final Operator ENDS_WITH_IGNORE_CASE
      Matches a column whose value ends with the given text, ignoring case, as CONTAINS_IGNORE_CASE matches it anywhere.
      Since:
      1.15
    • NOT_ENDS_WITH_IGNORE_CASE

      static final Operator NOT_ENDS_WITH_IGNORE_CASE
      Matches a column whose value does not end with the given text, ignoring case, the negation of ENDS_WITH_IGNORE_CASE.
      Since:
      1.15
    • GREATER_THAN

      static final Operator GREATER_THAN
      The > operator.
    • GREATER_THAN_OR_EQUAL

      static final Operator GREATER_THAN_OR_EQUAL
      The >= operator.
    • LESS_THAN

      static final Operator LESS_THAN
      The < operator.
    • LESS_THAN_OR_EQUAL

      static final Operator LESS_THAN_OR_EQUAL
      The <= operator.
    • BETWEEN

      static final Operator BETWEEN
      The BETWEEN operator.
    • IS_TRUE

      static final Operator IS_TRUE
      The IS TRUE operator.
    • IS_FALSE

      static final Operator IS_FALSE
      The IS FALSE operator.
    • IS_NULL

      static final Operator IS_NULL
      The IS NULL operator.
    • IS_NOT_NULL

      static final Operator IS_NOT_NULL
      The IS NOT NULL operator.
  • Method Details

    • format

      String format(@Nullable String column, String... placeholders)
      Formats the operator with bind variables matching the specified size.
      Parameters:
      column - the column to compare.
      placeholders - the placeholders to use in the template.
      Returns:
      the formatted operator.
      Throws:
      IllegalArgumentException - if the column is null but required by the operator, or if the number of placeholders is not supported by the operator.