diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 994a315805..c11525c166 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -20182,6 +20182,418 @@ public class DSL { return new JSONObject(SQLDataType.JSONB, new QueryPartList<>(entries)); } + /** + * The JSON_GET_ELEMENT function. + *

+ * Access an array element from a JSON array expression. + * + * @param field is wrapped as {@link #val(Object)}. + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElement(JSON field, int index) { + return new JSONGetElement(Tools.field(field), Tools.field(index)); + } + + /** + * The JSON_GET_ELEMENT function. + *

+ * Access an array element from a JSON array expression. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElement(JSON field, Field index) { + return new JSONGetElement(Tools.field(field), index); + } + + /** + * The JSON_GET_ELEMENT function. + *

+ * Access an array element from a JSON array expression. + * + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElement(Field field, int index) { + return new JSONGetElement(field, Tools.field(index)); + } + + /** + * The JSON_GET_ELEMENT function. + *

+ * Access an array element from a JSON array expression. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElement(Field field, Field index) { + return new JSONGetElement(field, index); + } + + /** + * The JSONB_GET_ELEMENT function. + *

+ * Access an array element from a JSONB array expression. + * + * @param field is wrapped as {@link #val(Object)}. + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElement(JSONB field, int index) { + return new JSONBGetElement(Tools.field(field), Tools.field(index)); + } + + /** + * The JSONB_GET_ELEMENT function. + *

+ * Access an array element from a JSONB array expression. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElement(JSONB field, Field index) { + return new JSONBGetElement(Tools.field(field), index); + } + + /** + * The JSONB_GET_ELEMENT function. + *

+ * Access an array element from a JSONB array expression. + * + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElement(Field field, int index) { + return new JSONBGetElement(field, Tools.field(index)); + } + + /** + * The JSONB_GET_ELEMENT function. + *

+ * Access an array element from a JSONB array expression. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElement(Field field, Field index) { + return new JSONBGetElement(field, index); + } + + /** + * The JSON_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSON array expression and return it as a string. + * + * @param field is wrapped as {@link #val(Object)}. + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElementAsText(JSON field, int index) { + return new JSONGetElementAsText(Tools.field(field), Tools.field(index)); + } + + /** + * The JSON_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSON array expression and return it as a string. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElementAsText(JSON field, Field index) { + return new JSONGetElementAsText(Tools.field(field), index); + } + + /** + * The JSON_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSON array expression and return it as a string. + * + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElementAsText(Field field, int index) { + return new JSONGetElementAsText(field, Tools.field(index)); + } + + /** + * The JSON_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSON array expression and return it as a string. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetElementAsText(Field field, Field index) { + return new JSONGetElementAsText(field, index); + } + + /** + * The JSONB_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSONB array expression and return it as a string. + * + * @param field is wrapped as {@link #val(Object)}. + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElementAsText(JSONB field, int index) { + return new JSONBGetElementAsText(Tools.field(field), Tools.field(index)); + } + + /** + * The JSONB_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSONB array expression and return it as a string. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElementAsText(JSONB field, Field index) { + return new JSONBGetElementAsText(Tools.field(field), index); + } + + /** + * The JSONB_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSONB array expression and return it as a string. + * + * @param index is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElementAsText(Field field, int index) { + return new JSONBGetElementAsText(field, Tools.field(index)); + } + + /** + * The JSONB_GET_ELEMENT_AS_TEXT function. + *

+ * Access an array element from a JSONB array expression and return it as a string. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetElementAsText(Field field, Field index) { + return new JSONBGetElementAsText(field, index); + } + + /** + * The JSON_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSON object expression. + * + * @param field is wrapped as {@link #val(Object)}. + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttribute(JSON field, @Stringly.Param String attribute) { + return new JSONGetAttribute(Tools.field(field), Tools.field(attribute)); + } + + /** + * The JSON_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSON object expression. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttribute(JSON field, Field attribute) { + return new JSONGetAttribute(Tools.field(field), attribute); + } + + /** + * The JSON_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSON object expression. + * + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttribute(Field field, @Stringly.Param String attribute) { + return new JSONGetAttribute(field, Tools.field(attribute)); + } + + /** + * The JSON_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSON object expression. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttribute(Field field, Field attribute) { + return new JSONGetAttribute(field, attribute); + } + + /** + * The JSONB_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSONB object expression. + * + * @param field is wrapped as {@link #val(Object)}. + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttribute(JSONB field, @Stringly.Param String attribute) { + return new JSONBGetAttribute(Tools.field(field), Tools.field(attribute)); + } + + /** + * The JSONB_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSONB object expression. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttribute(JSONB field, Field attribute) { + return new JSONBGetAttribute(Tools.field(field), attribute); + } + + /** + * The JSONB_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSONB object expression. + * + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttribute(Field field, @Stringly.Param String attribute) { + return new JSONBGetAttribute(field, Tools.field(attribute)); + } + + /** + * The JSONB_GET_ATTRIBUTE function. + *

+ * Access an object attribute value from a JSONB object expression. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttribute(Field field, Field attribute) { + return new JSONBGetAttribute(field, attribute); + } + + /** + * The JSON_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSON object expression and return it as string. + * + * @param field is wrapped as {@link #val(Object)}. + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttributeAsText(JSON field, @Stringly.Param String attribute) { + return new JSONGetAttributeAsText(Tools.field(field), Tools.field(attribute)); + } + + /** + * The JSON_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSON object expression and return it as string. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttributeAsText(JSON field, Field attribute) { + return new JSONGetAttributeAsText(Tools.field(field), attribute); + } + + /** + * The JSON_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSON object expression and return it as string. + * + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttributeAsText(Field field, @Stringly.Param String attribute) { + return new JSONGetAttributeAsText(field, Tools.field(attribute)); + } + + /** + * The JSON_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSON object expression and return it as string. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonGetAttributeAsText(Field field, Field attribute) { + return new JSONGetAttributeAsText(field, attribute); + } + + /** + * The JSONB_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSONB object expression and return it as + * string. + * + * @param field is wrapped as {@link #val(Object)}. + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttributeAsText(JSONB field, @Stringly.Param String attribute) { + return new JSONBGetAttributeAsText(Tools.field(field), Tools.field(attribute)); + } + + /** + * The JSONB_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSONB object expression and return it as + * string. + * + * @param field is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttributeAsText(JSONB field, Field attribute) { + return new JSONBGetAttributeAsText(Tools.field(field), attribute); + } + + /** + * The JSONB_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSONB object expression and return it as + * string. + * + * @param attribute is wrapped as {@link #val(Object)}. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttributeAsText(Field field, @Stringly.Param String attribute) { + return new JSONBGetAttributeAsText(field, Tools.field(attribute)); + } + + /** + * The JSONB_GET_ATTRIBUTE_AS_TEXT function. + *

+ * Access an object attribute value from a JSONB object expression and return it as + * string. + */ + @NotNull + @Support({ MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB }) + public static Field jsonbGetAttributeAsText(Field field, Field attribute) { + return new JSONBGetAttributeAsText(field, attribute); + } + diff --git a/jOOQ/src/main/java/org/jooq/impl/HintedTable.java b/jOOQ/src/main/java/org/jooq/impl/HintedTable.java index fdb6ac21ad..19c93b3f0e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/HintedTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/HintedTable.java @@ -42,6 +42,7 @@ import org.jooq.Keyword; import org.jooq.Name; import org.jooq.Record; import org.jooq.Table; +import org.jooq.impl.QOM.Aliasable; import org.jooq.impl.QOM.UNotYetImplemented; /** @@ -105,4 +106,18 @@ final class HintedTable extends AbstractTable implements UN final FieldsImpl fields0() { return delegate.fields0(); } + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Table $aliased() { + return new HintedTable((AbstractTable) ((Aliasable>) delegate).$aliased(), keywords, arguments); + } + + @Override + public final Name $alias() { + return ((Aliasable>) delegate).$alias(); + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttribute.java b/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttribute.java new file mode 100644 index 0000000000..6ae0c1cb68 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttribute.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ATTRIBUTE statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONBGetAttribute +extends + AbstractField +implements + QOM.JSONBGetAttribute +{ + + final Field field; + final Field attribute; + + JSONBGetAttribute( + Field field, + Field attribute + ) { + super( + N_JSONB_GET_ATTRIBUTE, + allNotNull(JSONB, field, attribute) + ); + + this.field = nullSafeNotNull(field, JSONB); + this.attribute = nullSafeNotNull(attribute, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSONB, field, inline("$.").concat(attribute))); + break; + + default: + ctx.sql('(').visit(field).sql("->").visit(attribute).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $attribute() { + return attribute; + } + + @Override + public final QOM.JSONBGetAttribute $field(Field newValue) { + return $constructor().apply(newValue, $attribute()); + } + + @Override + public final QOM.JSONBGetAttribute $attribute(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONBGetAttribute> $constructor() { + return (a1, a2) -> new JSONBGetAttribute(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONBGetAttribute o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($attribute(), o.$attribute()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttributeAsText.java b/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttributeAsText.java new file mode 100644 index 0000000000..a485691778 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONBGetAttributeAsText.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ATTRIBUTE AS TEXT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONBGetAttributeAsText +extends + AbstractField +implements + QOM.JSONBGetAttributeAsText +{ + + final Field field; + final Field attribute; + + JSONBGetAttributeAsText( + Field field, + Field attribute + ) { + super( + N_JSONB_GET_ATTRIBUTE_AS_TEXT, + allNotNull(VARCHAR, field, attribute) + ); + + this.field = nullSafeNotNull(field, JSONB); + this.attribute = nullSafeNotNull(attribute, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSONB, field, inline("$.").concat(attribute))); + break; + + default: + ctx.sql('(').visit(field).sql("->>").visit(attribute).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $attribute() { + return attribute; + } + + @Override + public final QOM.JSONBGetAttributeAsText $field(Field newValue) { + return $constructor().apply(newValue, $attribute()); + } + + @Override + public final QOM.JSONBGetAttributeAsText $attribute(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONBGetAttributeAsText> $constructor() { + return (a1, a2) -> new JSONBGetAttributeAsText(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONBGetAttributeAsText o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($attribute(), o.$attribute()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONBGetElement.java b/jOOQ/src/main/java/org/jooq/impl/JSONBGetElement.java new file mode 100644 index 0000000000..1b30b6f7ff --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONBGetElement.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ELEMENT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONBGetElement +extends + AbstractField +implements + QOM.JSONBGetElement +{ + + final Field field; + final Field index; + + JSONBGetElement( + Field field, + Field index + ) { + super( + N_JSONB_GET_ELEMENT, + allNotNull(JSONB, field, index) + ); + + this.field = nullSafeNotNull(field, JSONB); + this.index = nullSafeNotNull(index, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSONB, field, inline("$[").concat(index).concat(inline("]")))); + break; + + default: + ctx.sql('(').visit(field).sql("->").visit(index).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $index() { + return index; + } + + @Override + public final QOM.JSONBGetElement $field(Field newValue) { + return $constructor().apply(newValue, $index()); + } + + @Override + public final QOM.JSONBGetElement $index(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONBGetElement> $constructor() { + return (a1, a2) -> new JSONBGetElement(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONBGetElement o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($index(), o.$index()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONBGetElementAsText.java b/jOOQ/src/main/java/org/jooq/impl/JSONBGetElementAsText.java new file mode 100644 index 0000000000..17304ca1fb --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONBGetElementAsText.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ELEMENT AS TEXT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONBGetElementAsText +extends + AbstractField +implements + QOM.JSONBGetElementAsText +{ + + final Field field; + final Field index; + + JSONBGetElementAsText( + Field field, + Field index + ) { + super( + N_JSONB_GET_ELEMENT_AS_TEXT, + allNotNull(VARCHAR, field, index) + ); + + this.field = nullSafeNotNull(field, JSONB); + this.index = nullSafeNotNull(index, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSONB, field, inline("$[").concat(index).concat(inline("]")))); + break; + + default: + ctx.sql('(').visit(field).sql("->>").visit(index).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $index() { + return index; + } + + @Override + public final QOM.JSONBGetElementAsText $field(Field newValue) { + return $constructor().apply(newValue, $index()); + } + + @Override + public final QOM.JSONBGetElementAsText $index(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONBGetElementAsText> $constructor() { + return (a1, a2) -> new JSONBGetElementAsText(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONBGetElementAsText o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($index(), o.$index()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONGetAttribute.java b/jOOQ/src/main/java/org/jooq/impl/JSONGetAttribute.java new file mode 100644 index 0000000000..a4ce3e51c3 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONGetAttribute.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ATTRIBUTE statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONGetAttribute +extends + AbstractField +implements + QOM.JSONGetAttribute +{ + + final Field field; + final Field attribute; + + JSONGetAttribute( + Field field, + Field attribute + ) { + super( + N_JSON_GET_ATTRIBUTE, + allNotNull(JSON, field, attribute) + ); + + this.field = nullSafeNotNull(field, JSON); + this.attribute = nullSafeNotNull(attribute, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSON, field, inline("$.").concat(attribute))); + break; + + default: + ctx.sql('(').visit(field).sql("->").visit(attribute).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $attribute() { + return attribute; + } + + @Override + public final QOM.JSONGetAttribute $field(Field newValue) { + return $constructor().apply(newValue, $attribute()); + } + + @Override + public final QOM.JSONGetAttribute $attribute(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONGetAttribute> $constructor() { + return (a1, a2) -> new JSONGetAttribute(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONGetAttribute o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($attribute(), o.$attribute()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONGetAttributeAsText.java b/jOOQ/src/main/java/org/jooq/impl/JSONGetAttributeAsText.java new file mode 100644 index 0000000000..c8a6a9b52f --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONGetAttributeAsText.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ATTRIBUTE AS TEXT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONGetAttributeAsText +extends + AbstractField +implements + QOM.JSONGetAttributeAsText +{ + + final Field field; + final Field attribute; + + JSONGetAttributeAsText( + Field field, + Field attribute + ) { + super( + N_JSON_GET_ATTRIBUTE_AS_TEXT, + allNotNull(VARCHAR, field, attribute) + ); + + this.field = nullSafeNotNull(field, JSON); + this.attribute = nullSafeNotNull(attribute, VARCHAR); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSON, field, inline("$.").concat(attribute))); + break; + + default: + ctx.sql('(').visit(field).sql("->>").visit(attribute).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $attribute() { + return attribute; + } + + @Override + public final QOM.JSONGetAttributeAsText $field(Field newValue) { + return $constructor().apply(newValue, $attribute()); + } + + @Override + public final QOM.JSONGetAttributeAsText $attribute(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONGetAttributeAsText> $constructor() { + return (a1, a2) -> new JSONGetAttributeAsText(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONGetAttributeAsText o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($attribute(), o.$attribute()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONGetElement.java b/jOOQ/src/main/java/org/jooq/impl/JSONGetElement.java new file mode 100644 index 0000000000..677fe40cf9 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONGetElement.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ELEMENT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONGetElement +extends + AbstractField +implements + QOM.JSONGetElement +{ + + final Field field; + final Field index; + + JSONGetElement( + Field field, + Field index + ) { + super( + N_JSON_GET_ELEMENT, + allNotNull(JSON, field, index) + ); + + this.field = nullSafeNotNull(field, JSON); + this.index = nullSafeNotNull(index, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSON, field, inline("$[").concat(index).concat(inline("]")))); + break; + + default: + ctx.sql('(').visit(field).sql("->").visit(index).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $index() { + return index; + } + + @Override + public final QOM.JSONGetElement $field(Field newValue) { + return $constructor().apply(newValue, $index()); + } + + @Override + public final QOM.JSONGetElement $index(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONGetElement> $constructor() { + return (a1, a2) -> new JSONGetElement(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONGetElement o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($index(), o.$index()) + ; + } + else + return super.equals(that); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONGetElementAsText.java b/jOOQ/src/main/java/org/jooq/impl/JSONGetElementAsText.java new file mode 100644 index 0000000000..d936f714c0 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/JSONGetElementAsText.java @@ -0,0 +1,217 @@ +/* + * 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 + * + * http://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: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +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 GET ELEMENT AS TEXT statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class JSONGetElementAsText +extends + AbstractField +implements + QOM.JSONGetElementAsText +{ + + final Field field; + final Field index; + + JSONGetElementAsText( + Field field, + Field index + ) { + super( + N_JSON_GET_ELEMENT_AS_TEXT, + allNotNull(VARCHAR, field, index) + ); + + this.field = nullSafeNotNull(field, JSON); + this.index = nullSafeNotNull(index, INTEGER); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + case MARIADB: + case MYSQL: + case SQLITE: + ctx.visit(function(N_JSON_EXTRACT, JSON, field, inline("$[").concat(index).concat(inline("]")))); + break; + + default: + ctx.sql('(').visit(field).sql("->>").visit(index).sql(')'); + break; + } + } + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: Query Object Model + // ------------------------------------------------------------------------- + + @Override + public final Field $field() { + return field; + } + + @Override + public final Field $index() { + return index; + } + + @Override + public final QOM.JSONGetElementAsText $field(Field newValue) { + return $constructor().apply(newValue, $index()); + } + + @Override + public final QOM.JSONGetElementAsText $index(Field newValue) { + return $constructor().apply($field(), newValue); + } + + public final Function2, ? super Field, ? extends QOM.JSONGetElementAsText> $constructor() { + return (a1, a2) -> new JSONGetElementAsText(a1, a2); + } + + + + + + + + + + + + + + + + + + + + + + + + + // ------------------------------------------------------------------------- + // XXX: The Object API + // ------------------------------------------------------------------------- + + @Override + public boolean equals(Object that) { + if (that instanceof QOM.JSONGetElementAsText o) { + return + StringUtils.equals($field(), o.$field()) && + StringUtils.equals($index(), o.$index()) + ; + } + 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 5159e0a2a4..a96989af0d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -392,8 +392,16 @@ final class Names { static final Name N_GOTO = systemName("goto"); static final Name N_INSERTING = systemName("inserting"); static final Name N_JSONB_ARRAY = systemName("jsonb_array"); + 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"); + static final Name N_JSONB_GET_ELEMENT_AS_TEXT= systemName("jsonb_get_element_as_text"); static final Name N_JSONB_OBJECT = systemName("jsonb_object"); static final Name N_JSON_ARRAY = systemName("json_array"); + 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"); + static final Name N_JSON_GET_ELEMENT = systemName("json_get_element"); + static final Name N_JSON_GET_ELEMENT_AS_TEXT= systemName("json_get_element_as_text"); static final Name N_JSON_OBJECT = systemName("json_object"); static final Name N_LEFT = systemName("left"); static final Name N_LEVEL = systemName("level"); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 6780ac9f70..f9de33e55b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -197,12 +197,20 @@ import static org.jooq.impl.DSL.isoDayOfWeek; import static org.jooq.impl.DSL.jsonArray; import static org.jooq.impl.DSL.jsonArrayAgg; import static org.jooq.impl.DSL.jsonExists; +import static org.jooq.impl.DSL.jsonGetAttribute; +import static org.jooq.impl.DSL.jsonGetAttributeAsText; +import static org.jooq.impl.DSL.jsonGetElement; +import static org.jooq.impl.DSL.jsonGetElementAsText; import static org.jooq.impl.DSL.jsonObject; import static org.jooq.impl.DSL.jsonObjectAgg; import static org.jooq.impl.DSL.jsonTable; import static org.jooq.impl.DSL.jsonValue; import static org.jooq.impl.DSL.jsonbArray; import static org.jooq.impl.DSL.jsonbArrayAgg; +import static org.jooq.impl.DSL.jsonbGetAttribute; +import static org.jooq.impl.DSL.jsonbGetAttributeAsText; +import static org.jooq.impl.DSL.jsonbGetElement; +import static org.jooq.impl.DSL.jsonbGetElementAsText; import static org.jooq.impl.DSL.jsonbObject; import static org.jooq.impl.DSL.jsonbObjectAgg; import static org.jooq.impl.DSL.key; @@ -593,6 +601,7 @@ import org.jooq.InsertOnDuplicateStep; import org.jooq.InsertReturningStep; import org.jooq.InsertSetStep; import org.jooq.InsertValuesStepN; +import org.jooq.JSON; import org.jooq.JSONArrayAggNullStep; import org.jooq.JSONArrayAggOrderByStep; import org.jooq.JSONArrayAggReturningStep; @@ -702,7 +711,6 @@ import org.jooq.impl.QOM.JSONOnNull; import org.jooq.impl.QOM.UEmpty; import org.jooq.impl.QOM.XMLPassingMechanism; import org.jooq.impl.ScopeStack.Value; -import org.jooq.impl.Tools.BooleanDataKey; import org.jooq.tools.StringUtils; import org.jooq.tools.reflect.Reflect; import org.jooq.types.DayToSecond; @@ -7734,18 +7742,54 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { // Any numeric operator of low precedence // See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE private final FieldOrRow parseNumericOp() { - FieldOrRow r = parseSum(); + FieldOrRow l = parseSum(); - if (r instanceof Field) + if (l instanceof Field) for (;;) if (parseIf("<<")) - r = ((Field) r).shl((Field) parseSum()); + l = ((Field) l).shl((Field) parseSum()); else if (parseIf(">>")) - r = ((Field) r).shr((Field) parseSum()); + l = ((Field) l).shr((Field) parseSum()); + else if (parseIf("->>")) { + Field r = (Field) parseSum(); + + // [#10018] We cannot really know reliably whether this is a + // index or attribute access. Let's default to the + // more popular attribute access for now. Also, + // JSONB is likely more popular than JSON. + if (r.getDataType().isNumeric()) + if (((Field) l).getType() == JSON.class) + l = jsonGetElementAsText((Field) l, r); + else + l = jsonbGetElementAsText((Field) l, r); + else + if (((Field) l).getType() == JSON.class) + l = jsonGetAttributeAsText((Field) l, r); + else + l = jsonbGetAttributeAsText((Field) l, r); + } + else if (parseIf("->")) { + Field r = (Field) parseSum(); + + // [#10018] We cannot really know reliably whether this is a + // index or attribute access. Let's default to the + // more popular attribute access for now. Also, + // JSONB is likely more popular than JSON. + if (r.getDataType().isNumeric()) + if (((Field) l).getType() == JSON.class) + l = jsonGetElement((Field) l, r); + else + l = jsonbGetElement((Field) l, r); + else + if (((Field) l).getType() == JSON.class) + l = jsonGetAttribute((Field) l, r); + else + l = jsonbGetAttribute((Field) l, r); + } else break; - return r; + return l; } private final FieldOrRow parseSum() { @@ -7755,7 +7799,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { for (;;) if (parseIf('+')) r = parseSumRightOperand(r, true); - else if (parseIf('-')) + else if (!peek("->") && parseIf('-')) r = parseSumRightOperand(r, false); else break; diff --git a/jOOQ/src/main/java/org/jooq/impl/QOM.java b/jOOQ/src/main/java/org/jooq/impl/QOM.java index 42b46ac597..05e71b0405 100644 --- a/jOOQ/src/main/java/org/jooq/impl/QOM.java +++ b/jOOQ/src/main/java/org/jooq/impl/QOM.java @@ -89,6 +89,8 @@ import org.jooq.Function9; import org.jooq.Geometry; import org.jooq.GroupField; import org.jooq.Index; +import org.jooq.JSON; +import org.jooq.JSONB; import org.jooq.JSONEntry; import org.jooq.Keyword; // ... @@ -4535,6 +4537,143 @@ public final class QOM { @NotNull JSONObject $returning(DataType returning); } + /** + * The JSON GET ELEMENT function. + *

+ * Access an array element from a JSON array expression. + */ + public /*sealed*/ interface JSONGetElement + extends + org.jooq.Field + //permits + // JSONGetElement + { + @NotNull Field $field(); + @NotNull Field $index(); + @NotNull JSONGetElement $field(Field field); + @NotNull JSONGetElement $index(Field index); + } + + /** + * The JSONB GET ELEMENT function. + *

