[jOOQ/jOOQ#16101] Add support for binaryConcat()
This commit is contained in:
parent
bc1b4fcc72
commit
c1ffc7b7b3
167
jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java
Normal file
167
jOOQ/src/main/java/org/jooq/impl/BinaryConcat.java
Normal file
@ -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 <code>BINARY CONCAT</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class BinaryConcat
|
||||
extends
|
||||
AbstractField<byte[]>
|
||||
implements
|
||||
QOM.BinaryConcat
|
||||
{
|
||||
|
||||
final Field<byte[]> bytes1;
|
||||
final Field<byte[]> bytes2;
|
||||
|
||||
BinaryConcat(
|
||||
Field<byte[]> bytes1,
|
||||
Field<byte[]> 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<byte[]> $arg1() {
|
||||
return bytes1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<byte[]> $arg2() {
|
||||
return bytes2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BinaryConcat $arg1(Field<byte[]> newValue) {
|
||||
return $constructor().apply(newValue, $arg2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QOM.BinaryConcat $arg2(Field<byte[]> newValue) {
|
||||
return $constructor().apply($arg1(), newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Function2<? super Field<byte[]>, ? super Field<byte[]>, ? 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);
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -20922,6 +20922,62 @@ public class DSL {
|
||||
return new BinaryBitLength(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY_CONCAT</code> function.
|
||||
* <p>
|
||||
* The concatenation of binary strings.
|
||||
*
|
||||
* @param bytes1 The first binary string.
|
||||
* @param bytes2 The second binary string.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ POSTGRES, YUGABYTEDB })
|
||||
public static Field<byte[]> binaryConcat(byte[] bytes1, byte[] bytes2) {
|
||||
return new BinaryConcat(Tools.field(bytes1), Tools.field(bytes2));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY_CONCAT</code> function.
|
||||
* <p>
|
||||
* The concatenation of binary strings.
|
||||
*
|
||||
* @param bytes1 The first binary string.
|
||||
* @param bytes2 The second binary string.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ POSTGRES, YUGABYTEDB })
|
||||
public static Field<byte[]> binaryConcat(byte[] bytes1, Field<byte[]> bytes2) {
|
||||
return new BinaryConcat(Tools.field(bytes1), bytes2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY_CONCAT</code> function.
|
||||
* <p>
|
||||
* The concatenation of binary strings.
|
||||
*
|
||||
* @param bytes1 The first binary string.
|
||||
* @param bytes2 The second binary string.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ POSTGRES, YUGABYTEDB })
|
||||
public static Field<byte[]> binaryConcat(Field<byte[]> bytes1, byte[] bytes2) {
|
||||
return new BinaryConcat(bytes1, Tools.field(bytes2));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY_CONCAT</code> function.
|
||||
* <p>
|
||||
* The concatenation of binary strings.
|
||||
*
|
||||
* @param bytes1 The first binary string.
|
||||
* @param bytes2 The second binary string.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ POSTGRES, YUGABYTEDB })
|
||||
public static Field<byte[]> binaryConcat(Field<byte[]> bytes1, Field<byte[]> bytes2) {
|
||||
return new BinaryConcat(bytes1, bytes2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY_LENGTH</code> function.
|
||||
* <p>
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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<? extends Number> startIndex,
|
||||
Field<? extends Number> length,
|
||||
Function1<? super Field<T>, ? extends Field<? extends Number>> fLength,
|
||||
Function2<? super Field<T>, ? super Field<T>, ? extends Field<T>> fConcat,
|
||||
Function2<? super Field<T>, ? super Field<? extends Number>, ? extends Field<T>> fSubstring2,
|
||||
Function3<? super Field<T>, ? super Field<? extends Number>, ? super Field<? extends Number>, ? extends Field<T>> 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 {
|
||||
|
||||
@ -5844,6 +5844,43 @@ public final class QOM {
|
||||
@NotNull default BinaryBitLength $bytes(Field<byte[]> newBytes) { return $arg1(newBytes); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY CONCAT</code> function.
|
||||
* <p>
|
||||
* The concatenation of binary strings.
|
||||
*/
|
||||
public /*sealed*/ interface BinaryConcat
|
||||
extends
|
||||
UReturnsNullOnNullInput,
|
||||
UOperator2<Field<byte[]>, Field<byte[]>, BinaryConcat>,
|
||||
org.jooq.Field<byte[]>
|
||||
//permits
|
||||
// BinaryConcat
|
||||
{
|
||||
|
||||
/**
|
||||
* The first binary string.
|
||||
*/
|
||||
@NotNull default Field<byte[]> $bytes1() { return $arg1(); }
|
||||
|
||||
/**
|
||||
* The first binary string.
|
||||
*/
|
||||
@CheckReturnValue
|
||||
@NotNull default BinaryConcat $bytes1(Field<byte[]> newBytes1) { return $arg1(newBytes1); }
|
||||
|
||||
/**
|
||||
* The second binary string.
|
||||
*/
|
||||
@NotNull default Field<byte[]> $bytes2() { return $arg2(); }
|
||||
|
||||
/**
|
||||
* The second binary string.
|
||||
*/
|
||||
@CheckReturnValue
|
||||
@NotNull default BinaryConcat $bytes2(Field<byte[]> newBytes2) { return $arg2(newBytes2); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>BINARY LENGTH</code> function.
|
||||
* <p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user