[#2665] Implement SPI for RenderContext and BindContext listening to
allow for custom SQL transformation * Fixed various DUMMY references.
This commit is contained in:
parent
4a279450d5
commit
7ef726a570
@ -48,6 +48,13 @@ public enum Clause {
|
||||
@Deprecated
|
||||
DUMMY,
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Clauses used in a any type of statement to model package references
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
PACKAGE,
|
||||
PACKAGE_REFERENCE,
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Clauses used in a any type of statement to model catalog references
|
||||
// -------------------------------------------------------------------------
|
||||
@ -67,9 +74,9 @@ public enum Clause {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A complete table reference.
|
||||
* A table expression.
|
||||
* <p>
|
||||
* This clause surrounds a complete table reference as it can be encountered
|
||||
* This clause surrounds an actual table expression as it can be encountered
|
||||
* in
|
||||
* <ul>
|
||||
* <li> {@link #SELECT_FROM}</li>
|
||||
@ -84,10 +91,6 @@ public enum Clause {
|
||||
|
||||
TABLE_ALIAS,
|
||||
TABLE_REFERENCE,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TABLE_JOIN,
|
||||
TABLE_JOIN_INNER,
|
||||
TABLE_JOIN_CROSS,
|
||||
@ -320,6 +323,8 @@ public enum Clause {
|
||||
|
||||
INSERT,
|
||||
INSERT_INSERT_INTO,
|
||||
INSERT_ON_DUPLICATE_KEY_UPDATE,
|
||||
INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT,
|
||||
INSERT_RETURNING,
|
||||
|
||||
|
||||
@ -398,6 +403,8 @@ public enum Clause {
|
||||
|
||||
MERGE,
|
||||
MERGE_MERGE_INTO,
|
||||
MERGE_WHEN_MATCHED_THEN_UPDATE_SET,
|
||||
MERGE_WHEN_MATCHED_THEN_UPDATE_SET_ASSIGNMENT,
|
||||
|
||||
|
||||
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.impl.Utils.fieldArray;
|
||||
import static org.jooq.util.sqlite.SQLiteDSL.rowid;
|
||||
|
||||
@ -84,7 +83,7 @@ abstract class AbstractStoreQuery<R extends Record> extends AbstractQuery implem
|
||||
super(configuration);
|
||||
|
||||
this.into = into;
|
||||
this.returning = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.returning = new QueryPartList<Field<?>>();
|
||||
}
|
||||
|
||||
protected abstract Map<Field<?>, Field<?>> getValues();
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.SQLDialect.ASE;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
@ -7767,7 +7766,7 @@ public class DSL {
|
||||
WrappedList[] array = new WrappedList[fieldSets.length];
|
||||
|
||||
for (int i = 0; i < fieldSets.length; i++) {
|
||||
array[i] = new WrappedList(new QueryPartList<Field<?>>(DUMMY, fieldSets[i]));
|
||||
array[i] = new WrappedList(new QueryPartList<Field<?>>(fieldSets[i]));
|
||||
}
|
||||
|
||||
return new Function<Object>("grouping sets", SQLDataType.OTHER, array);
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
import static org.jooq.impl.DSL.notExists;
|
||||
@ -75,7 +74,7 @@ implements
|
||||
this.divisor = divisor;
|
||||
|
||||
this.condition = new ConditionProviderImpl();
|
||||
this.returning = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.returning = new QueryPartList<Field<?>>();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -36,7 +36,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.SQLDialect.ASE;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
@ -100,7 +99,7 @@ class Expression<T> extends AbstractFunction<T> {
|
||||
|
||||
this.operator = operator;
|
||||
this.lhs = lhs;
|
||||
this.rhs = new QueryPartList<Field<?>>(DUMMY, rhs);
|
||||
this.rhs = new QueryPartList<Field<?>>(rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.UPDATE_SET_ASSIGNMENT;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
|
||||
@ -59,7 +57,10 @@ class FieldMapForUpdate extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
*/
|
||||
private static final long serialVersionUID = -6139709404698673799L;
|
||||
|
||||
FieldMapForUpdate() {
|
||||
private final Clause assignmentClause;
|
||||
|
||||
FieldMapForUpdate(Clause assignmentClause) {
|
||||
this.assignmentClause = assignmentClause;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,13 +84,13 @@ class FieldMapForUpdate extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
context.formatNewLine();
|
||||
}
|
||||
|
||||
context.start(UPDATE_SET_ASSIGNMENT)
|
||||
context.start(assignmentClause)
|
||||
.qualify(supportsQualify)
|
||||
.visit(entry.getKey())
|
||||
.qualify(restoreQualify)
|
||||
.sql(" = ")
|
||||
.visit(entry.getValue())
|
||||
.end(UPDATE_SET_ASSIGNMENT);
|
||||
.end(assignmentClause);
|
||||
|
||||
separator = ", ";
|
||||
}
|
||||
@ -109,7 +110,7 @@ class FieldMapForUpdate extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return null;
|
||||
}
|
||||
|
||||
final void set(Map<? extends Field<?>, ?> map) {
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
@ -250,17 +248,17 @@ class Fields<R extends Record> extends AbstractQueryPart implements RecordType<R
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
new QueryPartList<Field<?>>(DUMMY, fields).toSQL(context);
|
||||
new QueryPartList<Field<?>>(fields).toSQL(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
new QueryPartList<Field<?>>(DUMMY, fields).bind(context);
|
||||
new QueryPartList<Field<?>>(fields).bind(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
@ -137,10 +136,10 @@ class Function<T> extends AbstractField<T> implements
|
||||
this.term = null;
|
||||
this.name = null;
|
||||
this.distinct = distinct;
|
||||
this.arguments = new QueryPartList<QueryPart>(DUMMY, arguments);
|
||||
this.arguments = new QueryPartList<QueryPart>(arguments);
|
||||
this.keepDenseRankOrderBy = new SortFieldList();
|
||||
this.withinGroupOrderBy = new SortFieldList();
|
||||
this.partitionBy = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.partitionBy = new QueryPartList<Field<?>>();
|
||||
this.orderBy = new SortFieldList();
|
||||
}
|
||||
|
||||
@ -150,10 +149,10 @@ class Function<T> extends AbstractField<T> implements
|
||||
this.term = term;
|
||||
this.name = null;
|
||||
this.distinct = distinct;
|
||||
this.arguments = new QueryPartList<QueryPart>(DUMMY, arguments);
|
||||
this.arguments = new QueryPartList<QueryPart>(arguments);
|
||||
this.keepDenseRankOrderBy = new SortFieldList();
|
||||
this.withinGroupOrderBy = new SortFieldList();
|
||||
this.partitionBy = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.partitionBy = new QueryPartList<Field<?>>();
|
||||
this.orderBy = new SortFieldList();
|
||||
}
|
||||
|
||||
@ -163,10 +162,10 @@ class Function<T> extends AbstractField<T> implements
|
||||
this.term = null;
|
||||
this.name = name;
|
||||
this.distinct = distinct;
|
||||
this.arguments = new QueryPartList<QueryPart>(DUMMY, arguments);
|
||||
this.arguments = new QueryPartList<QueryPart>(arguments);
|
||||
this.keepDenseRankOrderBy = new SortFieldList();
|
||||
this.withinGroupOrderBy = new SortFieldList();
|
||||
this.partitionBy = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.partitionBy = new QueryPartList<Field<?>>();
|
||||
this.orderBy = new SortFieldList();
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.INSERT;
|
||||
import static org.jooq.Clause.INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT;
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
|
||||
@ -76,7 +77,7 @@ class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
|
||||
InsertQueryImpl(Configuration configuration, Table<R> into) {
|
||||
super(configuration, into);
|
||||
|
||||
updateMap = new FieldMapForUpdate();
|
||||
updateMap = new FieldMapForUpdate(INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT);
|
||||
insertMaps = new FieldMapsForInsert();
|
||||
}
|
||||
|
||||
@ -149,7 +150,8 @@ class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
|
||||
case MYSQL: {
|
||||
toSQLInsert(context);
|
||||
context.formatSeparator()
|
||||
.keyword("on duplicate key update ")
|
||||
.keyword("on duplicate key update")
|
||||
.sql(" ")
|
||||
.visit(updateMap);
|
||||
|
||||
break;
|
||||
@ -191,13 +193,14 @@ class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
|
||||
|
||||
// CUBRID can simulate this using ON DUPLICATE KEY UPDATE
|
||||
case CUBRID: {
|
||||
FieldMapForUpdate update = new FieldMapForUpdate();
|
||||
FieldMapForUpdate update = new FieldMapForUpdate(INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT);
|
||||
Field<?> field = getInto().field(0);
|
||||
update.put(field, field);
|
||||
|
||||
toSQLInsert(context);
|
||||
context.formatSeparator()
|
||||
.keyword("on duplicate key update ")
|
||||
.keyword("on duplicate key update")
|
||||
.sql(" ")
|
||||
.visit(update);
|
||||
|
||||
break;
|
||||
|
||||
@ -36,7 +36,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.TABLE;
|
||||
import static org.jooq.Clause.TABLE_JOIN;
|
||||
import static org.jooq.Clause.TABLE_JOIN_CROSS;
|
||||
@ -118,11 +117,11 @@ class JoinTable extends AbstractTable<Record> implements TableOptionalOnStep, Ta
|
||||
|
||||
this.lhs = lhs.asTable();
|
||||
this.rhs = rhs.asTable();
|
||||
this.rhsPartitionBy = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.rhsPartitionBy = new QueryPartList<Field<?>>();
|
||||
this.type = type;
|
||||
|
||||
this.condition = new ConditionProviderImpl();
|
||||
this.using = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.using = new QueryPartList<Field<?>>();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -35,8 +35,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.MERGE;
|
||||
import static org.jooq.Clause.MERGE_WHEN_MATCHED_THEN_UPDATE_SET_ASSIGNMENT;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.exists;
|
||||
@ -235,7 +235,7 @@ implements
|
||||
|
||||
if (fields != null) {
|
||||
h2Style = true;
|
||||
h2Fields = new QueryPartList<Field<?>>(DUMMY, fields);
|
||||
h2Fields = new QueryPartList<Field<?>>(fields);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ implements
|
||||
|
||||
QueryPartList<Field<?>> getH2Fields() {
|
||||
if (h2Fields == null) {
|
||||
h2Fields = new QueryPartList<Field<?>>(DUMMY, table.fields());
|
||||
h2Fields = new QueryPartList<Field<?>>(table.fields());
|
||||
}
|
||||
|
||||
return h2Fields;
|
||||
@ -253,7 +253,7 @@ implements
|
||||
|
||||
QueryPartList<Field<?>> getH2Keys() {
|
||||
if (h2Keys == null) {
|
||||
h2Keys = new QueryPartList<Field<?>>(DUMMY);
|
||||
h2Keys = new QueryPartList<Field<?>>();
|
||||
}
|
||||
|
||||
return h2Keys;
|
||||
@ -261,7 +261,7 @@ implements
|
||||
|
||||
QueryPartList<Field<?>> getH2Values() {
|
||||
if (h2Values == null) {
|
||||
h2Values = new QueryPartList<Field<?>>(DUMMY);
|
||||
h2Values = new QueryPartList<Field<?>>();
|
||||
}
|
||||
|
||||
return h2Values;
|
||||
@ -678,7 +678,7 @@ implements
|
||||
@Override
|
||||
public final MergeImpl whenMatchedThenUpdate() {
|
||||
matchedClause = true;
|
||||
matchedUpdate = new FieldMapForUpdate();
|
||||
matchedUpdate = new FieldMapForUpdate(MERGE_WHEN_MATCHED_THEN_UPDATE_SET_ASSIGNMENT);
|
||||
|
||||
notMatchedClause = false;
|
||||
return this;
|
||||
|
||||
@ -35,8 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
@ -78,7 +76,7 @@ class NameImpl extends AbstractQueryPart implements Name {
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -35,7 +35,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.PACKAGE;
|
||||
import static org.jooq.Clause.PACKAGE_REFERENCE;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Clause;
|
||||
@ -61,10 +62,11 @@ public class PackageImpl extends AbstractQueryPart implements Package {
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 7466890004995197675L;
|
||||
private static final long serialVersionUID = 7466890004995197675L;
|
||||
private static final Clause[] CLAUSES = { PACKAGE, PACKAGE_REFERENCE };
|
||||
|
||||
private final Schema schema;
|
||||
private final String name;
|
||||
private final Schema schema;
|
||||
private final String name;
|
||||
|
||||
public PackageImpl(String name, Schema schema) {
|
||||
this.schema = schema;
|
||||
@ -91,7 +93,7 @@ public class PackageImpl extends AbstractQueryPart implements Package {
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return CLAUSES;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Configuration;
|
||||
@ -96,7 +94,7 @@ class ParameterImpl<T> extends AbstractQueryPart implements Parameter<T> {
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
@ -44,7 +43,7 @@ import org.jooq.Configuration;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.QuantifiedSelect;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.QueryPartInternal;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.Select;
|
||||
@ -76,62 +75,62 @@ class QuantifiedSelectImpl<R extends Record> extends AbstractQueryPart implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
public final void toSQL(RenderContext ctx) {
|
||||
|
||||
// If this is already a subquery, proceed
|
||||
if (context.subquery()) {
|
||||
context.keyword(quantifier.toSQL())
|
||||
.sql(" (")
|
||||
.formatIndentStart()
|
||||
.formatNewLine()
|
||||
.visit(part(context.configuration()))
|
||||
.formatIndentEnd()
|
||||
.formatNewLine()
|
||||
.sql(")");
|
||||
if (ctx.subquery()) {
|
||||
ctx.keyword(quantifier.toSQL())
|
||||
.sql(" (")
|
||||
.formatIndentStart()
|
||||
.formatNewLine()
|
||||
.visit(delegate(ctx.configuration()))
|
||||
.formatIndentEnd()
|
||||
.formatNewLine()
|
||||
.sql(")");
|
||||
}
|
||||
else {
|
||||
context.keyword(quantifier.toSQL())
|
||||
.sql(" (")
|
||||
.subquery(true)
|
||||
.formatIndentStart()
|
||||
.formatNewLine()
|
||||
.visit(part(context.configuration()))
|
||||
.formatIndentEnd()
|
||||
.formatNewLine()
|
||||
.subquery(false)
|
||||
.sql(")");
|
||||
ctx.keyword(quantifier.toSQL())
|
||||
.sql(" (")
|
||||
.subquery(true)
|
||||
.formatIndentStart()
|
||||
.formatNewLine()
|
||||
.visit(delegate(ctx.configuration()))
|
||||
.formatIndentEnd()
|
||||
.formatNewLine()
|
||||
.subquery(false)
|
||||
.sql(")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
public final void bind(BindContext ctx) {
|
||||
|
||||
// If this is already a subquery, proceed
|
||||
if (context.subquery()) {
|
||||
context.visit(part(context.configuration()));
|
||||
if (ctx.subquery()) {
|
||||
ctx.visit(delegate(ctx.configuration()));
|
||||
}
|
||||
else {
|
||||
context.subquery(true)
|
||||
.visit(part(context.configuration()))
|
||||
.subquery(false);
|
||||
ctx.subquery(true)
|
||||
.visit(delegate(ctx.configuration()))
|
||||
.subquery(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return delegate(ctx.configuration()).clauses(ctx);
|
||||
}
|
||||
|
||||
private final QueryPart part(Configuration context) {
|
||||
private final QueryPartInternal delegate(Configuration ctx) {
|
||||
if (query != null) {
|
||||
return query;
|
||||
return (QueryPartInternal) query;
|
||||
}
|
||||
else {
|
||||
switch (context.dialect()) {
|
||||
switch (ctx.dialect()) {
|
||||
|
||||
// [#869] Postgres supports this syntax natively
|
||||
case POSTGRES: {
|
||||
return array;
|
||||
return (QueryPartInternal) array;
|
||||
}
|
||||
|
||||
// [#869] H2 and HSQLDB can simulate this syntax by unnesting
|
||||
@ -142,7 +141,7 @@ class QuantifiedSelectImpl<R extends Record> extends AbstractQueryPart implement
|
||||
// [#1048] All other dialects simulate unnesting of arrays using
|
||||
// UNION ALL-connected subselects
|
||||
default: {
|
||||
return create(context).select().from(table(array));
|
||||
return (QueryPartInternal) create(ctx).select().from(table(array));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,11 +36,10 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.impl.Utils.visitAll;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -59,16 +58,14 @@ class QueryPartList<T extends QueryPart> extends AbstractQueryPart implements Li
|
||||
|
||||
private static final long serialVersionUID = -2936922742534009564L;
|
||||
private final List<T> wrappedList;
|
||||
private final Clause clause;
|
||||
|
||||
QueryPartList(Clause clause) {
|
||||
this(clause, (Collection<T>) null);
|
||||
QueryPartList() {
|
||||
this((Collection<T>) null);
|
||||
}
|
||||
|
||||
QueryPartList(Clause clause, Collection<? extends T> wrappedList) {
|
||||
QueryPartList(Collection<? extends T> wrappedList) {
|
||||
super();
|
||||
|
||||
this.clause = clause;
|
||||
this.wrappedList = new ArrayList<T>();
|
||||
|
||||
if (wrappedList != null) {
|
||||
@ -76,8 +73,8 @@ class QueryPartList<T extends QueryPart> extends AbstractQueryPart implements Li
|
||||
}
|
||||
}
|
||||
|
||||
QueryPartList(Clause clause, T... wrappedList) {
|
||||
this(clause, Arrays.asList(wrappedList));
|
||||
QueryPartList(T... wrappedList) {
|
||||
this(asList(wrappedList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,7 +127,7 @@ class QueryPartList<T extends QueryPart> extends AbstractQueryPart implements Li
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
import static org.jooq.impl.DSL.function;
|
||||
|
||||
@ -62,7 +61,7 @@ class Rollup extends AbstractFunction<Object> {
|
||||
case CUBRID:
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
return field("{0} {with rollup}", new QueryPartList<Field<?>>(DUMMY, getArguments()));
|
||||
return field("{0} {with rollup}", new QueryPartList<Field<?>>(getArguments()));
|
||||
|
||||
default:
|
||||
return function("rollup", Object.class, getArguments());
|
||||
|
||||
@ -38,7 +38,6 @@ package org.jooq.impl;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.CONDITION;
|
||||
import static org.jooq.Clause.CONDITION_COMPARISON;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Comparator.EQUALS;
|
||||
import static org.jooq.Comparator.GREATER;
|
||||
import static org.jooq.Comparator.GREATER_OR_EQUAL;
|
||||
@ -95,18 +94,18 @@ class RowCondition extends AbstractCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
delegate(context.configuration()).toSQL(context);
|
||||
public final void toSQL(RenderContext ctx) {
|
||||
delegate(ctx.configuration()).toSQL(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
delegate(context.configuration()).bind(context);
|
||||
public final void bind(BindContext ctx) {
|
||||
delegate(ctx.configuration()).bind(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return delegate(ctx.configuration()).clauses(ctx);
|
||||
}
|
||||
|
||||
private final QueryPartInternal delegate(Configuration configuration) {
|
||||
@ -193,10 +192,8 @@ class RowCondition extends AbstractCondition {
|
||||
|
||||
// Some dialects do not support != comparison with rows
|
||||
if (comparator == NOT_EQUALS && asList(DB2).contains(context.configuration().dialect().family())) {
|
||||
context.keyword("not(")
|
||||
.visit(left)
|
||||
.sql(" = ")
|
||||
.visit(right)
|
||||
context.keyword("not").sql("(")
|
||||
.visit(left).sql(" = ").visit(right)
|
||||
.sql(")");
|
||||
}
|
||||
else {
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.FIELD;
|
||||
import static org.jooq.Clause.FIELD_ROW;
|
||||
import static org.jooq.impl.DSL.row;
|
||||
@ -9921,13 +9920,13 @@ implements
|
||||
|
||||
@Override
|
||||
public final Condition in(Collection rows) {
|
||||
QueryPartList<Row> list = new QueryPartList<Row>(DUMMY, rows);
|
||||
QueryPartList<Row> list = new QueryPartList<Row>(rows);
|
||||
return new RowInCondition(this, list, Comparator.IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notIn(Collection rows) {
|
||||
QueryPartList<Row> list = new QueryPartList<Row>(DUMMY, rows);
|
||||
QueryPartList<Row> list = new QueryPartList<Row>(rows);
|
||||
return new RowInCondition(this, list, Comparator.NOT_IN);
|
||||
}
|
||||
|
||||
|
||||
@ -37,9 +37,8 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.CONDITION;
|
||||
import static org.jooq.Clause.CONDITION_IS_NULL;
|
||||
import static org.jooq.Clause.CONDITION_IS_NOT_NULL;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.CONDITION_IS_NULL;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
@ -77,7 +76,7 @@ class RowIsNull extends AbstractCondition {
|
||||
*/
|
||||
private static final long serialVersionUID = -1806139685201770706L;
|
||||
private static final Clause[] CLAUSES_NULL = { CONDITION, CONDITION_IS_NULL };
|
||||
private static final Clause[] CLAUSES_NULL_NOT = { CONDITION, CONDITION_IS_NOT_NULL };
|
||||
private static final Clause[] CLAUSES_NOT_NULL = { CONDITION, CONDITION_IS_NOT_NULL };
|
||||
|
||||
private final Row row;
|
||||
private final boolean isNull;
|
||||
@ -88,18 +87,18 @@ class RowIsNull extends AbstractCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
delegate(context.configuration()).toSQL(context);
|
||||
public final void toSQL(RenderContext ctx) {
|
||||
delegate(ctx.configuration()).toSQL(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
delegate(context.configuration()).bind(context);
|
||||
public final void bind(BindContext ctx) {
|
||||
delegate(ctx.configuration()).bind(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return delegate(ctx.configuration()).clauses(ctx);
|
||||
}
|
||||
|
||||
private final QueryPartInternal delegate(Configuration configuration) {
|
||||
@ -131,7 +130,8 @@ class RowIsNull extends AbstractCondition {
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
context.visit(row)
|
||||
.keyword(isNull ? " is null" : " is not null");
|
||||
.sql(" ")
|
||||
.keyword(isNull ? "is null" : "is not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,7 +141,7 @@ class RowIsNull extends AbstractCondition {
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return isNull ? CLAUSES_NULL : CLAUSES_NULL_NOT;
|
||||
return isNull ? CLAUSES_NULL : CLAUSES_NOT_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,7 +38,6 @@ package org.jooq.impl;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.CONDITION;
|
||||
import static org.jooq.Clause.CONDITION_COMPARISON;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Comparator.EQUALS;
|
||||
import static org.jooq.Comparator.IN;
|
||||
import static org.jooq.Comparator.NOT_EQUALS;
|
||||
@ -86,9 +85,9 @@ class RowSubqueryCondition extends AbstractCondition {
|
||||
private static final long serialVersionUID = -1806139685201770706L;
|
||||
private static final Clause[] CLAUSES = { CONDITION, CONDITION_COMPARISON };
|
||||
|
||||
private final Row left;
|
||||
private final Select<?> right;
|
||||
private final Comparator comparator;
|
||||
private final Row left;
|
||||
private final Select<?> right;
|
||||
private final Comparator comparator;
|
||||
|
||||
RowSubqueryCondition(Row left, Select<?> right, Comparator comparator) {
|
||||
this.left = left;
|
||||
@ -97,21 +96,21 @@ class RowSubqueryCondition extends AbstractCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
delegate(context.configuration(), context).toSQL(context);
|
||||
public final void toSQL(RenderContext ctx) {
|
||||
delegate(ctx.configuration(), ctx).toSQL(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
delegate(context.configuration(), null).bind(context);
|
||||
public final void bind(BindContext ctx) {
|
||||
delegate(ctx.configuration(), null).bind(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return new Clause[] { DUMMY };
|
||||
return delegate(ctx.configuration(), null).clauses(ctx);
|
||||
}
|
||||
|
||||
private final QueryPartInternal delegate(Configuration configuration, RenderContext context) {
|
||||
private final QueryPartInternal delegate(Configuration configuration, RenderContext ctx) {
|
||||
SQLDialect family = configuration.dialect().family();
|
||||
|
||||
// [#2395] These dialects have full native support for comparison
|
||||
@ -138,7 +137,7 @@ class RowSubqueryCondition extends AbstractCondition {
|
||||
|
||||
// [#2395] All other configurations have to be simulated
|
||||
else {
|
||||
String table = context == null ? "t" : context.nextAlias();
|
||||
String table = ctx == null ? "t" : ctx.nextAlias();
|
||||
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (int i = 0; i < left.size(); i++) {
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.FIELD;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.Field;
|
||||
@ -51,15 +49,15 @@ class SelectFieldList extends QueryPartList<Field<?>> {
|
||||
private static final long serialVersionUID = 8850104968428500798L;
|
||||
|
||||
SelectFieldList() {
|
||||
super(FIELD);
|
||||
super();
|
||||
}
|
||||
|
||||
SelectFieldList(Collection<? extends Field<?>> wrappedList) {
|
||||
super(FIELD, wrappedList);
|
||||
super(wrappedList);
|
||||
}
|
||||
|
||||
SelectFieldList(Field<?>... wrappedList) {
|
||||
super(FIELD, wrappedList);
|
||||
super(wrappedList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -36,7 +36,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
import static org.jooq.Clause.SELECT;
|
||||
import static org.jooq.Clause.SELECT_CONNECT_BY;
|
||||
import static org.jooq.Clause.SELECT_FROM;
|
||||
@ -153,7 +152,7 @@ class SelectQueryImpl<R extends Record> extends AbstractSelect<R> implements Sel
|
||||
this.condition = new ConditionProviderImpl();
|
||||
this.connectBy = new ConditionProviderImpl();
|
||||
this.connectByStartWith = new ConditionProviderImpl();
|
||||
this.groupBy = new QueryPartList<GroupField>(DUMMY);
|
||||
this.groupBy = new QueryPartList<GroupField>();
|
||||
this.having = new ConditionProviderImpl();
|
||||
this.orderBy = new SortFieldList();
|
||||
this.limit = new Limit();
|
||||
@ -162,7 +161,7 @@ class SelectQueryImpl<R extends Record> extends AbstractSelect<R> implements Sel
|
||||
this.from.add(from.asTable());
|
||||
}
|
||||
|
||||
this.forUpdateOf = new QueryPartList<Field<?>>(DUMMY);
|
||||
this.forUpdateOf = new QueryPartList<Field<?>>();
|
||||
this.forUpdateOfTables = new TableList();
|
||||
}
|
||||
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.DUMMY;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -57,7 +55,7 @@ class SortFieldList extends QueryPartList<SortField<?>> {
|
||||
}
|
||||
|
||||
SortFieldList(List<SortField<?>> wrappedList) {
|
||||
super(DUMMY, wrappedList);
|
||||
super(wrappedList);
|
||||
}
|
||||
|
||||
void addAll(Field<?>... fields) {
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.TABLE;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Field;
|
||||
@ -52,11 +50,11 @@ class TableList extends QueryPartList<Table<?>> {
|
||||
private static final long serialVersionUID = -8545559185481762229L;
|
||||
|
||||
TableList() {
|
||||
super(TABLE);
|
||||
super();
|
||||
}
|
||||
|
||||
TableList(List<? extends Table<?>> wrappedList) {
|
||||
super(TABLE, wrappedList);
|
||||
super(wrappedList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -128,7 +128,7 @@ class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
|
||||
super(configuration, table);
|
||||
|
||||
this.condition = new ConditionProviderImpl();
|
||||
this.updateMap = new FieldMapForUpdate();
|
||||
this.updateMap = new FieldMapForUpdate(UPDATE_SET_ASSIGNMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user