From 2e061133eaac6b03bfd3f89ea1e937d543c625ef Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 24 Sep 2021 15:57:47 +0200 Subject: [PATCH] [jOOQ/jOOQ#12465] [jOOQ/jOOQ#12432] Extract more CompareConditions Including: - LIKE_IGNORE_CASE - NOT_LIKE_IGNORE_CASE - NOT_SIMILAR_TO - SIMILAR_TO --- jOOQ/src/main/java/org/jooq/Field.java | 180 +++++++++--------- .../main/java/org/jooq/LikeEscapeStep.java | 4 +- .../java/org/jooq/impl/AbstractField.java | 97 ++++++---- .../java/org/jooq/impl/CompareCondition.java | 115 +---------- jOOQ/src/main/java/org/jooq/impl/Like.java | 20 +- .../java/org/jooq/impl/LikeIgnoreCase.java | 154 +++++++++++++++ .../java/org/jooq/impl/NotLikeIgnoreCase.java | 154 +++++++++++++++ .../main/java/org/jooq/impl/NotSimilarTo.java | 154 +++++++++++++++ .../main/java/org/jooq/impl/SimilarTo.java | 154 +++++++++++++++ 9 files changed, 791 insertions(+), 241 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/LikeIgnoreCase.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/NotLikeIgnoreCase.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/NotSimilarTo.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/SimilarTo.java diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index 9b5f78c574..b96bc576dc 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -959,6 +959,36 @@ extends @Support LikeEscapeStep like(Field pattern); + /** + * The LIKE_IGNORE_CASE operator. + *

+ * Create a condition to case-insensitively pattern-check this field against + * a value. + *

+ * This translates to this not ilike value in + * {@link SQLDialect#POSTGRES}, or to + * lower(this) not like lower(value) in all other dialects. + * + * @param pattern is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support + LikeEscapeStep likeIgnoreCase(@Stringly.Param String pattern); + + /** + * The LIKE_IGNORE_CASE operator. + *

+ * Create a condition to case-insensitively pattern-check this field against + * a value. + *

+ * This translates to this not ilike value in + * {@link SQLDialect#POSTGRES}, or to + * lower(this) not like lower(value) in all other dialects. + */ + @NotNull + @Support + LikeEscapeStep likeIgnoreCase(Field pattern); + /** * The LT operator. */ @@ -1038,6 +1068,68 @@ extends @Support LikeEscapeStep notLike(Field pattern); + /** + * The NOT_LIKE_IGNORE_CASE operator. + *

+ * Create a condition to case-insensitively pattern-check this field against + * a value. + *

+ * This translates to this not ilike value in + * {@link SQLDialect#POSTGRES}, or to + * lower(this) not like lower(value) in all other dialects. + * + * @param pattern is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support + LikeEscapeStep notLikeIgnoreCase(@Stringly.Param String pattern); + + /** + * The NOT_LIKE_IGNORE_CASE operator. + *

+ * Create a condition to case-insensitively pattern-check this field against + * a value. + *

+ * This translates to this not ilike value in + * {@link SQLDialect#POSTGRES}, or to + * lower(this) not like lower(value) in all other dialects. + */ + @NotNull + @Support + LikeEscapeStep notLikeIgnoreCase(Field pattern); + + /** + * The NOT_SIMILAR_TO operator. + * + * @param pattern is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support + LikeEscapeStep notSimilarTo(@Stringly.Param String pattern); + + /** + * The NOT_SIMILAR_TO operator. + */ + @NotNull + @Support + LikeEscapeStep notSimilarTo(Field pattern); + + /** + * The SIMILAR_TO operator. + * + * @param pattern is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support + LikeEscapeStep similarTo(@Stringly.Param String pattern); + + /** + * The SIMILAR_TO operator. + */ + @NotNull + @Support + LikeEscapeStep similarTo(Field pattern); + // ------------------------------------------------------------------------- // XML predicates // ------------------------------------------------------------------------- @@ -1336,7 +1428,7 @@ extends * also to express the "ARRAY contains" operator. For example:

      * // Use this expression
      * val(new Integer[] { 1, 2, 3 }).contains(new Integer[] { 1, 2 })
-     * 
+     *
      * // ... to render this SQL
      * ARRAY[1, 2, 3] @> ARRAY[1, 2]
      * 
@@ -1365,7 +1457,7 @@ extends * also to express the "ARRAY contains" operator. For example:
      * // Use this expression
      * val(new Integer[] { 1, 2, 3 }).contains(new Integer[] { 1, 2 })
-     * 
+     *
      * // ... to render this SQL
      * ARRAY[1, 2, 3] @> ARRAY[1, 2]
      * 
@@ -2027,15 +2119,6 @@ extends // SIMILAR TO predicates // ------------------------------------------------------------------------ - /** - * Create a condition to pattern-check this field against a value. - *

- * SQL: this similar to value - */ - @NotNull - @Support({ FIREBIRD, POSTGRES, YUGABYTE }) - LikeEscapeStep similarTo(Field value); - /** * Create a condition to pattern-check this field against a value. *

@@ -2047,15 +2130,6 @@ extends @Support({ FIREBIRD, POSTGRES, YUGABYTE }) Condition similarTo(Field value, char escape); - /** - * Create a condition to pattern-check this field against a value. - *

- * SQL: this similar to value - */ - @NotNull - @Support({ FIREBIRD, POSTGRES, YUGABYTE }) - LikeEscapeStep similarTo(String value); - /** * Create a condition to pattern-check this field against a value. *

@@ -2067,15 +2141,6 @@ extends @Support({ FIREBIRD, POSTGRES, YUGABYTE }) Condition similarTo(String value, char escape); - /** - * Create a condition to pattern-check this field against a field. - *

- * SQL: this not similar to field - */ - @NotNull - @Support({ FIREBIRD, POSTGRES, YUGABYTE }) - LikeEscapeStep notSimilarTo(Field field); - /** * Create a condition to pattern-check this field against a field. *

@@ -2087,15 +2152,6 @@ extends @Support({ FIREBIRD, POSTGRES, YUGABYTE }) Condition notSimilarTo(Field field, char escape); - /** - * Create a condition to pattern-check this field against a value. - *

- * SQL: this not similar to value - */ - @NotNull - @Support({ FIREBIRD, POSTGRES, YUGABYTE }) - LikeEscapeStep notSimilarTo(String value); - /** * Create a condition to pattern-check this field against a value. *

@@ -2153,18 +2209,6 @@ extends @Support LikeEscapeStep like(QuantifiedSelect> query); - /** - * Create a condition to case-insensitively pattern-check this field against - * a field. - *

- * This translates to this ilike field in - * {@link SQLDialect#POSTGRES}, or to - * lower(this) like lower(field) in all other dialects. - */ - @NotNull - @Support - LikeEscapeStep likeIgnoreCase(Field field); - /** * Create a condition to case-insensitively pattern-check this field against * a field. @@ -2179,18 +2223,6 @@ extends @Support Condition likeIgnoreCase(Field field, char escape); - /** - * Create a condition to case-insensitively pattern-check this field against - * a value. - *

- * This translates to this ilike value in - * {@link SQLDialect#POSTGRES}, or to - * lower(this) like lower(value) in all other dialects. - */ - @NotNull - @Support - LikeEscapeStep likeIgnoreCase(String value); - /** * Create a condition to case-insensitively pattern-check this field against * a value. @@ -2247,18 +2279,6 @@ extends @Support LikeEscapeStep notLike(QuantifiedSelect> query); - /** - * Create a condition to case-insensitively pattern-check this field against - * a field. - *

- * This translates to this not ilike field in - * {@link SQLDialect#POSTGRES}, or to - * lower(this) not like lower(field) in all other dialects. - */ - @NotNull - @Support - LikeEscapeStep notLikeIgnoreCase(Field field); - /** * Create a condition to case-insensitively pattern-check this field against * a field. @@ -2273,18 +2293,6 @@ extends @Support Condition notLikeIgnoreCase(Field field, char escape); - /** - * Create a condition to case-insensitively pattern-check this field against - * a value. - *

- * This translates to this not ilike value in - * {@link SQLDialect#POSTGRES}, or to - * lower(this) not like lower(value) in all other dialects. - */ - @NotNull - @Support - LikeEscapeStep notLikeIgnoreCase(String value); - /** * Create a condition to case-insensitively pattern-check this field against * a value. diff --git a/jOOQ/src/main/java/org/jooq/LikeEscapeStep.java b/jOOQ/src/main/java/org/jooq/LikeEscapeStep.java index 5cf5f5fc28..f8428af918 100644 --- a/jOOQ/src/main/java/org/jooq/LikeEscapeStep.java +++ b/jOOQ/src/main/java/org/jooq/LikeEscapeStep.java @@ -44,7 +44,7 @@ import java.util.*; import org.jetbrains.annotations.*; /** - * A step in the construction of the NOT LIKE function. + * A step in the construction of the LIKE function. *

*

Referencing XYZ*Step types directly from client code

*

@@ -68,7 +68,7 @@ import org.jetbrains.annotations.*; public interface LikeEscapeStep extends Condition { /** - * Add the ESCAPE clause to the NOT LIKE function. + * Add the ESCAPE clause to the LIKE function. *

* For example: * diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java index 888f4a99ee..99ecd86881 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractField.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractField.java @@ -544,6 +544,18 @@ abstract class AbstractField extends AbstractTypedNamed implements Field pattern) { + return new LikeIgnoreCase(this, nullSafe(pattern, getDataType())); + } + @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public final Condition lt(T arg2) { @@ -607,6 +619,42 @@ abstract class AbstractField extends AbstractTypedNamed implements Field pattern) { + return new NotLikeIgnoreCase(this, nullSafe(pattern, getDataType())); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public final LikeEscapeStep notSimilarTo(String pattern) { + return new NotSimilarTo(this, Tools.field(pattern)); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public final LikeEscapeStep notSimilarTo(Field pattern) { + return new NotSimilarTo(this, nullSafe(pattern, getDataType())); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public final LikeEscapeStep similarTo(String pattern) { + return new SimilarTo(this, Tools.field(pattern)); + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public final LikeEscapeStep similarTo(Field pattern) { + return new SimilarTo(this, nullSafe(pattern, getDataType())); + } + // ------------------------------------------------------------------------- // XML predicates // ------------------------------------------------------------------------- @@ -1051,41 +1099,21 @@ abstract class AbstractField extends AbstractTypedNamed implements Field field) { - return new CompareCondition(this, nullSafe(field, getDataType()), SIMILAR_TO); - } - @Override public final Condition similarTo(Field field, char escape) { return similarTo(field).escape(escape); } - @Override - public final LikeEscapeStep notSimilarTo(String value) { - return notSimilarTo(Tools.field(value)); - } - @Override public final Condition notSimilarTo(String value, char escape) { return notSimilarTo(Tools.field(value), escape); } - @Override - public final LikeEscapeStep notSimilarTo(Field field) { - return new CompareCondition(this, nullSafe(field, getDataType()), NOT_SIMILAR_TO); - } - @Override public final Condition notSimilarTo(Field field, char escape) { return notSimilarTo(field).escape(escape); @@ -1106,21 +1134,11 @@ abstract class AbstractField extends AbstractTypedNamed implements Field field) { - return new CompareCondition(this, nullSafe(field, getDataType()), LIKE_IGNORE_CASE); - } - @Override public final Condition likeIgnoreCase(Field field, char escape) { return likeIgnoreCase(field).escape(escape); @@ -1151,21 +1169,11 @@ abstract class AbstractField extends AbstractTypedNamed implements Field field) { - return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE_IGNORE_CASE); - } - @Override public final Condition notLikeIgnoreCase(Field field, char escape) { return notLikeIgnoreCase(field).escape(escape); @@ -1444,6 +1452,7 @@ abstract class AbstractField extends AbstractTypedNamed implements Field field) { switch (comparator) { @@ -1462,8 +1471,16 @@ abstract class AbstractField extends AbstractTypedNamed implements Field(this, nullSafe(field, getDataType())); diff --git a/jOOQ/src/main/java/org/jooq/impl/CompareCondition.java b/jOOQ/src/main/java/org/jooq/impl/CompareCondition.java index e4854e1e03..339bfb7dca 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CompareCondition.java +++ b/jOOQ/src/main/java/org/jooq/impl/CompareCondition.java @@ -42,85 +42,35 @@ import static java.lang.Boolean.TRUE; import static org.jooq.Clause.CONDITION; import static org.jooq.Clause.CONDITION_COMPARISON; import static org.jooq.Comparator.IN; -import static org.jooq.Comparator.LIKE; -import static org.jooq.Comparator.LIKE_IGNORE_CASE; import static org.jooq.Comparator.NOT_IN; -import static org.jooq.Comparator.NOT_LIKE; -import static org.jooq.Comparator.NOT_LIKE_IGNORE_CASE; -import static org.jooq.Comparator.NOT_SIMILAR_TO; -import static org.jooq.Comparator.SIMILAR_TO; // ... -// ... -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.CUBRID; -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.FIREBIRD; -// ... -import static org.jooq.SQLDialect.HSQLDB; -// ... -// ... -// ... -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... -// ... -import static org.jooq.SQLDialect.SQLITE; -// ... -// ... -// ... -// ... -import static org.jooq.SQLDialect.YUGABYTE; -import static org.jooq.conf.ParamType.INLINED; import static org.jooq.impl.DSL.asterisk; -import static org.jooq.impl.DSL.inline; import static org.jooq.impl.DSL.row; import static org.jooq.impl.DSL.select; -import static org.jooq.impl.Keywords.K_AS; -import static org.jooq.impl.Keywords.K_CAST; -import static org.jooq.impl.Keywords.K_ESCAPE; -import static org.jooq.impl.Keywords.K_VARCHAR; -import static org.jooq.impl.Tools.castIfNeeded; -import static org.jooq.impl.Tools.characterLiteral; import static org.jooq.impl.Tools.embeddedFields; import static org.jooq.impl.Tools.nullSafe; import static org.jooq.impl.Tools.nullableIf; import static org.jooq.impl.Tools.BooleanDataKey.DATA_MULTISET_CONDITION; -import static org.jooq.impl.Transformations.transformInConditionSubqueryWithLimitToDerivedTable; import static org.jooq.impl.Transformations.subqueryWithLimit; - -import java.util.Set; +import static org.jooq.impl.Transformations.transformInConditionSubqueryWithLimitToDerivedTable; import org.jooq.Clause; import org.jooq.Comparator; -import org.jooq.Condition; import org.jooq.Context; import org.jooq.Field; -import org.jooq.LikeEscapeStep; // ... -import org.jooq.SQLDialect; import org.jooq.Select; -import org.jooq.conf.ParamType; /** * @author Lukas Eder */ -final class CompareCondition extends AbstractCondition implements LikeEscapeStep { +final class CompareCondition extends AbstractCondition { private static final Clause[] CLAUSES = { CONDITION, CONDITION_COMPARISON }; - private static final Set REQUIRES_CAST_ON_LIKE = SQLDialect.supportedBy(DERBY, POSTGRES, YUGABYTE); - private static final Set NO_SUPPORT_ILIKE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL, SQLITE); final Field field1; final Field field2; final Comparator comparator; - private Character escape; CompareCondition(Field field1, Field field2, Comparator comparator) { this.field1 = nullableIf(comparator.supportsNulls(), nullSafe(field1, field2.getDataType())); @@ -128,12 +78,6 @@ final class CompareCondition extends AbstractCondition implements LikeEscapeStep this.comparator = comparator; } - @Override - public final Condition escape(char c) { - this.escape = c; - return this; - } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public final void accept(Context ctx) { @@ -167,57 +111,7 @@ final class CompareCondition extends AbstractCondition implements LikeEscapeStep - SQLDialect family = ctx.family(); - Field lhs = field1; - Field rhs = field2; - Comparator op = comparator; - - // [#1159] [#1725] Some dialects cannot auto-convert the LHS operand to a - // VARCHAR when applying a LIKE predicate - if ((op == LIKE || op == NOT_LIKE || op == SIMILAR_TO || op == NOT_SIMILAR_TO) - && field1.getType() != String.class - && REQUIRES_CAST_ON_LIKE.contains(ctx.dialect())) { - - lhs = castIfNeeded(lhs, String.class); - } - - // [#1423] [#9889] PostgreSQL and H2 support ILIKE natively. Other dialects - // need to emulate this as LOWER(lhs) LIKE LOWER(rhs) - else if ((op == LIKE_IGNORE_CASE || op == NOT_LIKE_IGNORE_CASE) && NO_SUPPORT_ILIKE.contains(ctx.dialect())) { - lhs = lhs.lower(); - rhs = rhs.lower(); - op = (op == LIKE_IGNORE_CASE ? LIKE : NOT_LIKE); - } - - ctx.visit(lhs) - .sql(' '); - - boolean castRhs = false; - ParamType previousParamType = ctx.paramType(); - ParamType forcedParamType = previousParamType; - - - - - - - - - - - - - - - ctx.visit(op.toKeyword()).sql(' '); - if (castRhs) ctx.visit(K_CAST).sql('('); - ctx.visit(rhs, forcedParamType); - if (castRhs) ctx.sql(' ').visit(K_AS).sql(' ').visit(K_VARCHAR).sql("(4000))"); - - if (escape != null) { - ctx.sql(' ').visit(K_ESCAPE).sql(' ') - .visit(inline(escape)); - } + ctx.visit(field1).sql(' ').visit(comparator.toKeyword()).sql(' ').visit(field2); } @@ -248,9 +142,6 @@ final class CompareCondition extends AbstractCondition implements LikeEscapeStep - - - diff --git a/jOOQ/src/main/java/org/jooq/impl/Like.java b/jOOQ/src/main/java/org/jooq/impl/Like.java index 6b9a6ffe25..3783341523 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Like.java +++ b/jOOQ/src/main/java/org/jooq/impl/Like.java @@ -46,6 +46,12 @@ import static org.jooq.impl.Tools.*; import static org.jooq.impl.Tools.BooleanDataKey.*; import static org.jooq.impl.Tools.DataExtendedKey.*; import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.Comparator.LIKE; +import static org.jooq.Comparator.LIKE_IGNORE_CASE; +import static org.jooq.Comparator.NOT_LIKE; +import static org.jooq.Comparator.NOT_LIKE_IGNORE_CASE; +import static org.jooq.Comparator.NOT_SIMILAR_TO; +import static org.jooq.Comparator.SIMILAR_TO; import static org.jooq.SQLDialect.*; import org.jooq.*; @@ -113,6 +119,7 @@ implements private static final Set REQUIRES_CAST_ON_LIKE = SQLDialect.supportedBy(DERBY, POSTGRES, YUGABYTE); + private static final Set NO_SUPPORT_ILIKE = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, HSQLDB, MARIADB, MYSQL, SQLITE); @Override public final void accept(Context ctx) { @@ -158,8 +165,19 @@ implements // [#1159] [#1725] Some dialects cannot auto-convert the LHS operand to a // VARCHAR when applying a LIKE predicate - if (arg1.getType() != String.class && REQUIRES_CAST_ON_LIKE.contains(ctx.dialect())) + if ((op == LIKE || op == NOT_LIKE || op == SIMILAR_TO || op == NOT_SIMILAR_TO) + && arg1.getType() != String.class + && REQUIRES_CAST_ON_LIKE.contains(ctx.dialect())) { arg1 = castIfNeeded(arg1, String.class); + } + + // [#1423] [#9889] PostgreSQL and H2 support ILIKE natively. Other dialects + // need to emulate this as LOWER(lhs) LIKE LOWER(rhs) + else if ((op == LIKE_IGNORE_CASE || op == NOT_LIKE_IGNORE_CASE) && NO_SUPPORT_ILIKE.contains(ctx.dialect())) { + arg1 = DSL.lower((Field) arg1); + arg2 = DSL.lower((Field) arg2); + op = (op == LIKE_IGNORE_CASE ? LIKE : NOT_LIKE); + } boolean castRhs = castRhs(ctx, arg2); diff --git a/jOOQ/src/main/java/org/jooq/impl/LikeIgnoreCase.java b/jOOQ/src/main/java/org/jooq/impl/LikeIgnoreCase.java new file mode 100644 index 0000000000..6a885c742b --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/LikeIgnoreCase.java @@ -0,0 +1,154 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + + +/** + * The LIKE IGNORE CASE statement. + */ +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class LikeIgnoreCase +extends + AbstractCondition +implements + LikeEscapeStep +{ + + final Field value; + final Field pattern; + Character escape; + + LikeIgnoreCase( + Field value, + Field pattern + ) { + this( + value, + pattern, + null + ); + } + + LikeIgnoreCase( + Field value, + Field pattern, + Character escape + ) { + + this.value = nullSafeNotNull(value, OTHER); + this.pattern = nullSafeNotNull(pattern, VARCHAR); + this.escape = escape; + } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final LikeIgnoreCase escape(char escape) { + this.escape = escape; + return this; + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Like.accept0(ctx, value, org.jooq.Comparator.LIKE_IGNORE_CASE, pattern, escape); + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof LikeIgnoreCase) { + return + StringUtils.equals(value, ((LikeIgnoreCase) that).value) && + StringUtils.equals(pattern, ((LikeIgnoreCase) that).pattern) && + StringUtils.equals(escape, ((LikeIgnoreCase) that).escape) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/NotLikeIgnoreCase.java b/jOOQ/src/main/java/org/jooq/impl/NotLikeIgnoreCase.java new file mode 100644 index 0000000000..aab9ed4a55 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/NotLikeIgnoreCase.java @@ -0,0 +1,154 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + + +/** + * The NOT LIKE IGNORE CASE statement. + */ +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class NotLikeIgnoreCase +extends + AbstractCondition +implements + LikeEscapeStep +{ + + final Field value; + final Field pattern; + Character escape; + + NotLikeIgnoreCase( + Field value, + Field pattern + ) { + this( + value, + pattern, + null + ); + } + + NotLikeIgnoreCase( + Field value, + Field pattern, + Character escape + ) { + + this.value = nullSafeNotNull(value, OTHER); + this.pattern = nullSafeNotNull(pattern, VARCHAR); + this.escape = escape; + } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final NotLikeIgnoreCase escape(char escape) { + this.escape = escape; + return this; + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Like.accept0(ctx, value, org.jooq.Comparator.NOT_LIKE_IGNORE_CASE, pattern, escape); + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof NotLikeIgnoreCase) { + return + StringUtils.equals(value, ((NotLikeIgnoreCase) that).value) && + StringUtils.equals(pattern, ((NotLikeIgnoreCase) that).pattern) && + StringUtils.equals(escape, ((NotLikeIgnoreCase) that).escape) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/NotSimilarTo.java b/jOOQ/src/main/java/org/jooq/impl/NotSimilarTo.java new file mode 100644 index 0000000000..a3137d4060 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/NotSimilarTo.java @@ -0,0 +1,154 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + + +/** + * The NOT SIMILAR TO statement. + */ +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class NotSimilarTo +extends + AbstractCondition +implements + LikeEscapeStep +{ + + final Field value; + final Field pattern; + Character escape; + + NotSimilarTo( + Field value, + Field pattern + ) { + this( + value, + pattern, + null + ); + } + + NotSimilarTo( + Field value, + Field pattern, + Character escape + ) { + + this.value = nullSafeNotNull(value, OTHER); + this.pattern = nullSafeNotNull(pattern, VARCHAR); + this.escape = escape; + } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final NotSimilarTo escape(char escape) { + this.escape = escape; + return this; + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Like.accept0(ctx, value, org.jooq.Comparator.NOT_SIMILAR_TO, pattern, escape); + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof NotSimilarTo) { + return + StringUtils.equals(value, ((NotSimilarTo) that).value) && + StringUtils.equals(pattern, ((NotSimilarTo) that).pattern) && + StringUtils.equals(escape, ((NotSimilarTo) that).escape) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/SimilarTo.java b/jOOQ/src/main/java/org/jooq/impl/SimilarTo.java new file mode 100644 index 0000000000..1ba5ff1a4b --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/SimilarTo.java @@ -0,0 +1,154 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + + +/** + * The SIMILAR TO statement. + */ +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class SimilarTo +extends + AbstractCondition +implements + LikeEscapeStep +{ + + final Field value; + final Field pattern; + Character escape; + + SimilarTo( + Field value, + Field pattern + ) { + this( + value, + pattern, + null + ); + } + + SimilarTo( + Field value, + Field pattern, + Character escape + ) { + + this.value = nullSafeNotNull(value, OTHER); + this.pattern = nullSafeNotNull(pattern, VARCHAR); + this.escape = escape; + } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final SimilarTo escape(char escape) { + this.escape = escape; + return this; + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + public final void accept(Context ctx) { + + + + + + + + Like.accept0(ctx, value, org.jooq.Comparator.SIMILAR_TO, pattern, escape); + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof SimilarTo) { + return + StringUtils.equals(value, ((SimilarTo) that).value) && + StringUtils.equals(pattern, ((SimilarTo) that).pattern) && + StringUtils.equals(escape, ((SimilarTo) that).escape) + ; + } + else + return super.equals(that); + } +}