use of org.jooq.UpdateOrderByStep in project jOOQ by jOOQ.
the class DefaultParseContext method parseUpdate.
private final Query parseUpdate(WithImpl with, boolean parseResultQuery) {
parseKeyword("UPDATE", "UPD");
Field<Long> limit = null;
// T-SQL style TOP .. START AT
if (parseKeywordIf("TOP")) {
limit = (Field) parseField();
// [#8623] TODO Support this
// percent = parseKeywordIf("PERCENT") && requireProEdition();
}
Table<?> table = parseTable(() -> peekKeyword(KEYWORDS_IN_UPDATE_FROM));
scope(table);
UpdateSetFirstStep<?> s1 = (with == null ? dsl.update(table) : with.update(table));
List<Table<?>> from = parseKeywordIf("FROM") ? parseList(',', t -> parseTable(() -> peekKeyword(KEYWORDS_IN_UPDATE_FROM))) : null;
parseKeyword("SET");
UpdateFromStep<?> s2;
if (peek('(')) {
Row row = parseRow();
parse('=');
// TODO Can we extract a public API for this?
if (peekSelectOrWith(true))
((UpdateImpl<?>) s1).getDelegate().addValues0(row, parseWithOrSelect(row.size()));
else
((UpdateImpl<?>) s1).getDelegate().addValues0(row, parseRow(row.size()));
s2 = (UpdateFromStep<?>) s1;
} else {
Map<Field<?>, Object> map = parseSetClauseList();
s2 = s1.set(map);
}
UpdateWhereStep<?> s3 = from != null ? s2.from(from) : parseKeywordIf("FROM") ? s2.from(parseList(',', t -> parseTable(() -> peekKeyword(KEYWORDS_IN_UPDATE_FROM)))) : s2;
UpdateOrderByStep<?> s4 = parseKeywordIf("ALL") ? s3 : parseKeywordIf("WHERE") ? s3.where(parseCondition()) : s3;
UpdateLimitStep<?> s5 = parseKeywordIf("ORDER BY") ? s4.orderBy(parseList(',', c -> c.parseSortField())) : s4;
UpdateReturningStep<?> s6 = (limit != null || parseKeywordIf("LIMIT")) ? s5.limit(limit != null ? limit : (Field) parseField()) : s5;
return (parseResultQuery ? parseKeyword("RETURNING") : parseKeywordIf("RETURNING")) ? s6.returning(parseSelectList()) : s6;
}
Aggregations