From 9d75ad1b2ee38fd59e8af330d844ce02e1bc1a1f Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 13 Dec 2022 15:33:36 +0100 Subject: [PATCH] [jOOQ/jOOQ#11981] [jOOQ/jOOQ#14352] Pull up PostgresDSL::arrayOverlap This implicitly fixes: - [jOOQ/jOOQ#14352] PostgresDSL arrayOverlap does not properly cast arguments --- .../main/java/org/jooq/impl/ArrayOverlap.java | 163 ++++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 44 +++++ jOOQ/src/main/java/org/jooq/impl/Names.java | 1 + jOOQ/src/main/java/org/jooq/impl/QOM.java | 14 ++ .../org/jooq/util/postgres/PostgresDSL.java | 72 ++++++-- 5 files changed, 280 insertions(+), 14 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/ArrayOverlap.java diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayOverlap.java b/jOOQ/src/main/java/org/jooq/impl/ArrayOverlap.java new file mode 100644 index 0000000000..eecef1da8f --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/ArrayOverlap.java @@ -0,0 +1,163 @@ +/* + * 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 + * + * https://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: https://www.jooq.org/legal/licensing + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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.ExtendedDataKey.*; +import static org.jooq.impl.Tools.SimpleDataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Function1; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.impl.QOM.*; +import org.jooq.tools.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + + +/** + * The ARRAY OVERLAP statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class ArrayOverlap +extends + AbstractCondition +implements + QOM.ArrayOverlap +{ + + final Field arg1; + final Field arg2; + + ArrayOverlap( + Field arg1, + Field arg2 + ) { + + this.arg1 = nullSafeNotNull(arg1, ((DataType) OTHER).getArrayDataType()); + this.arg2 = nullSafeNotNull(arg2, ((DataType) OTHER).getArrayDataType()); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + ctx.sql('(').visit(arg1).sql(" && ").visit(arg2).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return arg1; + } + + @Override + public final Field $arg2() { + return arg2; + } + + @Override + public final QOM.ArrayOverlap $arg1(Field newValue) { + return $constructor().apply(newValue, $arg2()); + } + + @Override + public final QOM.ArrayOverlap $arg2(Field newValue) { + return $constructor().apply($arg1(), newValue); + } + + @Override + public final Function2, ? super Field, ? extends QOM.ArrayOverlap> $constructor() { + return (a1, a2) -> new ArrayOverlap<>(a1, a2); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.ArrayOverlap o) { + return + StringUtils.equals($arg1(), o.$arg1()) && + StringUtils.equals($arg2(), o.$arg2()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index d85bcbfa31..14cb28d300 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -19736,6 +19736,50 @@ public class DSL { return new ArrayConcat<>(arg1, arg2); } + /** + * The ARRAY_OVERLAP function. + *

+ * Check if 2 arrays overlap. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Condition arrayOverlap(T[] arg1, T[] arg2) { + return new ArrayOverlap<>(Tools.field(arg1), Tools.field(arg2)); + } + + /** + * The ARRAY_OVERLAP function. + *

+ * Check if 2 arrays overlap. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Condition arrayOverlap(T[] arg1, Field arg2) { + return new ArrayOverlap<>(Tools.field(arg1), arg2); + } + + /** + * The ARRAY_OVERLAP function. + *

+ * Check if 2 arrays overlap. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Condition arrayOverlap(Field arg1, T[] arg2) { + return new ArrayOverlap<>(arg1, Tools.field(arg2, arg1)); + } + + /** + * The ARRAY_OVERLAP function. + *

+ * Check if 2 arrays overlap. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Condition arrayOverlap(Field arg1, Field arg2) { + return new ArrayOverlap<>(arg1, arg2); + } + // ------------------------------------------------------------------------- // Utility functions // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index 6dea5bfd14..66715b3fd9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -347,6 +347,7 @@ final class Names { static final Name N_ANY_VALUE = systemName("any_value"); static final Name N_ARRAY_CONCAT = systemName("array_concat"); static final Name N_ARRAY_GET = systemName("array_get"); + static final Name N_ARRAY_OVERLAP = systemName("array_overlap"); static final Name N_ASCII = systemName("ascii"); static final Name N_ASIN = systemName("asin"); static final Name N_ASINH = systemName("asinh"); diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 91f49d1362..57143b4d0e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -4841,6 +4841,20 @@ public final class QOM { // ArrayConcat {} + /** + * The ARRAY OVERLAP function. + *

+ * Check if 2 arrays overlap. + */ + public /*sealed*/ interface ArrayOverlap + extends + UReturnsNullOnNullInput, + UOperator2, Field, Condition>, + org.jooq.Condition + //permits + // ArrayOverlap + {} + /** * The NVL function. *

diff --git a/jOOQ/src/main/java/org/jooq/util/postgres/PostgresDSL.java b/jOOQ/src/main/java/org/jooq/util/postgres/PostgresDSL.java index 2408db1775..e42abba4dc 100644 --- a/jOOQ/src/main/java/org/jooq/util/postgres/PostgresDSL.java +++ b/jOOQ/src/main/java/org/jooq/util/postgres/PostgresDSL.java @@ -71,10 +71,18 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array1 && array2 overlap operator. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * true = array[1, 2, 3] && array[3, 4, 5]
-     * 
+ *
+ *
+ * + * @deprecated - 3.16.0 - [#14352] - Use + * {@link DSL#arrayOverlap(Object[], Object[])} instead. */ + @Deprecated @NotNull @Support({ POSTGRES, YUGABYTEDB }) public static Condition arrayOverlap(T[] left, T[] right) { @@ -84,10 +92,18 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array1 && array2 overlap operator. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * true = array[1, 2, 3] && array[3, 4, 5]
-     * 
+ *
+ *
+ * + * @deprecated - 3.16.0 - [#14352] - Use + * {@link DSL#arrayOverlap(Object[], Field)} instead. */ + @Deprecated @NotNull @Support({ POSTGRES, YUGABYTEDB }) public static Condition arrayOverlap(T[] left, Field right) { @@ -97,10 +113,18 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array1 && array2 overlap operator. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * true = array[1, 2, 3] && array[3, 4, 5]
-     * 
+ *
+ *
+ * + * @deprecated - 3.16.0 - [#14352] - Use + * {@link DSL#arrayOverlap(Field, Object[])} instead. */ + @Deprecated @NotNull @Support({ POSTGRES, YUGABYTEDB }) public static Condition arrayOverlap(Field left, T[] right) { @@ -110,10 +134,18 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array1 && array2 overlap operator. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * true = array[1, 2, 3] && array[3, 4, 5]
-     * 
+ *
+ *
+ * + * @deprecated - 3.16.0 - [#14352] - Use + * {@link DSL#arrayOverlap(Field, Field)} instead. */ + @Deprecated @NotNull @Support({ POSTGRES, YUGABYTEDB }) public static Condition arrayOverlap(Field left, Field right) { @@ -260,9 +292,13 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array_cat(anyarray, anyelement) function. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * {1, 2, 3, 4, 5} = array_cat(ARRAY[1, 2], ARRAY[3, 4, 5])
-     * 
+ *
+ *
* * @deprecated - 3.16.0 - [#14388] - Use * {@link DSL#arrayConcat(Object[], Field)} instead. @@ -277,9 +313,13 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array_cat(anyarray, anyelement) function. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * {1, 2, 3, 4, 5} = array_cat(ARRAY[1, 2], ARRAY[3, 4, 5])
-     * 
+ *
+ *
* * @deprecated - 3.16.0 - [#14388] - Use * {@link DSL#arrayConcat(Field, Object[])} instead. @@ -294,9 +334,13 @@ public class PostgresDSL extends DSL { /** * The PostgreSQL array_cat(anyarray, anyelement) function. *

- * Example:


+     * Example:
+     *
+     * 
+     * 
      * {1, 2, 3, 4, 5} = array_cat(ARRAY[1, 2], ARRAY[3, 4, 5])
-     * 
+ *
+ *
* * @deprecated - 3.16.0 - [#14388] - Use * {@link DSL#arrayConcat(Field, Field)} instead.