[jOOQ/jOOQ#15732] Support nested MULTISET

This commit is contained in:
Lukas Eder 2024-03-27 18:05:27 +01:00
parent e460a873fe
commit 67f4a83d71
2 changed files with 14 additions and 5 deletions

View File

@ -40,6 +40,7 @@ package org.jooq.impl;
import static java.util.Arrays.asList;
import static org.jooq.impl.Tools.newRecord;
import java.sql.Array;
import java.sql.SQLException;
import java.sql.Struct;
import java.util.List;
@ -78,10 +79,12 @@ final class ListHandler<R extends Record> {
for (int i = 0; i < attributes.length && i < row.size(); i++) {
DataType<?> t = row.field(i).getDataType();
if (t.isMultiset() && attributes[i] instanceof List)
attributes[i] = new ListHandler(ctx, (AbstractRow<?>) t.getRow(), t.getRecordType()).read((List<Struct>) attributes[i]);
else if (t.isRecord() && attributes[i] instanceof Struct)
attributes[i] = new ListHandler(ctx, (AbstractRow<?>) t.getRow(), t.getRecordType()).read(asList((Struct) attributes[i])).get(0);
if (t.isMultiset() && attributes[i] instanceof List<?> l)
attributes[i] = new ListHandler(ctx, (AbstractRow<?>) t.getRow(), t.getRecordType()).read(l);
else if (t.isMultiset() && attributes[i] instanceof Array a)
attributes[i] = new ListHandler(ctx, (AbstractRow<?>) t.getRow(), t.getRecordType()).read(asList((Object[]) a.getArray()));
else if (t.isRecord() && attributes[i] instanceof Struct x)
attributes[i] = new ListHandler(ctx, (AbstractRow<?>) t.getRow(), t.getRecordType()).read(asList(x)).get(0);
}
r.fromArray(attributes);

View File

@ -43,6 +43,7 @@ import static org.jooq.impl.Tools.CONFIG;
import static org.jooq.impl.Tools.newRecord;
import static org.jooq.impl.Tools.recordType;
import java.sql.Struct;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -164,7 +165,12 @@ final class RecordDataType<R extends Record> extends DefaultDataType<R> {
return (R) object;
// [#12116] TODO: Move this logic into JSONReader to make it more generally useful
else if (object instanceof Record || object instanceof Map || object instanceof List) {
else if (
object instanceof Record
|| object instanceof Map
|| object instanceof List
|| object instanceof Struct
) {
return newRecord(true, getRecordType(), row, CONFIG.get())
.operate(r -> {