diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index ca7d66027c..0fe51477e5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -18254,6 +18254,14 @@ public class DSL { return new XMLForest(fields); } + /** + * The XML aggregate function. + */ + @Support({ POSTGRES }) + public static ArrayAggOrderByStep xmlagg(Field field) { + return new XMLAgg(field); + } + // ------------------------------------------------------------------------- // XXX JSON functions // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLAgg.java b/jOOQ/src/main/java/org/jooq/impl/XMLAgg.java new file mode 100644 index 0000000000..b4dd0672d8 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/XMLAgg.java @@ -0,0 +1,72 @@ +/* + * 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.Names.N_XMLAGG; + +import org.jooq.Context; +import org.jooq.Field; +import org.jooq.XML; + + +/** + * The JSON array constructor. + * + * @author Lukas Eder + */ +final class XMLAgg extends AbstractAggregateFunction { + + /** + * Generated UID + */ + private static final long serialVersionUID = 1772007627336725780L; + + XMLAgg(Field arg) { + super(false, N_XMLAGG, SQLDataType.XML, arg); + } + + @Override + public void accept(Context ctx) { + ctx.visit(N_XMLAGG).sql('(').visit(arguments); + acceptOrderBy(ctx); + ctx.sql(')'); + + acceptFilterClause(ctx); + acceptOverClause(ctx); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java b/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java index 6baee1658a..0aa3d4cfb0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLAttributesImpl.java @@ -66,9 +66,13 @@ final class XMLAttributesImpl extends AbstractQueryPart implements XMLAttributes boolean declareFields = ctx.declareFields(); ctx.visit(N_XMLATTRIBUTES).sql('(') + .formatIndentStart() + .formatNewLine() .declareFields(true) .visit(attributes) .declareFields(declareFields) + .formatIndentEnd() + .formatNewLine() .sql(')'); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLElement.java b/jOOQ/src/main/java/org/jooq/impl/XMLElement.java index 4a23549aa0..c8fa3be51f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLElement.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLElement.java @@ -40,6 +40,7 @@ package org.jooq.impl; import static org.jooq.impl.Keywords.K_NAME; import static org.jooq.impl.Names.N_XMLCONCAT; import static org.jooq.impl.Names.N_XMLELEMENT; +import static org.jooq.impl.Tools.BooleanDataKey.DATA_LIST_ALREADY_INDENTED; import java.util.Collection; @@ -72,14 +73,40 @@ final class XMLElement extends AbstractField { @Override public final void accept(Context ctx) { + boolean hasAttributes = attributes != null && !((XMLAttributesImpl) attributes).attributes.isEmpty(); + boolean hasContent = !content.isEmpty(); + boolean format = + hasAttributes && ((XMLAttributesImpl) attributes).attributes.size() > 1 + || hasContent && content.size() > 1; + Object previous = ctx.data(DATA_LIST_ALREADY_INDENTED); + ctx.visit(N_XMLELEMENT).sql('('); + + if (format) { + ctx.formatIndentStart() + .formatNewLine(); + ctx.data(DATA_LIST_ALREADY_INDENTED, true); + } + ctx.visit(K_NAME).sql(' ').visit(elementName); - if (attributes != null && !((XMLAttributesImpl) attributes).attributes.isEmpty()) - ctx.sql(',').formatSeparator().visit(attributes); + if (hasAttributes) + if (format) + ctx.sql(',').formatSeparator().visit(attributes); + else + ctx.sql(", ").visit(attributes); - if (!content.isEmpty()) - ctx.sql(',').formatSeparator().visit(content); + if (hasContent) + if (format) + ctx.sql(',').formatSeparator().visit(content); + else + ctx.sql(", ").visit(content); + + if (format) { + ctx.formatIndentEnd() + .formatNewLine(); + ctx.data(DATA_LIST_ALREADY_INDENTED, previous); + } ctx.sql(')'); }