[jOOQ/jOOQ#9985] Refactor InsertQueryImpl::toSQLInsert's DEFAULT VALUES emulation
This commit is contained in:
parent
8aa94df0e7
commit
006615ab2b
@ -39,6 +39,7 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static java.util.Collections.nCopies;
|
||||
import static org.jooq.Clause.INSERT;
|
||||
import static org.jooq.Clause.INSERT_INSERT_INTO;
|
||||
import static org.jooq.Clause.INSERT_ON_DUPLICATE_KEY_UPDATE;
|
||||
@ -74,6 +75,7 @@ import static org.jooq.impl.Keywords.K_ON_DUPLICATE_KEY_UPDATE;
|
||||
import static org.jooq.impl.Keywords.K_SET;
|
||||
import static org.jooq.impl.Keywords.K_VALUES;
|
||||
import static org.jooq.impl.Keywords.K_WHERE;
|
||||
import static org.jooq.impl.QueryPartListView.wrap;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.aliasedFields;
|
||||
import static org.jooq.impl.Tools.fieldNameStrings;
|
||||
@ -663,23 +665,15 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
case MYSQL:
|
||||
ctx.formatSeparator()
|
||||
.visit(K_VALUES)
|
||||
.sql('(');
|
||||
.sql(" (")
|
||||
.visit(wrap(nCopies(table().fields().length, K_DEFAULT)))
|
||||
.sql(')');
|
||||
|
||||
int count = table().fields().length;
|
||||
String separator = "";
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.sql(separator);
|
||||
ctx.visit(K_DEFAULT);
|
||||
separator = ", ";
|
||||
}
|
||||
|
||||
ctx.sql(')');
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.formatSeparator()
|
||||
.visit(K_DEFAULT_VALUES);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,15 @@ class QueryPartListView<T extends QueryPart> extends AbstractQueryPart implement
|
||||
|
||||
private static final long serialVersionUID = -2936922742534009564L;
|
||||
private final List<T> wrappedList;
|
||||
private int indentSize = 2;
|
||||
|
||||
static <T extends QueryPart> QueryPartListView<T> wrap(T[] wrappedList) {
|
||||
return new QueryPartListView<>(wrappedList);
|
||||
}
|
||||
|
||||
static <T extends QueryPart> QueryPartListView<T> wrap(List<T> wrappedList) {
|
||||
return new QueryPartListView<>(wrappedList);
|
||||
}
|
||||
|
||||
QueryPartListView(T[] wrappedList) {
|
||||
this(asList(wrappedList));
|
||||
@ -71,12 +80,20 @@ class QueryPartListView<T extends QueryPart> extends AbstractQueryPart implement
|
||||
this.wrappedList = wrappedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to indent this list, and after what size indentation is applied.
|
||||
*/
|
||||
QueryPartListView<T> indentSize(int newIndentSize) {
|
||||
this.indentSize = newIndentSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* non-final */ void accept(Context<?> ctx) {
|
||||
int size = size();
|
||||
|
||||
if (ctx.separatorRequired())
|
||||
if (size > 1)
|
||||
if (size >= indentSize)
|
||||
ctx.formatSeparator();
|
||||
else
|
||||
ctx.sql(' ');
|
||||
@ -87,7 +104,7 @@ class QueryPartListView<T extends QueryPart> extends AbstractQueryPart implement
|
||||
}
|
||||
|
||||
else {
|
||||
boolean indent = (size > 1) && !TRUE.equals(ctx.data(DATA_LIST_ALREADY_INDENTED));
|
||||
boolean indent = (size >= indentSize) && !TRUE.equals(ctx.data(DATA_LIST_ALREADY_INDENTED));
|
||||
|
||||
if (indent)
|
||||
ctx.formatIndentStart();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user