+ * Access an array element from a JSONB array expression. + */ + public /*sealed*/ interface JSONBGetElement + extends + org.jooq.Field + //permits + // JSONBGetElement + { + @NotNull Field $field(); + @NotNull Field $index(); + @NotNull JSONBGetElement $field(Field field); + @NotNull JSONBGetElement $index(Field index); + } + + /** + * The JSON GET ELEMENT AS TEXT function. + *

+ * Access an array element from a JSON array expression and return it as a string. + */ + public /*sealed*/ interface JSONGetElementAsText + extends + org.jooq.Field + //permits + // JSONGetElementAsText + { + @NotNull Field $field(); + @NotNull Field $index(); + @NotNull JSONGetElementAsText $field(Field field); + @NotNull JSONGetElementAsText $index(Field index); + } + + /** + * The JSONB GET ELEMENT AS TEXT function. + *

+ * Access an array element from a JSONB array expression and return it as a string. + */ + public /*sealed*/ interface JSONBGetElementAsText + extends + org.jooq.Field + //permits + // JSONBGetElementAsText + { + @NotNull Field $field(); + @NotNull Field $index(); + @NotNull JSONBGetElementAsText $field(Field field); + @NotNull JSONBGetElementAsText $index(Field index); + } + + /** + * The JSON GET ATTRIBUTE function. + *

