diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index f607e03f12..b4d9cf677a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -18114,7 +18114,7 @@ public class DSL { */ @Support({ POSTGRES }) @SafeVarargs - public static Field xmlconcat(Field... fields) { + public static Field xmlconcat(Field... fields) { return xmlconcat(asList(fields)); } @@ -18122,7 +18122,7 @@ public class DSL { * The XML concat function. */ @Support({ POSTGRES }) - public static Field xmlconcat(Collection> fields) { + public static Field xmlconcat(Collection> fields) { return new XMLConcat(fields); } @@ -18131,6 +18131,14 @@ public class DSL { */ @Support({ POSTGRES }) public static Field xmlelement(String name, Field... content) { + return xmlelement(name(name), (XMLAttributes) null, asList(content)); + } + + /** + * The XML element constructor. + */ + @Support({ POSTGRES }) + public static Field xmlelement(String name, Collection> content) { return xmlelement(name(name), (XMLAttributes) null, content); } @@ -18139,6 +18147,14 @@ public class DSL { */ @Support({ POSTGRES }) public static Field xmlelement(Name name, Field... content) { + return xmlelement(name, (XMLAttributes) null, asList(content)); + } + + /** + * The XML element constructor. + */ + @Support({ POSTGRES }) + public static Field xmlelement(Name name, Collection> content) { return xmlelement(name, (XMLAttributes) null, content); } @@ -18147,6 +18163,14 @@ public class DSL { */ @Support({ POSTGRES }) public static Field xmlelement(String name, XMLAttributes attributes, Field... content) { + return xmlelement(name(name), attributes, asList(content)); + } + + /** + * The XML element constructor. + */ + @Support({ POSTGRES }) + public static Field xmlelement(String name, XMLAttributes attributes, Collection> content) { return xmlelement(name(name), attributes, content); } @@ -18155,6 +18179,14 @@ public class DSL { */ @Support({ POSTGRES }) public static Field xmlelement(Name name, XMLAttributes attributes, Field... content) { + return xmlelement(name, attributes, asList(content)); + } + + /** + * The XML element constructor. + */ + @Support({ POSTGRES }) + public static Field xmlelement(Name name, XMLAttributes attributes, Collection> content) { return new XMLElement(name, attributes, content); } @@ -18163,6 +18195,14 @@ public class DSL { */ @Support({ POSTGRES }) public static XMLAttributes xmlattributes(Field... attributes) { + return xmlattributes(asList(attributes)); + } + + /** + * The XML attributes constructor. + */ + @Support({ POSTGRES }) + public static XMLAttributes xmlattributes(Collection> attributes) { return new XMLAttributesImpl(attributes); } diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 3dcdf6d61c..67fc391dad 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -291,6 +291,10 @@ import static org.jooq.impl.DSL.varSamp; import static org.jooq.impl.DSL.week; import static org.jooq.impl.DSL.when; // ... +import static org.jooq.impl.DSL.xmlattributes; +import static org.jooq.impl.DSL.xmlcomment; +import static org.jooq.impl.DSL.xmlconcat; +import static org.jooq.impl.DSL.xmlelement; import static org.jooq.impl.DSL.year; import static org.jooq.impl.DSL.zero; import static org.jooq.impl.JSONNullClause.ABSENT_ON_NULL; @@ -306,6 +310,7 @@ import static org.jooq.impl.ParserImpl.Type.J; import static org.jooq.impl.ParserImpl.Type.N; import static org.jooq.impl.ParserImpl.Type.S; import static org.jooq.impl.ParserImpl.Type.X; +import static org.jooq.impl.ParserImpl.Type.Y; import static org.jooq.impl.SQLDataType.BIGINT; import static org.jooq.impl.SQLDataType.INTEGER; import static org.jooq.impl.Tools.EMPTY_BYTE; @@ -501,6 +506,7 @@ import org.jooq.WindowSpecificationExcludeStep; import org.jooq.WindowSpecificationOrderByStep; import org.jooq.WindowSpecificationRowsAndStep; import org.jooq.WindowSpecificationRowsStep; +import org.jooq.XMLAttributes; import org.jooq.conf.ParseSearchSchema; import org.jooq.conf.ParseUnknownFunctions; import org.jooq.conf.ParseUnsupportedSyntax; @@ -5561,8 +5567,9 @@ final class ParserImpl implements Parser { S("string"), N("numeric"), B("boolean"), - X("binary"), - J("json"); + Y("binary"), + J("json"), + X("xml"); private final String name; @@ -6382,10 +6389,18 @@ final class ParserImpl implements Parser { case 'x': case 'X': - if (X.is(type)) + if (Y.is(type)) if ((value = parseBinaryLiteralIf(ctx)) != null) return inline((byte[]) value); + if (X.is(type)) + if ((field = parseFieldXMLCommentIf(ctx)) != null) + return field; + else if ((field = parseFieldXMLConcatIf(ctx)) != null) + return field; + else if ((field = parseFieldXMLElementIf(ctx)) != null) + return field; + break; case 'y': @@ -6678,8 +6693,77 @@ final class ParserImpl implements Parser { CURRVAL; } + private static final Field parseFieldXMLCommentIf(ParserContext ctx) { + if (parseFunctionNameIf(ctx, "XMLCOMMENT")) { + parse(ctx, '('); + Field comment = (Field) parseField(ctx); + parse(ctx, ')'); + + return xmlcomment(comment); + } + + return null; + } + + private static final Field parseFieldXMLConcatIf(ParserContext ctx) { + if (parseFunctionNameIf(ctx, "XMLCONCAT")) { + parse(ctx, '('); + List> fields = parseFields(ctx); + parse(ctx, ')'); + + return xmlconcat(fields); + } + + return null; + } + + private static final Field parseFieldXMLElementIf(ParserContext ctx) { + if (parseFunctionNameIf(ctx, "XMLELEMENT")) { + parse(ctx, '('); + parseKeyword(ctx, "NAME"); + Name name = parseIdentifier(ctx); + XMLAttributes attr = null; + List> content = new ArrayList<>(); + + while (parseIf(ctx, ',')) { + if (attr == null && parseKeywordIf(ctx, "XMLATTRIBUTES")) { + List> attrs = new ArrayList<>(); + + parse(ctx, '('); + + do { + Name alias = null; + Field field = null; + + if (field == null) { + field = parseField(ctx); + + if (parseKeywordIf(ctx, "AS")) + alias = parseIdentifier(ctx, true); + } + + attrs.add(alias == null ? field : field.as(alias)); + } + while (parseIf(ctx, ',')); + + parse(ctx, ')'); + attr = xmlattributes(attrs); + } + else + content.add(parseField(ctx)); + } + parse(ctx, ')'); + + return attr == null + ? xmlelement(name, content) + : xmlelement(name, attr, content); + } + + return null; + } + private static final Field parseFieldJSONArrayConstructorIf(ParserContext ctx) { - if (parseKeywordIf(ctx, "JSON_ARRAY")) { + if (parseFunctionNameIf(ctx, "JSON_ARRAY")) { parse(ctx, '('); if (parseIf(ctx, ')')) return DSL.jsonArray(); @@ -6706,7 +6790,7 @@ final class ParserImpl implements Parser { } private static final Field parseFieldJSONArrayAggIf(ParserContext ctx) { - if (parseKeywordIf(ctx, "JSON_ARRAYAGG")) { + if (parseFunctionNameIf(ctx, "JSON_ARRAYAGG")) { Field result; JSONArrayAggOrderByStep s1; JSONArrayAggNullStep s2; @@ -6759,7 +6843,7 @@ final class ParserImpl implements Parser { } private static final Field parseFieldJSONObjectAggIf(ParserContext ctx) { - if (parseKeywordIf(ctx, "JSON_OBJECTAGG")) { + if (parseFunctionNameIf(ctx, "JSON_OBJECTAGG")) { Field result; JSONObjectAggNullStep s1; JSONNullClause nullClause; diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java b/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java index 1ffe15bb0b..6baee1658a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java @@ -39,6 +39,8 @@ package org.jooq.impl; import static org.jooq.impl.Names.N_XMLATTRIBUTES; +import java.util.Collection; + import org.jooq.Context; import org.jooq.Field; import org.jooq.XMLAttributes; @@ -55,7 +57,7 @@ final class XMLAttributesImpl extends AbstractQueryPart implements XMLAttributes final SelectFieldList> attributes; - XMLAttributesImpl(Field... attributes) { + XMLAttributesImpl(Collection> attributes) { this.attributes = new SelectFieldList<>(attributes); } diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLConcat.java b/jOOQ/src/main/java/org/jooq/impl/XMLConcat.java index 73fcc32582..1ef4adbb25 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLConcat.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLConcat.java @@ -53,10 +53,10 @@ final class XMLConcat extends AbstractField { /** * Generated UID */ - private static final long serialVersionUID = 4505809303211506197L; - private final QueryPartList> args; + private static final long serialVersionUID = 4505809303211506197L; + private final QueryPartList> args; - XMLConcat(Collection> args) { + XMLConcat(Collection> args) { super(N_XMLCONCAT, SQLDataType.XML); this.args = new QueryPartList<>(args); diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLElement.java b/jOOQ/src/main/java/org/jooq/impl/XMLElement.java index e56f5bafb1..c215f0e965 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLElement.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLElement.java @@ -41,6 +41,8 @@ import static org.jooq.impl.Names.N_NAME; import static org.jooq.impl.Names.N_XMLCONCAT; import static org.jooq.impl.Names.N_XMLELEMENT; +import java.util.Collection; + import org.jooq.Context; import org.jooq.Field; import org.jooq.Name; @@ -60,7 +62,7 @@ final class XMLElement extends AbstractField { private final XMLAttributes attributes; private final QueryPartList> content; - XMLElement(Name elementName, XMLAttributes attributes, Field[] content) { + XMLElement(Name elementName, XMLAttributes attributes, Collection> content) { super(N_XMLCONCAT, SQLDataType.XML); this.elementName = elementName;