[jOOQ/jOOQ#8012] Avoid aliased column fields in InlineDerivedTable

The aliased column fields were introduced as a workaround for a StackOverflowError where we try to access the fields of a Table while creating the field reference for the table itself.

But returning the aliased field references prevents schema mapping, which was discovered by some integration test.
This commit is contained in:
Lukas Eder 2023-05-25 11:27:01 +02:00
parent 537acb56a6
commit 0963ffff1b
3 changed files with 11 additions and 6 deletions

View File

@ -879,7 +879,7 @@ implements
// [#1199] The public API of Table returns immutable field lists
if (table instanceof TableImpl<?> t)
t.fields0().add(tableField);
t.fields.add(tableField);
return tableField;
}

View File

@ -39,6 +39,7 @@
package org.jooq.impl;
import static org.jooq.impl.DSL.selectFrom;
import static org.jooq.impl.DSL.table;
import org.jooq.Condition;
import org.jooq.QueryPart;
@ -47,8 +48,6 @@ import org.jooq.Record;
import org.jooq.Table;
// ...
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@ -90,13 +89,15 @@ final class InlineDerivedTable<R extends Record> extends DerivedTable<R> {
@Override
final FieldsImpl<R> fields0() {
// [#8012] Re-use the existing fields row if this is an aliased table
// [#8012] Re-use the existing fields row if this is an aliased table.
if (table instanceof TableAlias)
return new FieldsImpl<>(table.fields());
// [#8012] Re-wrap fields in new TableAlias to prevent StackOverflowError
// [#8012] Re-wrap fields in new TableAlias to prevent StackOverflowError.
// Cannot produce qualified table references here in case the
// InlineDerivedTable cannot be inlined.
else
return new FieldsImpl<>(table.as(table).fields());
return new FieldsImpl<>(Tools.qualify(table(table.getUnqualifiedName()), table.as(table).fields()));
}

View File

@ -6208,6 +6208,10 @@ final class Tools {
throw new UnsupportedOperationException("Unsupported field : " + field);
}
static final Field<?>[] qualify(Table<?> table, Field<?>[] fields) {
return map(fields, f -> qualify(table, f), Field<?>[]::new);
}
static final <T> Field<T> qualify(Table<?> table, Field<T> field) {
Field<T> result = table.field(field);