[jOOQ/jOOQ#9985] Refactor Alias::toSQLDerivedColumnList

This commit is contained in:
Lukas Eder 2020-03-24 12:18:44 +01:00
parent 8e22487f23
commit c678df4402
2 changed files with 9 additions and 63 deletions

View File

@ -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.QueryPartListView.wrap;
import static org.jooq.impl.Tools.renderUnqualifiedNames;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_AS_REQUIRED;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS;
@ -313,25 +314,16 @@ final class Alias<Q extends QueryPart> extends AbstractQueryPart {
}
}
private void toSQLWrapped(Context<?> context) {
context.sql(wrapInParentheses ? "(" : "")
.visit(wrapped)
.sql(wrapInParentheses ? ")" : "");
private void toSQLWrapped(Context<?> ctx) {
ctx.sql(wrapInParentheses ? "(" : "")
.visit(wrapped)
.sql(wrapInParentheses ? ")" : "");
}
private void toSQLDerivedColumnList(Context<?> context) {
String separator = "";
context.sql('(');
for (int i = 0; i < fieldAliases.length; i++) {
context.sql(separator);
context.visit(fieldAliases[i]);
separator = ", ";
}
context.sql(')');
private void toSQLDerivedColumnList(Context<?> ctx) {
ctx.sql('(')
.visit(wrap(fieldAliases).indentSize(0))
.sql(')');
}
@Override

View File

@ -38,9 +38,7 @@
package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static java.util.Arrays.asList;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_LIST_ALREADY_INDENTED;
import java.util.Collection;
import java.util.List;
@ -48,7 +46,6 @@ import java.util.ListIterator;
import org.jooq.Context;
import org.jooq.QueryPart;
import org.jooq.Statement;
/**
* A {@link List} view, delegating all calls to a wrapped list, but acting like
@ -86,49 +83,6 @@ class QueryPartListView<T extends QueryPart> extends QueryPartCollectionView<T>
return (List<T>) super.wrapped();
}
@Override
public /* non-final */ void accept(Context<?> ctx) {
int size = size();
if (ctx.separatorRequired())
if (size >= indentSize)
ctx.formatSeparator();
else
ctx.sql(' ');
// Some lists render different SQL when empty
if (size == 0) {
toSQLEmptyList(ctx);
}
else {
boolean indent = (size >= indentSize) && !TRUE.equals(ctx.data(DATA_LIST_ALREADY_INDENTED));
if (indent)
ctx.formatIndentStart();
for (int i = 0; i < size; i++) {
T part = get(i);
if (i > 0) {
// [#3607] Procedures and functions are not separated by comma
if (!(part instanceof Statement))
ctx.sql(',');
ctx.formatSeparator();
}
else if (indent)
ctx.formatNewLine();
ctx.visit(part);
}
if (indent)
ctx.formatIndentEnd().formatNewLine();
}
}
/**
* Subclasses may override this method
*/