From c6d4705f72cdf8d89e054b460ddd486e6522c401 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 25 Aug 2021 09:32:29 +0200 Subject: [PATCH] [jOOQ/jOOQ#5306] Support the standard SQL --- jOOQ/src/main/java/org/jooq/impl/DSL.java | 36 ++++++++++++------- .../org/jooq/impl/DataChangeDeltaTable.java | 35 +++++++++++++++--- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index f3276c8791..4c7657e7fa 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -10899,7 +10899,7 @@ public class DSL { * {@link Delete} statement was applied. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table oldTable(Update query) { return new DataChangeDeltaTable<>(ResultOption.OLD, query); } @@ -10921,7 +10921,7 @@ public class DSL { * {@link Delete} statement was applied. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table oldTable(Merge query) { return new DataChangeDeltaTable<>(ResultOption.OLD, query); } @@ -10931,10 +10931,11 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This does not include trigger generated values. + * Depending on the dialect, this may show transitive data prior to + * referential integrity validation and the firing of any after triggers. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table newTable(Insert query) { return new DataChangeDeltaTable(ResultOption.NEW, query); } @@ -10944,10 +10945,11 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This does not include trigger generated values. + * Depending on the dialect, this may show transitive data prior to + * referential integrity validation and the firing of any after triggers. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table newTable(Update query) { return new DataChangeDeltaTable(ResultOption.NEW, query); } @@ -10957,10 +10959,11 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This does not include trigger generated values. + * Depending on the dialect, this may show transitive data prior to + * referential integrity validation and the firing of any after triggers. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table newTable(Merge query) { return new DataChangeDeltaTable(ResultOption.NEW, query); } @@ -10970,7 +10973,10 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This includes trigger generated values. + * Depending on the dialect, this may show data after all referential + * integrity validation and all triggers have been executed or fired, + * meaning there will be no more additional modification to the "final" + * version of the modified data. */ @NotNull @Support({ H2, POSTGRES }) @@ -10983,7 +10989,10 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This includes trigger generated values. + * Depending on the dialect, this may show data after all referential + * integrity validation and all triggers have been executed or fired, + * meaning there will be no more additional modification to the "final" + * version of the modified data. */ @NotNull @Support({ H2, POSTGRES }) @@ -10996,10 +11005,13 @@ public class DSL { * retrieve the modified data from after the {@link Update} or * {@link Insert} statement was applied. *

- * This includes trigger generated values. + * Depending on the dialect, this may show data after all referential + * integrity validation and all triggers have been executed or fired, + * meaning there will be no more additional modification to the "final" + * version of the modified data. */ @NotNull - @Support({ H2, POSTGRES }) + @Support({ H2 }) public static Table finalTable(Merge query) { return new DataChangeDeltaTable<>(ResultOption.FINAL, query); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DataChangeDeltaTable.java b/jOOQ/src/main/java/org/jooq/impl/DataChangeDeltaTable.java index a2eb289bfb..908c69119d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DataChangeDeltaTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/DataChangeDeltaTable.java @@ -50,7 +50,9 @@ import org.jooq.DMLQuery; import org.jooq.Delete; import org.jooq.Insert; import org.jooq.Merge; +import org.jooq.Name; import org.jooq.Record; +import org.jooq.Record1; import org.jooq.Table; import org.jooq.TableOptions; import org.jooq.Update; @@ -59,18 +61,28 @@ import org.jooq.Update; /** * @author Lukas Eder */ -final class DataChangeDeltaTable extends AbstractTable { +final class DataChangeDeltaTable extends AbstractTable implements AutoAliasTable { private final ResultOption result; private final DMLQuery query; private final Table table; + private final Name alias; DataChangeDeltaTable(ResultOption result, DMLQuery query) { - super(TableOptions.expression(), table(query).getUnqualifiedName()); + this(result, query, table(query)); + } + + private DataChangeDeltaTable(ResultOption result, DMLQuery query, Table table) { + this(result, query, table, table.getUnqualifiedName()); + } + + private DataChangeDeltaTable(ResultOption result, DMLQuery query, Table table, Name alias) { + super(TableOptions.expression(), alias); this.result = result; this.query = query; - this.table = table(query); + this.table = table; + this.alias = alias; } enum ResultOption { @@ -110,6 +122,21 @@ final class DataChangeDeltaTable extends AbstractTable { // XXX: Table API // ------------------------------------------------------------------------- + @Override + public Table as(Name as) { + return new TableAlias<>(new DataChangeDeltaTable<>(result, query, table, as), as); + } + + @Override + public Table as(Name as, Name... fieldAliases) { + return new TableAlias<>(new DataChangeDeltaTable<>(result, query, table, as), as, fieldAliases); + } + + @Override + public final Table autoAlias(Context ctx) { + return as(alias); + } + @Override public final Class getRecordType() { return table.getRecordType(); @@ -118,6 +145,6 @@ final class DataChangeDeltaTable extends AbstractTable { @SuppressWarnings("unchecked") @Override final FieldsImpl fields0() { - return ((AbstractRow) table.fieldsRow()).fields; + return ((AbstractRow) table.as(alias).fieldsRow()).fields; } }