+ * Access an object attribute value from a JSON object expression. + */ + public /*sealed*/ interface JSONGetAttribute + extends + org.jooq.Field + //permits + // JSONGetAttribute + { + @NotNull Field $field(); + @NotNull Field $attribute(); + @NotNull JSONGetAttribute $field(Field field); + @NotNull JSONGetAttribute $attribute(Field attribute); + } + + /** + * The JSONB GET ATTRIBUTE function. + *

+ * Access an object attribute value from a JSONB object expression. + */ + public /*sealed*/ interface JSONBGetAttribute + extends + org.jooq.Field + //permits + // JSONBGetAttribute + { + @NotNull Field $field(); + @NotNull Field $attribute(); + @NotNull JSONBGetAttribute $field(Field field); + @NotNull JSONBGetAttribute $attribute(Field attribute); + } + + /** + * The JSON GET ATTRIBUTE AS TEXT function. + *

+ * Access an object attribute value from a JSON object expression and return it as string. + */ + public /*sealed*/ interface JSONGetAttributeAsText + extends + org.jooq.Field + //permits + // JSONGetAttributeAsText + { + @NotNull Field $field(); + @NotNull Field $attribute(); + @NotNull JSONGetAttributeAsText $field(Field field); + @NotNull JSONGetAttributeAsText $attribute(Field attribute); + } + + /** + * The JSONB GET ATTRIBUTE AS TEXT function. + *

