use of org.jooq.CommonTableExpression in project jOOQ by jOOQ.
the class DefaultParseContext method parseWith.
private final Query parseWith(boolean parseSelect, Integer degree) {
int parens = 0;
while (parseIf('(')) parens++;
parseKeyword("WITH");
boolean recursive = parseKeywordIf("RECURSIVE");
List<CommonTableExpression<?>> cte = new ArrayList<>();
do {
Name name = parseIdentifier();
DerivedColumnList dcl = null;
if (parseIf('(')) {
List<Name> columnNames = parseIdentifiers();
parse(')');
dcl = name.fields(columnNames.toArray(EMPTY_NAME));
}
parseKeyword("AS");
boolean materialized = parseKeywordIf("MATERIALIZED");
boolean notMaterialized = !materialized && parseKeywordIf("NOT MATERIALIZED");
parse('(');
ResultQuery<?> resultQuery = (ResultQuery<?>) parseQuery(true, false);
parse(')');
cte.add(dcl != null ? materialized ? dcl.asMaterialized(resultQuery) : notMaterialized ? dcl.asNotMaterialized(resultQuery) : dcl.as(resultQuery) : materialized ? name.asMaterialized(resultQuery) : notMaterialized ? name.asNotMaterialized(resultQuery) : name.as(resultQuery));
} while (parseIf(','));
// TODO Better model API for WITH clause
WithImpl with = (WithImpl) new WithImpl(dsl.configuration(), recursive).with(cte.toArray(EMPTY_COMMON_TABLE_EXPRESSION));
Query result;
if (!parseSelect && (peekKeyword("DELETE") || peekKeyword("DEL")))
result = parseDelete(with, false);
else if (!parseSelect && (peekKeyword("INSERT") || peekKeyword("INS")))
result = parseInsert(with, false);
else if (!parseSelect && peekKeyword("MERGE"))
result = parseMerge(with);
else if (peekSelect(true))
result = parseSelect(degree, with);
else if (!parseSelect && (peekKeyword("UPDATE") || peekKeyword("UPD")))
result = parseUpdate(with, false);
else if ((parseWhitespaceIf() || true) && done())
throw exception("Missing statement after WITH");
else
throw exception("Unsupported statement after WITH");
while (parens-- > 0) parse(')');
return result;
}
use of org.jooq.CommonTableExpression in project jOOQ by jOOQ.
the class WithImpl method as0.
// -------------------------------------------------------------------------
// XXX With API
// -------------------------------------------------------------------------
private final WithStep as0(ResultQuery query, Boolean materialized) {
DerivedColumnList dcl;
if (fieldNameFunction != null)
dcl = name(alias).fields(fieldNameFunction);
else
dcl = name(alias).fields(fieldAliases);
CommonTableExpression cte;
if (materialized == null)
cte = dcl.as(query);
else if (materialized)
cte = dcl.asMaterialized(query);
else
cte = dcl.asNotMaterialized(query);
this.ctes.add(cte);
this.alias = null;
this.fieldAliases = null;
this.fieldNameFunction = null;
return this;
}
Aggregations