Package de.calamanari.adl.sql.config
Class SqlContainsPolicyDecorator
java.lang.Object
de.calamanari.adl.sql.config.SqlContainsPolicyDecorator
- All Implemented Interfaces:
SqlContainsPolicy,Serializable
An
SqlContainsPolicyDecorator allows to quickly create a new policy by decorating a given one with a different behavioral aspect.- Author:
- Karl Eilebrecht
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.calamanari.adl.sql.config.SqlContainsPolicy
SqlContainsPolicy.CreatorFunction, SqlContainsPolicy.PreparatorFunction -
Method Summary
Modifier and TypeMethodDescriptioncreateInstruction(String columnName, String patternParameter) Returns the SQL-instruction to compare a column against a pattern.name()prepareSearchSnippet(String value) This method allows to modify the snippet to conform to a specific database.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface de.calamanari.adl.sql.config.SqlContainsPolicy
withCreatorFunction, withCreatorFunction, withPreparatorFunction, withPreparatorFunction
-
Method Details
-
prepareSearchSnippet
Description copied from interface:SqlContainsPolicyThis 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:
prepareSearchSnippetin interfaceSqlContainsPolicy- Parameters:
value- the text value (snippet) of a CONTAINSMatchExpression- Returns:
- cleaned value
-
createInstruction
Description copied from interface:SqlContainsPolicyReturns the SQL-instruction to compare a column against a pattern.Here are some examples:
COL123 LIKE '%' || ${PATTERN_1011} || '%'should work well with Oracle, SQLite, PostgreSQLCOL123 LIKE CONCAT('%', ${PATTERN_1011}, '%')should do with MySQLCOL123 LIKE '%' + ${PATTERN_1011} + '%'should work with SQL ServerCHARINDEX(${PATTERN_1011}, COL123, 0) > 0may also work with SQL Server
- 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:
createInstructionin interfaceSqlContainsPolicy- Parameters:
columnName- this is the SQL column or alias to perform the CONTAINS/LIKE operation on, e.g.COL123patternParameter- placeholder (later argument to prepared statement) that will hold the pattern (e.g.,${PATTERN_1011}
-
name
- Specified by:
namein interfaceSqlContainsPolicy- Returns:
- unique name (identifier) of this policy
-
toString
-