From c1ffc7b7b3f29c2fd8fa80fa05a7a2bdd324b1b4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 7 Feb 2024 13:27:52 +0100 Subject: [PATCH] [jOOQ/jOOQ#16101] Add support for binaryConcat() --- .../main/java/org/jooq/impl/BinaryConcat.java | 167 ++++++++++++++++++ .../java/org/jooq/impl/BinaryOverlay.java | 2 +- jOOQ/src/main/java/org/jooq/impl/DSL.java | 56 ++++++ jOOQ/src/main/java/org/jooq/impl/Names.java | 1 + jOOQ/src/main/java/org/jooq/impl/Overlay.java | 24 ++- jOOQ/src/main/java/org/jooq/impl/QOM.java | 37 ++++ 6 files changed, 278 insertions(+), 9 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java b/jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java new file mode 100644 index 0000000000..df24273d18 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java @@ -0,0 +1,167 @@ +/* + * 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 BINARY CONCAT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class BinaryConcat +extends + AbstractField +implements + QOM.BinaryConcat +{ + + final Field bytes1; + final Field bytes2; + + BinaryConcat( + Field bytes1, + Field bytes2 + ) { + super( + N_BINARY_CONCAT, + allNotNull(VARBINARY, bytes1, bytes2) + ); + + this.bytes1 = nullSafeNotNull(bytes1, VARBINARY); + this.bytes2 = nullSafeNotNull(bytes2, VARBINARY); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + default: + ctx.sql('(').visit(bytes1).sql(" || ").visit(bytes2).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return bytes1; + } + + @Override + public final Field $arg2() { + return bytes2; + } + + @Override + public final QOM.BinaryConcat $arg1(Field newValue) { + return $constructor().apply(newValue, $arg2()); + } + + @Override + public final QOM.BinaryConcat $arg2(Field newValue) { + return $constructor().apply($arg1(), newValue); + } + + @Override + public final Function2, ? super Field, ? extends QOM.BinaryConcat> $constructor() { + return (a1, a2) -> new BinaryConcat(a1, a2); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.BinaryConcat o) { + return + StringUtils.equals($bytes1(), o.$bytes1()) && + StringUtils.equals($bytes2(), o.$bytes2()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java b/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java index 6bc895bb2a..3ef93864d9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java +++ b/jOOQ/src/main/java/org/jooq/impl/BinaryOverlay.java @@ -127,7 +127,7 @@ implements Overlay.accept0(ctx, in, placing, startIndex, length, - DSL::binaryLength, DSL::binarySubstring, DSL::binarySubstring + DSL::binaryLength, DSL::binaryConcat, DSL::binarySubstring, DSL::binarySubstring ); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 4d360c16a8..c606d11545 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -20922,6 +20922,62 @@ public class DSL { return new BinaryBitLength(bytes); } + /** + * The BINARY_CONCAT function. + *

+ * The concatenation of binary strings. + * + * @param bytes1 The first binary string. + * @param bytes2 The second binary string. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryConcat(byte[] bytes1, byte[] bytes2) { + return new BinaryConcat(Tools.field(bytes1), Tools.field(bytes2)); + } + + /** + * The BINARY_CONCAT function. + *

+ * The concatenation of binary strings. + * + * @param bytes1 The first binary string. + * @param bytes2 The second binary string. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryConcat(byte[] bytes1, Field bytes2) { + return new BinaryConcat(Tools.field(bytes1), bytes2); + } + + /** + * The BINARY_CONCAT function. + *

+ * The concatenation of binary strings. + * + * @param bytes1 The first binary string. + * @param bytes2 The second binary string. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryConcat(Field bytes1, byte[] bytes2) { + return new BinaryConcat(bytes1, Tools.field(bytes2)); + } + + /** + * The BINARY_CONCAT function. + *

+ * The concatenation of binary strings. + * + * @param bytes1 The first binary string. + * @param bytes2 The second binary string. + */ + @NotNull + @Support({ POSTGRES, YUGABYTEDB }) + public static Field binaryConcat(Field bytes1, Field bytes2) { + return new BinaryConcat(bytes1, bytes2); + } + /** * The BINARY_LENGTH function. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index 2eb60e96b4..3fea52acbe 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -331,6 +331,7 @@ final class Names { static final Name N_ATN2 = systemName("atn2"); static final Name N_AVG = systemName("avg"); static final Name N_BINARY_BIT_LENGTH = systemName("binary_bit_length"); + static final Name N_BINARY_CONCAT = systemName("binary_concat"); static final Name N_BINARY_LENGTH = systemName("binary_length"); static final Name N_BINARY_LTRIM = systemName("binary_ltrim"); static final Name N_BINARY_MD5 = systemName("binary_md5"); diff --git a/jOOQ/src/main/java/org/jooq/impl/Overlay.java b/jOOQ/src/main/java/org/jooq/impl/Overlay.java index 81e47ecf62..42015515de 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Overlay.java +++ b/jOOQ/src/main/java/org/jooq/impl/Overlay.java @@ -135,7 +135,7 @@ implements accept0(ctx, in, placing, startIndex, length, - DSL::length, DSL::substring, DSL::substring + DSL::length, (f1, f2) -> DSL.concat(f1, f2), DSL::substring, DSL::substring ); } @@ -146,6 +146,7 @@ implements Field startIndex, Field length, Function1, ? extends Field> fLength, + Function2, ? super Field, ? extends Field> fConcat, Function2, ? super Field, ? extends Field> fSubstring2, Function3, ? super Field, ? super Field, ? extends Field> fSubstring3 ) { @@ -171,9 +172,13 @@ implements // [#16101] TODO: Use binaryConcat() if necessary ctx.visit( - fSubstring3.apply(in, inline(1), isub(startIndex, inline(1))) - .concat(placing) - .concat(fSubstring2.apply(in, iadd(startIndex, l))) + fConcat.apply( + fConcat.apply( + fSubstring3.apply(in, inline(1), isub(startIndex, inline(1))), + placing + ), + fSubstring2.apply(in, iadd(startIndex, l)) + ) ); } else { @@ -194,11 +199,14 @@ implements NO_SUPPORT.contains(ctx.dialect()) ) { - // [#16101] TODO: Use binaryConcat() if necessary ctx.visit( - fSubstring3.apply(in, inline(1), isub(startIndex, inline(1))) - .concat(placing) - .concat(fSubstring2.apply(in, iadd(startIndex, fLength.apply(placing)))) + fConcat.apply( + fConcat.apply( + fSubstring3.apply(in, inline(1), isub(startIndex, inline(1))), + placing + ), + fSubstring2.apply(in, iadd(startIndex, fLength.apply(placing))) + ) ); } else { diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 99d0859ee4..58e89e54f6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -5844,6 +5844,43 @@ public final class QOM { @NotNull default BinaryBitLength $bytes(Field newBytes) { return $arg1(newBytes); } } + /** + * The BINARY CONCAT function. + *

+ * The concatenation of binary strings. + */ + public /*sealed*/ interface BinaryConcat + extends + UReturnsNullOnNullInput, + UOperator2, Field, BinaryConcat>, + org.jooq.Field + //permits + // BinaryConcat + { + + /** + * The first binary string. + */ + @NotNull default Field $bytes1() { return $arg1(); } + + /** + * The first binary string. + */ + @CheckReturnValue + @NotNull default BinaryConcat $bytes1(Field newBytes1) { return $arg1(newBytes1); } + + /** + * The second binary string. + */ + @NotNull default Field $bytes2() { return $arg2(); } + + /** + * The second binary string. + */ + @CheckReturnValue + @NotNull default BinaryConcat $bytes2(Field newBytes2) { return $arg2(newBytes2); } + } + /** * The BINARY LENGTH function. *