[jOOQ/jOOQ#9925] Added DB2 support
This commit is contained in:
parent
bd53d19855
commit
5201a73d9c
@ -37,6 +37,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
|
||||
/**
|
||||
|
||||
@ -74,6 +74,7 @@ import static org.jooq.impl.DSL.falseCondition;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.Keywords.K_AS;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_AS_REQUIRED;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS;
|
||||
|
||||
import java.util.Set;
|
||||
@ -284,7 +285,13 @@ final class Alias<Q extends QueryPart> extends AbstractQueryPart {
|
||||
}
|
||||
|
||||
void toSQLAs(Context<?> ctx) {
|
||||
if (wrapped instanceof Field) {
|
||||
|
||||
// [#9925] In some cases, AS is always required, regardless
|
||||
// of the dialect or settings (e.g. XMLATTRIBUTES).
|
||||
if (TRUE.equals(ctx.data(DATA_AS_REQUIRED))) {
|
||||
ctx.sql(' ').visit(K_AS);
|
||||
}
|
||||
else if (wrapped instanceof Field) {
|
||||
if (ctx.settings().getRenderOptionalAsKeywordForFieldAliases() == RenderOptionalKeyword.DEFAULT && SUPPORT_AS_REQUIRED.contains(ctx.family()))
|
||||
ctx.sql(' ').visit(K_AS);
|
||||
else if (ctx.settings().getRenderOptionalAsKeywordForFieldAliases() == RenderOptionalKeyword.ON)
|
||||
|
||||
@ -390,6 +390,7 @@ import org.jooq.WithAsStep8;
|
||||
import org.jooq.WithAsStep9;
|
||||
import org.jooq.WithStep;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.XMLAggOrderByStep;
|
||||
import org.jooq.XMLAttributes;
|
||||
import org.jooq.XMLExistsPassingStep;
|
||||
import org.jooq.conf.Settings;
|
||||
@ -18292,7 +18293,7 @@ public class DSL {
|
||||
* The XML aggregate function.
|
||||
*/
|
||||
@Support({ POSTGRES })
|
||||
public static ArrayAggOrderByStep<XML> xmlagg(Field<XML> field) {
|
||||
public static XMLAggOrderByStep<XML> xmlagg(Field<XML> field) {
|
||||
return new XMLAgg(field);
|
||||
}
|
||||
|
||||
|
||||
@ -513,6 +513,7 @@ import org.jooq.WindowSpecificationOrderByStep;
|
||||
import org.jooq.WindowSpecificationRowsAndStep;
|
||||
import org.jooq.WindowSpecificationRowsStep;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.XMLAggOrderByStep;
|
||||
import org.jooq.XMLAttributes;
|
||||
import org.jooq.conf.ParseSearchSchema;
|
||||
import org.jooq.conf.ParseUnknownFunctions;
|
||||
@ -6854,7 +6855,7 @@ final class ParserImpl implements Parser {
|
||||
|
||||
private static final AggregateFilterStep<?> parseXMLAggFunctionIf(ParserContext ctx) {
|
||||
if (parseFunctionNameIf(ctx, "XMLAGG")) {
|
||||
ArrayAggOrderByStep<?> s1;
|
||||
XMLAggOrderByStep<?> s1;
|
||||
AggregateFilterStep<?> s2;
|
||||
|
||||
parse(ctx, '(');
|
||||
|
||||
@ -496,6 +496,11 @@ final class Tools {
|
||||
* [#1535] We're currently generating the window specification of a ranking function.
|
||||
*/
|
||||
DATA_ORDERED_WINDOW_FUNCTION,
|
||||
|
||||
/**
|
||||
* [#9925] In some cases the <code>AS</code> keyword is required for aliasing, e.g. XML.
|
||||
*/
|
||||
DATA_AS_REQUIRED
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -42,6 +42,7 @@ import static org.jooq.impl.Names.N_XMLAGG;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.XMLAggOrderByStep;
|
||||
|
||||
|
||||
/**
|
||||
@ -49,7 +50,7 @@ import org.jooq.XML;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class XMLAgg extends AbstractAggregateFunction<XML> {
|
||||
final class XMLAgg extends AbstractAggregateFunction<XML> implements XMLAggOrderByStep<XML> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Names.N_XMLATTRIBUTES;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_AS_REQUIRED;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -53,7 +54,7 @@ final class XMLAttributesImpl extends AbstractQueryPart implements XMLAttributes
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1887555231334164185L;
|
||||
private static final long serialVersionUID = 1887555231334164185L;
|
||||
|
||||
final SelectFieldList<Field<?>> attributes;
|
||||
|
||||
@ -66,6 +67,7 @@ final class XMLAttributesImpl extends AbstractQueryPart implements XMLAttributes
|
||||
boolean declareFields = ctx.declareFields();
|
||||
boolean format = attributes.size() > 1;
|
||||
|
||||
Object previous = ctx.data(DATA_AS_REQUIRED, true);
|
||||
ctx.visit(N_XMLATTRIBUTES).sql('(');
|
||||
|
||||
if (format)
|
||||
@ -81,5 +83,6 @@ final class XMLAttributesImpl extends AbstractQueryPart implements XMLAttributes
|
||||
.formatNewLine();
|
||||
|
||||
ctx.sql(')');
|
||||
ctx.data(DATA_AS_REQUIRED, previous);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
// ...
|
||||
import static org.jooq.conf.ParamType.INLINED;
|
||||
import static org.jooq.impl.Keywords.K_BY;
|
||||
import static org.jooq.impl.Keywords.K_PASSING;
|
||||
import static org.jooq.impl.Keywords.K_REF;
|
||||
@ -50,6 +52,7 @@ import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.XML;
|
||||
import org.jooq.XMLExistsPassingStep;
|
||||
import org.jooq.conf.ParamType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -117,9 +120,22 @@ final class XMLExists extends AbstractCondition implements XMLExistsPassingStep
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.visit(K_XMLEXISTS).sql('(')
|
||||
.formatIndentStart()
|
||||
.formatNewLine()
|
||||
.visit(xpath)
|
||||
.formatSeparator()
|
||||
.formatNewLine();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ctx.visit(xpath);
|
||||
|
||||
ctx.formatSeparator()
|
||||
.visit(K_PASSING);
|
||||
|
||||
if (passingMechanism == BY_REF)
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Names.N_XMLFOREST;
|
||||
import static org.jooq.impl.Tools.BooleanDataKey.DATA_AS_REQUIRED;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -66,10 +67,12 @@ final class XMLForest extends AbstractField<XML> {
|
||||
public final void accept(Context<?> ctx) {
|
||||
boolean declareFields = ctx.declareFields();
|
||||
|
||||
Object previous = ctx.data(DATA_AS_REQUIRED, true);
|
||||
ctx.visit(N_XMLFOREST).sql('(')
|
||||
.declareFields(true)
|
||||
.visit(args)
|
||||
.declareFields(declareFields)
|
||||
.sql(')');
|
||||
ctx.data(DATA_AS_REQUIRED, previous);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ final class XMLPI extends AbstractField<XML> {
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.visit(N_XMLPI).sql('(').visit(K_NAME).sql(' ').visit(target.unquotedName());
|
||||
ctx.visit(N_XMLPI).sql('(').visit(K_NAME).sql(' ').visit(target);
|
||||
|
||||
if (content != null)
|
||||
ctx.sql(", ").visit(content);
|
||||
|
||||
@ -37,9 +37,12 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.xmlparseDocument;
|
||||
import static org.jooq.impl.Keywords.K_CONTENT;
|
||||
import static org.jooq.impl.Keywords.K_DOCUMENT;
|
||||
import static org.jooq.impl.Names.N_XMLPARSE;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import static org.jooq.impl.XMLParse.DocumentOrContent.DOCUMENT;
|
||||
|
||||
import org.jooq.Context;
|
||||
@ -67,7 +70,40 @@ final class XMLParse extends AbstractField<XML> {
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.visit(N_XMLPARSE).sql('(').visit(documentOrContent == DOCUMENT ? K_DOCUMENT : K_CONTENT).sql(' ').visit(content).sql(')');
|
||||
switch (ctx.family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES:
|
||||
default:
|
||||
acceptStandard(ctx, documentOrContent, content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static final void acceptStandard(
|
||||
Context<?> ctx,
|
||||
DocumentOrContent documentOrContent,
|
||||
Field<String> content
|
||||
) {
|
||||
ctx.visit(N_XMLPARSE).sql('(')
|
||||
.visit(documentOrContent == DOCUMENT ? K_DOCUMENT : K_CONTENT).sql(' ')
|
||||
.visit(content)
|
||||
.sql(')');
|
||||
}
|
||||
|
||||
enum DocumentOrContent { DOCUMENT, CONTENT }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user