diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 683999762b..a8f94e2203 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -184,6 +184,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Struct; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; @@ -3801,8 +3802,8 @@ public class DefaultBinding implements Binding { AbstractRow row = (AbstractRow) type.getRow(); Result result; - // [#12930] AbstractRowAsSubquery doesn't unnecessarily nest Row1 - if (row.size() == 1) { + // [#12930] AbstractRowAsField doesn't unnecessarily nest Row1 + if (row.size() == 1 && emulateMultiset(ctx.configuration()) != NestedCollectionEmulation.NATIVE) { result = new ResultImpl<>(ctx.configuration(), row); result.add(newRecord(true, (Class) type.getRecordType(), row, ctx.configuration()).operate(r -> { DefaultBindingGetResultSetContext c = new DefaultBindingGetResultSetContext<>(ctx.executeContext(), ctx.resultSet(), ctx.index()); @@ -3813,8 +3814,9 @@ public class DefaultBinding implements Binding { } else result = DefaultResultBinding.readMultiset(ctx, row, type.getType(), - s -> s != null && (s.startsWith("[") || s.startsWith("{")) ? "[" + s + "]" : s, - s -> s != null && (s.startsWith("<")) ? "" + s + "" : s + s -> s != null && (s.startsWith("[") || s.startsWith("{")) ? "[" + s + "]" : null, + s -> s != null && (s.startsWith("<")) ? "" + s + "" : null, + s -> s instanceof Struct ? asList((Struct) s) : null ); return isEmpty(result) ? null : result.get(0); @@ -4035,7 +4037,7 @@ public class DefaultBinding implements Binding { @SuppressWarnings("unchecked") static final Result readMultiset(BindingGetResultSetContext ctx, DataType> type) throws SQLException { - return readMultiset(ctx, (AbstractRow) type.getRow(), (Class) type.getRecordType(), identity(), identity()); + return readMultiset(ctx, (AbstractRow) type.getRow(), (Class) type.getRecordType(), identity(), identity(), (Function) identity()); } static final Result readMultiset( @@ -4043,7 +4045,8 @@ public class DefaultBinding implements Binding { AbstractRow row, Class recordType, Function jsonStringPatch, - Function xmlStringPatch + Function xmlStringPatch, + Function> nativePatch ) throws SQLException { NestedCollectionEmulation emulation = emulateMultiset(ctx.configuration()); @@ -4073,26 +4076,42 @@ public class DefaultBinding implements Binding { xmlStringPatch.apply(ctx.resultSet().getString(ctx.index())), s -> readMultisetXML(ctx, row, recordType, s) ); + + + + + + + + + } throw new UnsupportedOperationException("Multiset emulation not yet supported: " + emulation); } - static Result readMultisetXML(Scope ctx, AbstractRow row, Class recordType, String s) { + + + + + + + + static final Result readMultisetXML(Scope ctx, AbstractRow row, Class recordType, String s) { if (s.startsWith("<")) return new XMLHandler<>(ctx.dsl(), row, recordType).read(s); else return readMultisetScalar(ctx, row, recordType, s); } - static Result readMultisetJSON(Scope ctx, AbstractRow row, Class recordType, String s) { + static final Result readMultisetJSON(Scope ctx, AbstractRow row, Class recordType, String s) { if (s.startsWith("{") || s.startsWith("[")) return new JSONReader<>(ctx.dsl(), row, recordType, true).read(new StringReader(s), true); else return readMultisetScalar(ctx, row, recordType, s); } - static Result readMultisetScalar(Scope ctx, AbstractRow row, Class recordType, String s) { + static final Result readMultisetScalar(Scope ctx, AbstractRow row, Class recordType, String s) { Result result = new ResultImpl<>(ctx.configuration(), row); result.add(newRecord(true, recordType, row, ctx.configuration()).operate(r -> { diff --git a/jOOQ/src/main/java/org/jooq/impl/ListHandler.java b/jOOQ/src/main/java/org/jooq/impl/ListHandler.java new file mode 100644 index 0000000000..aa6cfc5b2a --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/ListHandler.java @@ -0,0 +1,101 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static java.util.Arrays.asList; +import static org.jooq.impl.Tools.apply; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index 09a43854ce..b79caa7861 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -1895,7 +1895,7 @@ final class Tools { return it instanceof Collection ? new ArrayList<>(((Collection) it).size()) : new ArrayList<>(); } - static final R apply(@Nullable T t, Function f) { + static final R apply(@Nullable T t, ThrowingFunction f) throws X { return t == null ? null : f.apply(t); }