[jOOQ/jOOQ#13069] Support InlineDerivedTables

This commit is contained in:
Lukas Eder 2022-02-25 11:23:17 +01:00
parent 9330cb0783
commit 1519ead0c2
5 changed files with 39 additions and 27 deletions

View File

@ -152,6 +152,7 @@ import static org.jooq.impl.Tools.emulateMultiset;
import static org.jooq.impl.Tools.enums;
// ...
import static org.jooq.impl.Tools.getMappedUDTName;
import static org.jooq.impl.Tools.isEmpty;
import static org.jooq.impl.Tools.map;
import static org.jooq.impl.Tools.needsBackslashEscaping;
import static org.jooq.impl.Tools.newRecord;
@ -3779,10 +3780,12 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
}
static final <R extends Record> R readMultiset(BindingGetResultSetContext<?> ctx, DataType<R> type) throws SQLException {
return DefaultResultBinding.readMultiset(ctx, (AbstractRow<R>) type.getRow(), type.getType(),
s -> s.startsWith("[") || s.startsWith("{") ? "[" + s + "]" : s,
s -> s.startsWith("<") ? "<result>" + s + "</result>" : s
).get(0);
Result<R> result = DefaultResultBinding.readMultiset(ctx, (AbstractRow<R>) type.getRow(), type.getType(),
s -> s != null && (s.startsWith("[") || s.startsWith("{")) ? "[" + s + "]" : s,
s -> s != null && (s.startsWith("<")) ? "<result>" + s + "</result>" : s
);
return isEmpty(result) ? null : result.get(0);
}
@Override
@ -4019,16 +4022,19 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
case JSON:
case JSONB:
if (emulation == NestedCollectionEmulation.JSONB && EMULATE_AS_BLOB.contains(ctx.dialect()))
if (emulation == NestedCollectionEmulation.JSONB && EMULATE_AS_BLOB.contains(ctx.dialect())) {
byte[] bytes = ctx.resultSet().getBytes(ctx.index());
return apply(
jsonStringPatch.apply(Source.of(ctx.resultSet().getBytes(ctx.index()), ctx.configuration().charsetProvider().provide()).readString()),
jsonStringPatch.apply(bytes == null ? null : Source.of(bytes, ctx.configuration().charsetProvider().provide()).readString()),
s -> readMultisetJSON(ctx, row, recordType, s)
);
else
}
else {
return apply(
jsonStringPatch.apply(ctx.resultSet().getString(ctx.index())),
s -> readMultisetJSON(ctx, row, recordType, s)
);
}
case XML:
return apply(

View File

@ -39,7 +39,7 @@
package org.jooq.impl;
// ...
import static org.jooq.impl.Names.N_SELECT;
import static org.jooq.impl.Names.N_T;
import static org.jooq.impl.Tools.visitSubquery;
import org.jooq.Clause;
@ -59,7 +59,11 @@ class DerivedTable<R extends Record> extends AbstractTable<R> implements QOM.Der
private final Select<R> query;
DerivedTable(Select<R> query) {
super(TableOptions.expression(), N_SELECT);
this(query, N_T);
}
DerivedTable(Select<R> query, Name name) {
super(TableOptions.expression(), name);
this.query = query;
}

View File

@ -54,22 +54,14 @@ import org.jetbrains.annotations.NotNull;
*/
final class InlineDerivedTable<R extends Record> extends DerivedTable<R> {
private final Table<R> table;
private final Condition where;
final Table<R> table;
final Condition condition;
InlineDerivedTable(Table<R> table, Condition where) {
super(selectFrom(table).where(where));
InlineDerivedTable(Table<R> table, Condition condition) {
super(selectFrom(table).where(condition), table.getUnqualifiedName());
this.table = table;
this.where = where;
}
final Table<R> table() {
return table;
}
final Condition condition() {
return where;
this.condition = condition;
}
@Override

View File

@ -2526,8 +2526,8 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
private final void transformInlineDerivedTable0(Table<?> table, TableList result, ConditionProviderImpl where) {
if (table instanceof InlineDerivedTable) { InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
result.add(t.table());
where.addConditions(t.condition());
result.add(t.table);
where.addConditions(t.condition);
}
else if (table instanceof JoinTable)
result.add(transformInlineDerivedTables0(table, where, false));
@ -2538,10 +2538,10 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
private final Table<?> transformInlineDerivedTables0(Table<?> table, ConditionProviderImpl where, boolean keepDerivedTable) {
if (table instanceof InlineDerivedTable) { InlineDerivedTable<?> t = (InlineDerivedTable<?>) table;
if (keepDerivedTable)
return t.query().asTable(t.table());
return t.query().asTable(t.table);
where.addConditions(t.condition());
return t.table();
where.addConditions(t.condition);
return t.table;
}
else if (table instanceof JoinTable) { JoinTable j = (JoinTable) table;
Table<?> lhs;

View File

@ -306,6 +306,8 @@ implements
}
throw new DataAccessException("The to-one ROW convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition.");
@ -339,6 +341,8 @@ implements
}
throw new DataAccessException("The one-to-many MULTISET convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition.");
@ -373,6 +377,8 @@ implements
}
throw new DataAccessException("The many-to-many MULTISET convenience feature is available in the commercial jOOQ distribution only. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition.");
@ -475,6 +481,10 @@ implements