[jOOQ/jOOQ#1592] Added support for audit columns in embeddables

- AuditProvider callbacks should receive GeneratorContext, not DataType
- Added code generation tests (some still fail)
- Added integration tests (still fail)
- Flatten embeddables
  - in Tools::anyComputedOnClientStoredFields
  - in FieldMapsForInsert::keysFlattenedAndComputedOnClientStored

This includes:

- [jOOQ/jOOQ#9879] Retain aliasing of computed columns in projection
This commit is contained in:
Lukas Eder 2022-04-20 13:19:54 +02:00
parent 7740ce2ecd
commit 33b383b0a3
7 changed files with 36 additions and 10 deletions

View File

@ -89,10 +89,6 @@ package org.jooq.impl;

View File

@ -163,7 +163,7 @@ implements
// [#12925] Workaround for https://github.com/h2database/h2database/issues/3398
if (requiresWorkaroundFor12925(ctx))
ctx.sql("/* [#12925] ").sql(UUID.randomUUID().toString()).sql(" */ ");
ctx.sql("/* [#12925] ").sql(UUID.randomUUID().toString()).sql(" */").formatSeparator();
ctx.visit(query)
.sqlIndentEnd(')');

View File

@ -109,6 +109,8 @@ package org.jooq.impl;

View File

@ -38,6 +38,7 @@
package org.jooq.impl;
import static java.lang.Boolean.TRUE;
import static java.util.Arrays.asList;
import static java.util.Collections.emptySet;
import static org.jooq.Clause.FIELD_ROW;
import static org.jooq.Clause.INSERT_SELECT;
@ -56,6 +57,7 @@ import static org.jooq.impl.QueryPartCollectionView.wrap;
import static org.jooq.impl.Tools.anyMatch;
import static org.jooq.impl.Tools.filter;
import static org.jooq.impl.Tools.flatten;
import static org.jooq.impl.Tools.flattenCollection;
import static org.jooq.impl.Tools.flattenFieldOrRows;
import static org.jooq.impl.Tools.lazy;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_EMULATE_BULK_INSERT_RETURNING;

View File

@ -250,6 +250,7 @@ import org.jooq.Context;
import org.jooq.DataType;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.GeneratorStatementType;
import org.jooq.GroupField;
import org.jooq.JSONEntry;
import org.jooq.JSONObjectNullStep;
@ -3726,6 +3727,21 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp

View File

@ -138,6 +138,8 @@ class TableFieldImpl<R extends Record, T> extends AbstractField<T> implements Ta

View File

@ -5960,7 +5960,7 @@ final class Tools {
static final Row embeddedFieldsRow(Row row) {
if (hasEmbeddedFields(row.fields()))
return row(map(flattenCollection(Arrays.asList(row.fields()), false, false), f -> f));
return row(map(flattenCollection(Arrays.asList(row.fields())), f -> f));
else
return row;
}
@ -5973,7 +5973,7 @@ final class Tools {
// [#8353] [#10522] [#10523] TODO: Factor out some of this logic and
// reuse it for the emulation of UPDATE .. SET row = (SELECT ..)
List<Field<?>> select = field.query.getSelect();
List<Field<?>> result = collect(flattenCollection(select, false, false));
List<Field<?>> result = collect(flattenCollection(select));
Name tableName = name("t");
Name[] fieldNames = fieldNames(result.size());
Table<?> t = new AliasedSelect<>(field.query, true, true, fieldNames).as("t");
@ -6100,14 +6100,22 @@ final class Tools {
return () -> it2;
}
/**
* Flatten out {@link EmbeddableTableField} elements contained in an
* ordinary iterable.
*/
static final Iterable<Field<?>> flattenCollection(Iterable<? extends Field<?>> iterable) {
return flattenCollection(iterable, false, false);
}
/**
* Flatten out {@link EmbeddableTableField} elements contained in an
* ordinary iterable.
*/
static final Iterable<Field<?>> flattenCollection(
final Iterable<? extends Field<?>> iterable,
final boolean removeDuplicates,
final boolean flattenRowFields
Iterable<? extends Field<?>> iterable,
boolean removeDuplicates,
boolean flattenRowFields
) {
// [#2530] [#6124] [#10481] TODO: Refactor and optimise these flattening algorithms
return () -> new FlatteningIterator<>(iterable.iterator(), (e, duplicates) -> {