[jOOQ/jOOQ#9925] Added support for xmlagg
This commit is contained in:
parent
04c61c0fca
commit
aff0fbea35
@ -18254,6 +18254,14 @@ public class DSL {
|
||||
return new XMLForest(fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML aggregate function.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
public static ArrayAggOrderByStep<XML> xmlagg(Field<XML> field) {
|
||||
return new XMLAgg(field);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX JSON functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
72
jOOQ/src/main/java/org/jooq/impl/XMLAgg.java
Normal file
72
jOOQ/src/main/java/org/jooq/impl/XMLAgg.java
Normal file
@ -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<XML> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1772007627336725780L;
|
||||
|
||||
XMLAgg(Field<XML> 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);
|
||||
}
|
||||
}
|
||||
@ -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(')');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<XML> {
|
||||
|
||||
@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(')');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user