+ * Access an object attribute value from a JSONB object expression and return it as + * string. + */ + public /*sealed*/ interface JSONBGetAttributeAsText + extends + org.jooq.Field + //permits + // JSONBGetAttributeAsText + { + @NotNull Field $field(); + @NotNull Field $attribute(); + @NotNull JSONBGetAttributeAsText $field(Field field); + @NotNull JSONBGetAttributeAsText $attribute(Field attribute); + } + diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index 0373c8541f..350ca583d5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -318,6 +318,7 @@ import org.jooq.WindowSpecification; import org.jooq.XML; import org.jooq.conf.BackslashEscaping; import org.jooq.conf.NestedCollectionEmulation; +import org.jooq.conf.ParamType; import org.jooq.conf.ParseNameCase; import org.jooq.conf.RenderDefaultNullability; import org.jooq.conf.RenderMapping; @@ -5792,6 +5793,13 @@ final class Tools { return VARCHAR(length).nullability(type.nullability()).defaultValue((Field) type.defaultValue()); } + static final > C prependInline(C ctx, String prepend, Field inline, String append) { + if (inline instanceof Param p) + return ctx.visit(DSL.inline(prepend + p.getValue() + append)); + else + return ctx.visit(DSL.inline(prepend).concat(inline).concat(DSL.inline(append)), ParamType.INLINED); + } + static final > C prependSQL(C ctx, Query... queries) { return preOrAppendSQL(SimpleDataKey.DATA_PREPEND_SQL, ctx, queries); }