diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index c606d11545..297430d31d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -23312,6 +23312,54 @@ public class DSL { return new JSONBGetAttributeAsText(field, attribute); } + /** + * The JSON_ARRAY_LENGTH function. + *

+ * Calculate the length of a JSON array. + * + * @param field is wrapped as {@link DSL#val(Object)}. + */ + @NotNull + @Support + public static Field jsonArrayLength(JSON field) { + return new JSONArrayLength(Tools.field(field)); + } + + /** + * The JSON_ARRAY_LENGTH function. + *

+ * Calculate the length of a JSON array. + */ + @NotNull + @Support + public static Field jsonArrayLength(Field field) { + return new JSONArrayLength(field); + } + + /** + * The JSONB_ARRAY_LENGTH function. + *

+ * Calculate the length of a JSONB array. + * + * @param field is wrapped as {@link DSL#val(Object)}. + */ + @NotNull + @Support + public static Field jsonbArrayLength(JSONB field) { + return new JSONBArrayLength(Tools.field(field)); + } + + /** + * The JSONB_ARRAY_LENGTH function. + *

+ * Calculate the length of a JSONB array. + */ + @NotNull + @Support + public static Field jsonbArrayLength(Field field) { + return new JSONBArrayLength(field); + } + /** * The JSON_KEYS function. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONArrayLength.java b/jOOQ/src/main/java/org/jooq/impl/JSONArrayLength.java new file mode 100644 index 0000000000..17b91cbad1 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONArrayLength.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 JSON ARRAY LENGTH statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONArrayLength +extends + AbstractField +implements + QOM.JSONArrayLength +{ + + final Field field; + + JSONArrayLength( + Field field + ) { + super( + N_JSON_ARRAY_LENGTH, + allNotNull(INTEGER, field) + ); + + this.field = nullSafeNotNull(field, JSON); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + case POSTGRES: + case YUGABYTEDB: + ctx.visit(function(N_JSON_ARRAY_LENGTH, getDataType(), field)); + break; + + default: + ctx.visit(function(N_JSON_ARRAY_LENGTH, getDataType(), field)); + break; + } + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return field; + } + + @Override + public final QOM.JSONArrayLength $arg1(Field newValue) { + return $constructor().apply(newValue); + } + + @Override + public final Function1, ? extends QOM.JSONArrayLength> $constructor() { + return (a1) -> new JSONArrayLength(a1); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONArrayLength o) { + return + StringUtils.equals($field(), o.$field()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONBArrayLength.java b/jOOQ/src/main/java/org/jooq/impl/JSONBArrayLength.java new file mode 100644 index 0000000000..aeacb247b4 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONBArrayLength.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 JSONB ARRAY LENGTH statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONBArrayLength +extends + AbstractField +implements + QOM.JSONBArrayLength +{ + + final Field field; + + JSONBArrayLength( + Field field + ) { + super( + N_JSONB_ARRAY_LENGTH, + allNotNull(INTEGER, field) + ); + + this.field = nullSafeNotNull(field, JSONB); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + final boolean parenthesised(Context ctx) { + return true; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + case POSTGRES: + case YUGABYTEDB: + ctx.visit(function(N_JSONB_ARRAY_LENGTH, getDataType(), field)); + break; + + default: + ctx.visit(function(N_JSONB_ARRAY_LENGTH, getDataType(), field)); + break; + } + } + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $arg1() { + return field; + } + + @Override + public final QOM.JSONBArrayLength $arg1(Field newValue) { + return $constructor().apply(newValue); + } + + @Override + public final Function1, ? extends QOM.JSONBArrayLength> $constructor() { + return (a1) -> new JSONBArrayLength(a1); + } + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONBArrayLength o) { + return + StringUtils.equals($field(), o.$field()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index 3fea52acbe..ff5b464120 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -431,6 +431,7 @@ final class Names { static final Name N_INSTR = systemName("instr"); static final Name N_ISJSON = systemName("isjson"); static final Name N_JSONB_ARRAY = systemName("jsonb_array"); + static final Name N_JSONB_ARRAY_LENGTH = systemName("jsonb_array_length"); static final Name N_JSONB_GET_ATTRIBUTE = systemName("jsonb_get_attribute"); static final Name N_JSONB_GET_ATTRIBUTE_AS_TEXT = systemName("jsonb_get_attribute_as_text"); static final Name N_JSONB_GET_ELEMENT = systemName("jsonb_get_element"); @@ -442,6 +443,7 @@ final class Names { static final Name N_JSONB_REPLACE = systemName("jsonb_replace"); static final Name N_JSONB_SET = systemName("jsonb_set"); static final Name N_JSON_ARRAY = systemName("json_array"); + static final Name N_JSON_ARRAY_LENGTH = systemName("json_array_length"); static final Name N_JSON_EXTRACT = systemName("json_extract"); static final Name N_JSON_GET_ATTRIBUTE = systemName("json_get_attribute"); static final Name N_JSON_GET_ATTRIBUTE_AS_TEXT = systemName("json_get_attribute_as_text"); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 9551f378c7..2130bd8182 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -8964,6 +8964,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return field; else if ((field = parseFieldJSONLiteralIf()) != null) return field; + else if (parseFunctionNameIf("JSON_ARRAY_LENGTH")) + return parseFunctionArgs1(DSL::jsonArrayLength); else if (parseFunctionNameIf("JSON_KEYS")) return parseFunctionArgs1(DSL::jsonKeys); else if (parseFunctionNameIf("JSON_INSERT")) @@ -8976,6 +8978,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { return parseFunctionArgs3(DSL::jsonSet); else if (parseFunctionNameIf("JSON_VALID")) return parseFunctionArgs1(f -> case_(f.isJson()).when(trueCondition(), one()).when(falseCondition(), zero())); + else if (parseFunctionNameIf("JSONB_ARRAY_LENGTH")) + return parseFunctionArgs1(DSL::jsonbArrayLength); else if (parseFunctionNameIf("JSONB_KEYS")) return parseFunctionArgs1(DSL::jsonbKeys); else if (parseFunctionNameIf("JSONB_INSERT")) diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 58e89e54f6..d69cac698b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -6971,6 +6971,42 @@ public final class QOM { @NotNull default JSONBGetAttributeAsText $attribute(Field newAttribute) { return $arg2(newAttribute); } } + /** + * The JSON ARRAY LENGTH function. + *

+ * Calculate the length of a JSON array. + */ + public /*sealed*/ interface JSONArrayLength + extends + UReturnsNullOnNullInput, + UOperator1, JSONArrayLength>, + org.jooq.Field + //permits + // JSONArrayLength + { + @NotNull default Field $field() { return $arg1(); } + @CheckReturnValue + @NotNull default JSONArrayLength $field(Field newField) { return $arg1(newField); } + } + + /** + * The JSONB ARRAY LENGTH function. + *

+ * Calculate the length of a JSONB array. + */ + public /*sealed*/ interface JSONBArrayLength + extends + UReturnsNullOnNullInput, + UOperator1, JSONBArrayLength>, + org.jooq.Field + //permits + // JSONBArrayLength + { + @NotNull default Field $field() { return $arg1(); } + @CheckReturnValue + @NotNull default JSONBArrayLength $field(Field newField) { return $arg1(newField); } + } + /** * The JSON KEYS function. *