[jOOQ/jOOQ#11981] Support ARRAY_APPEND and ARRAY_PREPEND

This commit is contained in:
Lukas Eder 2022-12-13 17:33:51 +01:00
parent a1a67a0b17
commit b7c2c5e347
7 changed files with 548 additions and 14 deletions

View File

@ -0,0 +1,172 @@
/*
* 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>ARRAY APPEND</code> statement.
*/
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class ArrayAppend<T>
extends
AbstractField<T[]>
implements
QOM.ArrayAppend<T>
{
final Field<T[]> arg1;
final Field<T> arg2;
ArrayAppend(
Field<T[]> arg1,
Field<T> arg2
) {
super(
N_ARRAY_APPEND,
allNotNull(((DataType) OTHER).getArrayDataType(), arg1, arg2)
);
this.arg1 = nullSafeNotNull(arg1, ((DataType) OTHER).getArrayDataType());
this.arg2 = nullSafeNotNull(arg2, (DataType) OTHER);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
final boolean parenthesised(Context<?> ctx) {
return true;
}
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
default:
ctx.visit(function(N_ARRAY_APPEND, getDataType(), arg1, arg2));
break;
}
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@Override
public final Field<T[]> $arg1() {
return arg1;
}
@Override
public final Field<T> $arg2() {
return arg2;
}
@Override
public final QOM.ArrayAppend<T> $arg1(Field<T[]> newValue) {
return $constructor().apply(newValue, $arg2());
}
@Override
public final QOM.ArrayAppend<T> $arg2(Field<T> newValue) {
return $constructor().apply($arg1(), newValue);
}
@Override
public final Function2<? super Field<T[]>, ? super Field<T>, ? extends QOM.ArrayAppend<T>> $constructor() {
return (a1, a2) -> new ArrayAppend<>(a1, a2);
}
// -------------------------------------------------------------------------
// XXX: The Object API
// -------------------------------------------------------------------------
@Override
public boolean equals(Object that) {
if (that instanceof QOM.ArrayAppend<?> o) {
return
StringUtils.equals($arg1(), o.$arg1()) &&
StringUtils.equals($arg2(), o.$arg2())
;
}
else
return super.equals(that);
}
}

View File

@ -0,0 +1,172 @@
/*
* 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>ARRAY PREPEND</code> statement.
*/
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
final class ArrayPrepend<T>
extends
AbstractField<T[]>
implements
QOM.ArrayPrepend<T>
{
final Field<T> arg1;
final Field<T[]> arg2;
ArrayPrepend(
Field<T> arg1,
Field<T[]> arg2
) {
super(
N_ARRAY_PREPEND,
allNotNull(((DataType) OTHER).getArrayDataType(), arg1, arg2)
);
this.arg1 = nullSafeNotNull(arg1, (DataType) OTHER);
this.arg2 = nullSafeNotNull(arg2, ((DataType) OTHER).getArrayDataType());
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
final boolean parenthesised(Context<?> ctx) {
return true;
}
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
default:
ctx.visit(function(N_ARRAY_PREPEND, getDataType(), arg1, arg2));
break;
}
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@Override
public final Field<T> $arg1() {
return arg1;
}
@Override
public final Field<T[]> $arg2() {
return arg2;
}
@Override
public final QOM.ArrayPrepend<T> $arg1(Field<T> newValue) {
return $constructor().apply(newValue, $arg2());
}
@Override
public final QOM.ArrayPrepend<T> $arg2(Field<T[]> newValue) {
return $constructor().apply($arg1(), newValue);
}
@Override
public final Function2<? super Field<T>, ? super Field<T[]>, ? extends QOM.ArrayPrepend<T>> $constructor() {
return (a1, a2) -> new ArrayPrepend<>(a1, a2);
}
// -------------------------------------------------------------------------
// XXX: The Object API
// -------------------------------------------------------------------------
@Override
public boolean equals(Object that) {
if (that instanceof QOM.ArrayPrepend<?> o) {
return
StringUtils.equals($arg1(), o.$arg1()) &&
StringUtils.equals($arg2(), o.$arg2())
;
}
else
return super.equals(that);
}
}

View File

@ -19736,6 +19736,102 @@ public class DSL {
return new ArrayConcat<>(arg1, arg2);
}
/**
* The <code>ARRAY_APPEND</code> function.
* <p>
* Append an element to an array.
*
* @param arg2 is wrapped as {@link #val(Object)}.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(T[] arg1, T arg2) {
return new ArrayAppend<>(Tools.field(arg1), Tools.field(arg2));
}
/**
* The <code>ARRAY_APPEND</code> function.
* <p>
* Append an element to an array.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(T[] arg1, Field<T> arg2) {
return new ArrayAppend<>(Tools.field(arg1), arg2);
}
/**
* The <code>ARRAY_APPEND</code> function.
* <p>
* Append an element to an array.
*
* @param arg2 is wrapped as {@link #val(Object)}.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(Field<T[]> arg1, T arg2) {
return new ArrayAppend<>(arg1, Tools.field(arg2));
}
/**
* The <code>ARRAY_APPEND</code> function.
* <p>
* Append an element to an array.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(Field<T[]> arg1, Field<T> arg2) {
return new ArrayAppend<>(arg1, arg2);
}
/**
* The <code>ARRAY_PREPEND</code> function.
* <p>
* Prepend an element to an array.
*
* @param arg1 is wrapped as {@link #val(Object)}.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(T arg1, T[] arg2) {
return new ArrayPrepend<>(Tools.field(arg1), Tools.field(arg2));
}
/**
* The <code>ARRAY_PREPEND</code> function.
* <p>
* Prepend an element to an array.
*
* @param arg1 is wrapped as {@link #val(Object)}.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(T arg1, Field<T[]> arg2) {
return new ArrayPrepend<>(Tools.field(arg1), arg2);
}
/**
* The <code>ARRAY_PREPEND</code> function.
* <p>
* Prepend an element to an array.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(Field<T> arg1, T[] arg2) {
return new ArrayPrepend<>(arg1, Tools.field(arg2));
}
/**
* The <code>ARRAY_PREPEND</code> function.
* <p>
* Prepend an element to an array.
*/
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(Field<T> arg1, Field<T[]> arg2) {
return new ArrayPrepend<>(arg1, arg2);
}
/**
* The <code>ARRAY_OVERLAP</code> function.
* <p>

View File

@ -345,9 +345,11 @@ final class Names {
static final Name N_ACOSH = systemName("acosh");
static final Name N_ACOTH = systemName("acoth");
static final Name N_ANY_VALUE = systemName("any_value");
static final Name N_ARRAY_APPEND = systemName("array_append");
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_ARRAY_PREPEND = systemName("array_prepend");
static final Name N_ARRAY_REMOVE = systemName("array_remove");
static final Name N_ASCII = systemName("ascii");
static final Name N_ASIN = systemName("asin");

View File

@ -79,8 +79,10 @@ import static org.jooq.impl.DSL.any;
import static org.jooq.impl.DSL.anyValue;
import static org.jooq.impl.DSL.arrayAgg;
import static org.jooq.impl.DSL.arrayAggDistinct;
import static org.jooq.impl.DSL.arrayAppend;
import static org.jooq.impl.DSL.arrayConcat;
import static org.jooq.impl.DSL.arrayGet;
import static org.jooq.impl.DSL.arrayPrepend;
import static org.jooq.impl.DSL.arrayRemove;
import static org.jooq.impl.DSL.ascii;
import static org.jooq.impl.DSL.asin;
@ -8351,6 +8353,10 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
return parseFunctionArgs2((f1, f2) -> arrayConcat(f1, f2));
else if (parseFunctionNameIf("ARRAY_REMOVE"))
return parseFunctionArgs2((f1, f2) -> arrayRemove((Field<Void[]>) f1, (Field<Void>) f2));
else if (parseFunctionNameIf("ARRAY_APPEND"))
return parseFunctionArgs2((f1, f2) -> arrayAppend((Field<Void[]>) f1, (Field<Void>) f2));
else if (parseFunctionNameIf("ARRAY_PREPEND"))
return parseFunctionArgs2((f1, f2) -> arrayPrepend((Field<Void>) f1, (Field<Void[]>) f2));
break;

View File

@ -4841,6 +4841,32 @@ public final class QOM {
// ArrayConcat
{}
/**
* The <code>ARRAY APPEND</code> function.
* <p>
* Append an element to an array.
*/
public /*sealed*/ interface ArrayAppend<T>
extends
UOperator2<Field<T[]>, Field<T>, Field<T[]>>,
org.jooq.Field<T[]>
//permits
// ArrayAppend
{}
/**
* The <code>ARRAY PREPEND</code> function.
* <p>
* Prepend an element to an array.
*/
public /*sealed*/ interface ArrayPrepend<T>
extends
UOperator2<Field<T>, Field<T[]>, Field<T[]>>,
org.jooq.Field<T[]>
//permits
// ArrayPrepend
{}
/**
* The <code>ARRAY OVERLAP</code> function.
* <p>

View File

@ -155,10 +155,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_append(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_append(ARRAY[1, 2], 3)
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayAppend(Object[], Object)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(T[] array, T value) {
@ -168,10 +176,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_append(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_append(ARRAY[1, 2], 3)
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Object[], Field)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(T[] array, Field<T> value) {
@ -181,10 +197,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_append(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_append(ARRAY[1, 2], 3)
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Field, Object)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(Field<T[]> array, T value) {
@ -194,10 +218,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_append(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_append(ARRAY[1, 2], 3)
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Field, Field)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayAppend(Field<T[]> array, Field<T> value) {
@ -213,10 +245,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_prepend(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_prepend(1, ARRAY[2, 3])
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Object, Object[])} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(T value, T[] array) {
@ -226,10 +266,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_prepend(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_prepend(1, ARRAY[2, 3])
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Field, Object[])} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(Field<T> value, T[] array) {
@ -242,7 +290,11 @@ public class PostgresDSL extends DSL {
* Example: <pre><code>
* {1, 2, 3} = array_prepend(1, ARRAY[2, 3])
* </code></pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Object, Field)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(T value, Field<T[]> array) {
@ -252,10 +304,18 @@ public class PostgresDSL extends DSL {
/**
* The PostgreSQL <code>array_prepend(anyarray, anyelement)</code> function.
* <p>
* Example: <pre><code>
* Example:
*
* <pre>
* <code>
* {1, 2, 3} = array_prepend(1, ARRAY[2, 3])
* </code></pre>
* </code>
* </pre>
*
* @deprecated - 3.16.0 - [#14388] - Use
* {@link DSL#arrayPrepend(Field, Field)} instead.
*/
@Deprecated
@NotNull
@Support({ POSTGRES, YUGABYTEDB })
public static <T> Field<T[]> arrayPrepend(Field<T> value, Field<T[]> array) {