Class SqlContainsPolicyDecorator

java.lang.Object
de.calamanari.adl.sql.config.SqlContainsPolicyDecorator
All Implemented Interfaces:
SqlContainsPolicy, Serializable

public class SqlContainsPolicyDecorator extends Object implements SqlContainsPolicy
An SqlContainsPolicyDecorator allows to quickly create a new policy by decorating a given one with a different behavioral aspect.
Author:
Karl Eilebrecht
See Also:
  • Method Details

    • prepareSearchSnippet

      public String prepareSearchSnippet(String value)
      Description copied from interface: SqlContainsPolicy
      This method allows to modify the snippet to conform to a specific database.

      E.g., given as a prepared statement parameter one would assume that further percentage signs or underscores in the snippet would be escaped by the driver. However, some databases interpret them as further wildcards.

      This method allows intercepting the snippet preparation (e.g., remove such problematic characters).

      Important:
      The return value of this method is still a text snippet and not yet the SQL-pattern to be included in the statement.
      So, typically, you should NOT surround the text here with percentage signs but. Otherwise the driver will most likely escape them and this way destroy the search pattern.

      Specified by:
      prepareSearchSnippet in interface SqlContainsPolicy
      Parameters:
      value - the text value (snippet) of a CONTAINS MatchExpression
      Returns:
      cleaned value
    • createInstruction

      public String createInstruction(String columnName, String patternParameter)
      Description copied from interface: SqlContainsPolicy
      Returns the SQL-instruction to compare a column against a pattern.

      Here are some examples:

      • COL123 LIKE '%' || ${PATTERN_1011} || '%' should work well with Oracle, SQLite, PostgreSQL
      • COL123 LIKE CONCAT('%', ${PATTERN_1011}, '%') should do with MySQL
      • COL123 LIKE '%' + ${PATTERN_1011} + '%' should work with SQL Server
      • CHARINDEX(${PATTERN_1011}, COL123, 0) > 0 may also work with SQL Server
      Notes:
      • The percentage signs are not part of the prepared statement parameter. This will ensure they do their job, no matter if the driver escapes percentage signs in prepared statement parameters or not.
      • ${PATTERN_1011} is a placeholder without any meaning and not to be included in quotes here.
      • The best way to realize CONTAINS depends on your DB, and there might be multiple roads to success.
      Specified by:
      createInstruction in interface SqlContainsPolicy
      Parameters:
      columnName - this is the SQL column or alias to perform the CONTAINS/LIKE operation on, e.g. COL123
      patternParameter - placeholder (later argument to prepared statement) that will hold the pattern (e.g., ${PATTERN_1011}
    • name

      public String name()
      Specified by:
      name in interface SqlContainsPolicy
      Returns:
      unique name (identifier) of this policy
    • toString

      public String toString()
      Overrides:
      toString in class Object