[jOOQ/jOOQ#15632] Support InlineDerivedTables in DELETE and INSERT
This includes: - [jOOQ/jOOQ#15634] Distinguish between Context::qualify and Context::qualifySchema
This commit is contained in:
parent
ef2b95eb46
commit
4168c15d2b
@ -800,8 +800,6 @@ public interface Context<C extends Context<C>> extends ExecuteScope {
|
||||
|
||||
/**
|
||||
* Set the new context value for {@link #qualify()}.
|
||||
* <p>
|
||||
* This is the same as {@link #qualifySchema(boolean)}.
|
||||
*/
|
||||
@NotNull
|
||||
C qualify(boolean qualify);
|
||||
@ -814,9 +812,7 @@ public interface Context<C extends Context<C>> extends ExecuteScope {
|
||||
C qualify(boolean qualify, Consumer<? super C> consumer);
|
||||
|
||||
/**
|
||||
* Whether query parts should render qualified names or not.
|
||||
* <p>
|
||||
* This is the same as {@link #qualifySchema()}.
|
||||
* Whether query parts should render {@link Schema}-qualified names or not.
|
||||
*/
|
||||
boolean qualifySchema();
|
||||
|
||||
@ -834,18 +830,12 @@ public interface Context<C extends Context<C>> extends ExecuteScope {
|
||||
C qualifySchema(boolean qualifySchema, Consumer<? super C> consumer);
|
||||
|
||||
/**
|
||||
* Whether query parts should render qualified names or not.
|
||||
* <p>
|
||||
* The catalog can only be qualified when {@link #qualifySchema()} is
|
||||
* <code>true</code> as well.
|
||||
* Whether query parts should render {@link Catalog}-qualified names or not.
|
||||
*/
|
||||
boolean qualifyCatalog();
|
||||
|
||||
/**
|
||||
* Set the new context value for {@link #qualifyCatalog()}.
|
||||
* <p>
|
||||
* The catalog can only be qualified when {@link #qualifySchema()} is
|
||||
* <code>true</code> as well.
|
||||
*/
|
||||
@NotNull
|
||||
C qualifyCatalog(boolean qualifyCatalog);
|
||||
@ -853,9 +843,6 @@ public interface Context<C extends Context<C>> extends ExecuteScope {
|
||||
/**
|
||||
* Set the new context value for {@link #qualifyCatalog()} for the scope of
|
||||
* a {@link Consumer}.
|
||||
* <p>
|
||||
* The catalog can only be qualified when {@link #qualifySchema()} is
|
||||
* <code>true</code> as well.
|
||||
*/
|
||||
@NotNull
|
||||
C qualifyCatalog(boolean qualifyCatalog, Consumer<? super C> consumer);
|
||||
|
||||
@ -161,6 +161,7 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
LanguageContext languageContext;
|
||||
ParamType paramType = ParamType.INDEXED;
|
||||
boolean quote = true;
|
||||
boolean qualify = true;
|
||||
boolean qualifySchema = true;
|
||||
boolean qualifyCatalog = true;
|
||||
QueryPart topLevel;
|
||||
@ -1027,12 +1028,13 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
|
||||
@Override
|
||||
public final boolean qualify() {
|
||||
return qualifySchema();
|
||||
return qualify;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final C qualify(boolean q) {
|
||||
return qualifySchema(q);
|
||||
this.qualify = q;
|
||||
return (C) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1042,7 +1044,7 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
|
||||
@Override
|
||||
public final boolean qualifySchema() {
|
||||
return qualifySchema;
|
||||
return qualify && qualifySchema;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1058,7 +1060,7 @@ abstract class AbstractContext<C extends Context<C>> extends AbstractScope imple
|
||||
|
||||
@Override
|
||||
public final boolean qualifyCatalog() {
|
||||
return qualifyCatalog;
|
||||
return qualify && qualifyCatalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1618,7 +1618,7 @@ implements
|
||||
private final Name getQualifiedName(Context<?> ctx) {
|
||||
List<Name> list = new ArrayList<>();
|
||||
|
||||
if (ctx.qualify()) {
|
||||
if (ctx.qualifySchema()) {
|
||||
Schema mapped = Tools.getMappedSchema(ctx, getSchema());
|
||||
|
||||
if (mapped != null && !"".equals(mapped.getName()))
|
||||
|
||||
@ -331,8 +331,6 @@ implements
|
||||
}
|
||||
|
||||
private final void acceptRenameTable(Context<?> ctx) {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
ctx.start(Clause.ALTER_SEQUENCE_SEQUENCE)
|
||||
.start(Clause.ALTER_SEQUENCE_RENAME)
|
||||
.visit(K_ALTER_TABLE)
|
||||
@ -341,7 +339,7 @@ implements
|
||||
.sql(' ')
|
||||
.visit(K_RENAME_TO)
|
||||
.sql(' ')
|
||||
.qualify(false, c -> c.visit(renameTo))
|
||||
.qualifySchema(false, c -> c.visit(renameTo))
|
||||
.end(Clause.ALTER_SEQUENCE_RENAME)
|
||||
.end(Clause.ALTER_SEQUENCE_SEQUENCE);
|
||||
}
|
||||
|
||||
@ -1823,8 +1823,6 @@ implements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -208,8 +208,6 @@ implements
|
||||
ctx.visit(getQualifiedName());
|
||||
}
|
||||
else {
|
||||
boolean qualify = ctx.qualify();
|
||||
|
||||
if (named )
|
||||
ctx.visit(K_CONSTRAINT).sql(' ')
|
||||
.visit(getUnqualifiedName()).sql(' ');
|
||||
|
||||
@ -148,6 +148,7 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
|
||||
this(context.configuration(), context.executeContext());
|
||||
|
||||
paramType(context.paramType());
|
||||
qualify(context.qualify());
|
||||
qualifyCatalog(context.qualifyCatalog());
|
||||
qualifySchema(context.qualifySchema());
|
||||
quote(context.quote());
|
||||
|
||||
@ -252,14 +252,14 @@ implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
accept0(ctx);
|
||||
// [#2682] [#15632] Apply inline derived tables to the target table (TODO: Apply also to USING, etc.)
|
||||
// [#15632] TODO: Check if this behaves correctly with aliases
|
||||
Table<?> t = InlineDerivedTable.inlineDerivedTable(ctx, table(ctx));
|
||||
if (t instanceof InlineDerivedTable<?> i) {
|
||||
copy(d -> d.addConditions(i.condition), i.table).accept0(ctx);
|
||||
}
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
||||
@ -376,24 +376,24 @@ implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
accept0(ctx);
|
||||
// [#2682] [#15632] Apply inline derived tables to the target table (TODO: Apply also to FROM, etc.)
|
||||
// [#15632] TODO: Check if this behaves correctly with aliases
|
||||
Table<?> t = InlineDerivedTable.inlineDerivedTable(ctx, table(ctx));
|
||||
if (t instanceof InlineDerivedTable<?> i) {
|
||||
copy(
|
||||
d -> {
|
||||
if (!d.insertMaps.values.isEmpty())
|
||||
d.select =
|
||||
selectFrom(
|
||||
d.insertMaps.insertSelect(ctx, null)
|
||||
.asTable(i.table, d.insertMaps.keysFlattened(ctx, GeneratorStatementType.INSERT)))
|
||||
.where(CustomCondition.of(c1 -> c1.qualifySchema(false, c2 -> c2.visit(i.condition))));
|
||||
},
|
||||
i.table
|
||||
).accept0(ctx);
|
||||
}
|
||||
else
|
||||
accept0(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -469,7 +469,7 @@ implements
|
||||
if (ctx.declareTables())
|
||||
ctx.scopeMarkStart(this);
|
||||
|
||||
if (ctx.qualify() && (ctx.declareTables()
|
||||
if (ctx.qualifySchema() && (ctx.declareTables()
|
||||
|| (!NO_SUPPORT_QUALIFIED_TVF_CALLS.contains(ctx.dialect()) || parameters == null)
|
||||
|
||||
|
||||
|
||||
@ -564,7 +564,8 @@ implements
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
|
||||
// [#2682] [#15632] Apply inline derived tables to the target table (TODO: Apply also to USING, etc.)
|
||||
// [#2682] [#15632] Apply inline derived tables to the target table (TODO: Apply also to FROM, etc.)
|
||||
// [#15632] TODO: Check if this behaves correctly with aliases
|
||||
Table<?> t = InlineDerivedTable.inlineDerivedTable(ctx, table(ctx));
|
||||
if (t instanceof InlineDerivedTable<?> i) {
|
||||
copy(d -> d.addConditions(i.condition), i.table).accept0(ctx);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user