use of org.jooq.Clause.UPDATE_SET in project jOOQ by jOOQ.
the class UpdateQueryImpl method accept0.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
final void accept0(Context<?> ctx) {
boolean declareTables = ctx.declareTables();
ctx.start(UPDATE_UPDATE).visit(K_UPDATE).sql(' ').declareTables(true).visit(table(ctx)).declareTables(declareTables).end(UPDATE_UPDATE);
ctx.formatSeparator().start(UPDATE_SET).visit(K_SET).separatorRequired(true);
// A multi-row update was specified
if (multiRow != null) {
// [#6884] This syntax can be emulated trivially, if the RHS is not a SELECT subquery
if (multiValue != null && !SUPPORT_RVE_SET.contains(ctx.dialect())) {
FieldMapForUpdate map = new FieldMapForUpdate(table(), UPDATE_SET_ASSIGNMENT);
for (int i = 0; i < multiRow.size(); i++) {
Field<?> k = multiRow.field(i);
Field<?> v = multiValue.field(i);
map.put(k, Tools.field(v, k));
}
ctx.formatIndentStart().formatSeparator().visit(map).formatIndentEnd();
} else {
Row row = removeReadonly(ctx, multiRow);
ctx.start(UPDATE_SET_ASSIGNMENT).formatIndentStart().formatSeparator().qualify(false, c -> c.visit(row)).sql(" = ");
// right hand side of a SET clause
if (multiValue != null) {
// single-degree rows. Let's just always render it, here.
if (REQUIRE_RVE_ROW_CLAUSE.contains(ctx.dialect()))
ctx.visit(K_ROW).sql(" ");
ctx.visit(removeReadonly(ctx, multiRow, multiValue));
} else // Subselects or subselect emulations of row value expressions
{
Select<?> select;
if (multiValue != null)
select = select(removeReadonly(ctx, multiRow, multiValue).fields());
else
select = multiSelect;
visitSubquery(ctx, select, false, false, false);
}
ctx.formatIndentEnd().end(UPDATE_SET_ASSIGNMENT);
}
} else // A regular (non-multi-row) update was specified
{
ctx.formatIndentStart().formatSeparator().visit(updateMap).formatIndentEnd();
}
ctx.end(UPDATE_SET);
switch(ctx.family()) {
default:
acceptFrom(ctx);
break;
}
if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.dialect()) || !orderBy.isEmpty() && NO_SUPPORT_ORDER_BY_LIMIT.contains(ctx.dialect())) {
Field<?>[] keyFields = table().getKeys().isEmpty() ? new Field[] { table().rowid() } : (table().getPrimaryKey() != null ? table().getPrimaryKey() : table().getKeys().get(0)).getFieldsArray();
ctx.start(UPDATE_WHERE).formatSeparator().visit(K_WHERE).sql(' ');
if (keyFields.length == 1)
ctx.visit(keyFields[0].in(select((Field) keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
else
ctx.visit(row(keyFields).in(select(keyFields).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
ctx.end(UPDATE_WHERE);
} else {
ctx.start(UPDATE_WHERE);
if (hasWhere())
ctx.formatSeparator().visit(K_WHERE).sql(' ').visit(getWhere());
ctx.end(UPDATE_WHERE);
if (!orderBy.isEmpty())
ctx.formatSeparator().visit(K_ORDER_BY).sql(' ').visit(orderBy);
if (limit != null)
ctx.formatSeparator().visit(K_LIMIT).sql(' ').visit(limit);
}
ctx.start(UPDATE_RETURNING);
toSQLReturning(ctx);
ctx.end(UPDATE_RETURNING);
}
Aggregations