From 8d39ea9f3f87e9db427752f698e8c34e3fb71d58 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 19 May 2021 14:15:29 +0200 Subject: [PATCH] [jOOQ/jOOQ#9288] Added mappers for int[], String[], Name[], Field[] This includes: - [jOOQ/jOOQ#3619] Result.intoGroups() and intoMap() do not run through RecordListener --- jOOQ/src/main/java/org/jooq/Records.java | 121 ++++++++++++---- .../java/org/jooq/impl/AbstractResult.java | 2 - .../main/java/org/jooq/impl/FieldsImpl.java | 31 ++++ .../src/main/java/org/jooq/impl/Mappable.java | 24 ++++ .../main/java/org/jooq/impl/ResultImpl.java | 134 ++++-------------- .../java/org/jooq/impl/ResultQueryTrait.java | 76 ++++++---- 6 files changed, 226 insertions(+), 162 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/Records.java b/jOOQ/src/main/java/org/jooq/Records.java index 7a269b1df6..05a6b4e222 100644 --- a/jOOQ/src/main/java/org/jooq/Records.java +++ b/jOOQ/src/main/java/org/jooq/Records.java @@ -82,7 +82,7 @@ public final class Records { * List<String> titles = * ctx.select(BOOK.TITLE) * .from(BOOK) - * .collect(toList()); + * .collect(intoList()); * *

* This is the same as the following, but allows for omitting repeating the @@ -109,7 +109,7 @@ public final class Records { * List<String> titles = * ctx.select(BOOK.TITLE) * .from(BOOK) - * .collect(toList(r -> r.get(BOOK.TITLE))); + * .collect(intoList(r -> r.get(BOOK.TITLE))); * *

* This is the same as the following: @@ -136,7 +136,7 @@ public final class Records { * Set<String> titles = * ctx.select(BOOK.TITLE) * .from(BOOK) - * .collect(toSet()); + * .collect(intoSet()); * *

* This is the same as the following, but allows for omitting repeating the @@ -163,7 +163,7 @@ public final class Records { * Set<String> titles = * ctx.select(BOOK.TITLE) * .from(BOOK) - * .collect(toSet(r -> r.get(BOOK.TITLE))); + * .collect(intoSet(r -> r.get(BOOK.TITLE))); * *

* This is the same as the following: @@ -193,7 +193,7 @@ public final class Records { * Map<Integer, String> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toMap()); + * .collect(intoMap()); * *

* This is the same as the following, but allows for omitting repeating the @@ -224,7 +224,7 @@ public final class Records { * Map<Integer, Record2<Integer, String>> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toMap(r -> r.get(BOOK.ID))); + * .collect(intoMap(r -> r.get(BOOK.ID))); * *

* This is the same as the following: @@ -255,7 +255,7 @@ public final class Records { * Map<Integer, String> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toMap(r -> r.get(BOOK.ID), r -> r.get(BOOK.TITLE))); + * .collect(intoMap(r -> r.get(BOOK.ID), r -> r.get(BOOK.TITLE))); * *

* This is the same as the following: @@ -292,7 +292,7 @@ public final class Records { * Map<Integer, List<String>> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toGroups()); + * .collect(intoGroups()); * *

* This is the same as the following, but allows for omitting repeating the @@ -321,7 +321,7 @@ public final class Records { * Map<Integer, List<Record2<Integer, String>>> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toGroups(r -> r.get(BOOK.ID))); + * .collect(intoGroups(r -> r.get(BOOK.ID))); * *

* This is the same as the following: @@ -333,26 +333,8 @@ public final class Records { * .fetchGroups(BOOK.ID); * */ - @SuppressWarnings("unchecked") - public static final Collector>> intoGroups(Function keyMapper) { - return Collectors.groupingBy( - keyMapper, - LinkedHashMap::new, - Collector.[], Result>of( - () -> new Result[1], - (x, r) -> { - if (x[0] == null) - x[0] = Internal.result(r); - - x[0].add(r); - }, - (r1, r2) -> { - r1[0].addAll(r2[0]); - return r1; - }, - r -> r[0] - ) - ); + public static final Collector>> intoGroups(Function keyMapper) { + return intoGroups(keyMapper, r -> r); } /** @@ -367,7 +349,7 @@ public final class Records { * Map<Integer, List<String>> books = * ctx.select(BOOK.ID, BOOK.TITLE) * .from(BOOK) - * .collect(toGroups(r -> r.get(BOOK.ID), r -> r.get(BOOK.TITLE))); + * .collect(intoGroups(r -> r.get(BOOK.ID), r -> r.get(BOOK.TITLE))); * *

* This is the same as the following: @@ -393,6 +375,85 @@ public final class Records { ); } + /** + * Create a collector that can collect {@link Record} resulting from a + * {@link ResultQuery} into a {@link Map} using the result of the argument + * {@link RecordMapper} as key collecting the records themselves into a + * {@link Result}. + *

+ * For example: + *

+ *

+     * Map<Integer, Result<Record2<Integer, String>>> books =
+     * ctx.select(BOOK.ID, BOOK.TITLE)
+     *    .from(BOOK)
+     *    .collect(intoResultGroups(r -> r.get(BOOK.ID)));
+     * 
+ *

+ * This is the same as the following: + *

+ *

+     * Map<Integer, Result<Record2<Integer, String>>> books =
+     * ctx.select(BOOK.ID, BOOK.TITLE)
+     *    .from(BOOK)
+     *    .fetchGroups(BOOK.ID);
+     * 
+ */ + public static final Collector>> intoResultGroups(Function keyMapper) { + return intoResultGroups(keyMapper, r -> r); + } + + /** + * Create a collector that can collect {@link Record} resulting from a + * {@link ResultQuery} into a {@link Map} using the result of the argument + * {@link RecordMapper} as key collecting the result of another argument + * {@link RecordMapper} into a {@link Result} of values. + *

+ * For example: + *

+ *

+     * Map<Integer, Result<Record1<String>>> books =
+     * ctx.select(BOOK.ID, BOOK.TITLE)
+     *    .from(BOOK)
+     *    .collect(intoResultGroups(r -> r.get(BOOK.ID), r -> r.get(BOOK.TITLE)));
+     * 
+ *

+ * This is the same as the following: + *

+ *

+     * Map<Integer, Result<Record1<String>>> books =
+     * ctx.select(BOOK.ID, BOOK.TITLE)
+     *    .from(BOOK)
+     *    .fetchGroups(BOOK.ID, BOOK.TITLE);
+     * 
+ */ + @SuppressWarnings("unchecked") + public static final Collector>> intoResultGroups( + Function keyMapper, + Function valueMapper + ) { + return Collectors.groupingBy( + keyMapper, + LinkedHashMap::new, + Collector.[], Result>of( + () -> new Result[1], + (x, r) -> { + V v = valueMapper.apply(r); + + if (x[0] == null) + x[0] = Internal.result(v); + + x[0].add(v); + }, + (r1, r2) -> { + r1[0].addAll(r2[0]); + return r1; + }, + r -> r[0] + ) + ); + } + /** diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractResult.java b/jOOQ/src/main/java/org/jooq/impl/AbstractResult.java index af240449ee..9ac9314c4c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractResult.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractResult.java @@ -62,7 +62,6 @@ import java.util.Deque; import java.util.Iterator; import java.util.List; import java.util.TreeMap; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.xml.bind.DatatypeConverter; @@ -88,7 +87,6 @@ import org.jooq.JSONFormat; import org.jooq.Name; import org.jooq.Param; import org.jooq.Record; -import org.jooq.RecordType; import org.jooq.Result; import org.jooq.Row; import org.jooq.Schema; diff --git a/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java b/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java index fc10138e2e..4a9243fc60 100644 --- a/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java @@ -43,12 +43,15 @@ import static org.jooq.impl.Tools.EMPTY_FIELD; import static org.jooq.impl.Tools.converterOrFail; import static org.jooq.impl.Tools.indexOrFail; import static org.jooq.impl.Tools.map; +import static org.jooq.impl.Tools.newRecord; import java.sql.SQLWarning; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.stream.Stream; import org.jooq.Configuration; @@ -60,6 +63,7 @@ import org.jooq.Name; import org.jooq.Record; import org.jooq.RecordMapper; import org.jooq.RecordType; +import org.jooq.Result; import org.jooq.Row; import org.jooq.SelectField; import org.jooq.Table; @@ -105,6 +109,11 @@ final class FieldsImpl extends AbstractQueryPart implements Re return r -> r.get(fieldIndex, converter); } + @Override + public final RecordMapper mapper(int[] fieldIndexes) { + return mapper(fields(fieldIndexes)); + } + @Override public final RecordMapper mapper(String fieldName) { return mapper(field(fieldName)); @@ -120,6 +129,11 @@ final class FieldsImpl extends AbstractQueryPart implements Re return r -> r.get(fieldName, converter); } + @Override + public final RecordMapper mapper(String[] fieldNames) { + return mapper(fields(fieldNames)); + } + @Override public final RecordMapper mapper(Name fieldName) { return mapper(field(fieldName)); @@ -135,6 +149,11 @@ final class FieldsImpl extends AbstractQueryPart implements Re return r -> r.get(fieldName, converter); } + @Override + public final RecordMapper mapper(Name[] fieldNames) { + return mapper(fields(fieldNames)); + } + @SuppressWarnings("unchecked") @Override public final RecordMapper mapper(Field field) { @@ -153,6 +172,18 @@ final class FieldsImpl extends AbstractQueryPart implements Re return (RecordMapper) mapper(indexOrFail(fieldsRow(), field), converter); } + @Override + public final RecordMapper mapper(Field[] f) { + AbstractRow row = Tools.row0(f == null ? EMPTY_FIELD : f); + + return r -> newRecord(false, AbstractRecord.class, row, r.configuration()).operate(x -> { + for (Field field : row.fields.fields) + Tools.copyValue((AbstractRecord) x, field, r, field); + + return x; + }); + } + @Override public final RecordMapper mapper(Table table) { return r -> r.into(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/Mappable.java b/jOOQ/src/main/java/org/jooq/impl/Mappable.java index 6475e59559..0e194f2f5f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Mappable.java +++ b/jOOQ/src/main/java/org/jooq/impl/Mappable.java @@ -75,6 +75,12 @@ interface Mappable { @NotNull RecordMapper mapper(int fieldIndex, Converter converter); + /** + * Create a record mapper that extracts values by field index. + */ + @NotNull + RecordMapper mapper(int[] fieldIndexes); + /** * Create a record mapper that extracts a value by field name. */ @@ -95,6 +101,12 @@ interface Mappable { @NotNull RecordMapper mapper(String fieldName, Converter converter); + /** + * Create a record mapper that extracts values by field name. + */ + @NotNull + RecordMapper mapper(String[] fieldNames); + /** * Create a record mapper that extracts a value by field name. */ @@ -115,6 +127,12 @@ interface Mappable { @NotNull RecordMapper mapper(Name fieldName, Converter converter); + /** + * Create a record mapper that extracts values by field name. + */ + @NotNull + RecordMapper mapper(Name[] fieldNames); + /** * Create a record mapper that extracts a value by field reference. */ @@ -135,6 +153,12 @@ interface Mappable { @NotNull RecordMapper mapper(Field field, Converter converter); + /** + * Create a record mapper that extracts values by field reference. + */ + @NotNull + RecordMapper mapper(Field[] fields); + /** * Create a record mapper that maps records to a new * {@link RecordQualifier#getRecordType()}. diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index 1ad99f0af0..6d1b828112 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -39,8 +39,7 @@ package org.jooq.impl; import static org.jooq.Records.intoList; -import static org.jooq.impl.Tools.EMPTY_FIELD; -import static org.jooq.impl.Tools.converterOrFail; +import static org.jooq.Records.intoResultGroups; import static org.jooq.impl.Tools.indexOrFail; import java.lang.reflect.Array; @@ -51,7 +50,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -289,73 +287,42 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map intoMap(int[] keyFieldIndexes) { - return intoMap(fields(keyFieldIndexes)); + return collect(Records.intoMap(recordType().mapper(keyFieldIndexes))); } @Override public final Map intoMap(String[] keyFieldNames) { - return intoMap(fields(keyFieldNames)); + return collect(Records.intoMap(recordType().mapper(keyFieldNames))); } @Override public final Map intoMap(Name[] keyFieldNames) { - return intoMap(fields(keyFieldNames)); + return collect(Records.intoMap(recordType().mapper(keyFieldNames))); } @Override public final Map intoMap(Field[] keys) { - AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys); - - Map map = new LinkedHashMap<>(); - for (R record : this) { - RecordImplN key = new RecordImplN(keysRow); - - for (Field field : keysRow.fields.fields) - Tools.copyValue(key, field, record, field); - - if (map.put(key, record) != null) - throw new InvalidResultException("Key list " + keysRow + " is not unique in Result for " + this); - } - - return map; + return collect(Records.intoMap(recordType().mapper(keys))); } @Override public final Map intoMap(int[] keyFieldIndexes, int[] valueFieldIndexes) { - return intoMap(fields(keyFieldIndexes), fields(valueFieldIndexes)); + return collect(Records.intoMap(recordType().mapper(keyFieldIndexes), recordType().mapper(valueFieldIndexes))); } @Override public final Map intoMap(String[] keyFieldNames, String[] valueFieldNames) { - return intoMap(fields(keyFieldNames), fields(valueFieldNames)); + return collect(Records.intoMap(recordType().mapper(keyFieldNames), recordType().mapper(valueFieldNames))); } @Override public final Map intoMap(Name[] keyFieldNames, Name[] valueFieldNames) { - return intoMap(fields(keyFieldNames), fields(valueFieldNames)); + return collect(Records.intoMap(recordType().mapper(keyFieldNames), recordType().mapper(valueFieldNames))); } @Override public final Map intoMap(Field[] keys, Field[] values) { - AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys); - AbstractRow valuesRow = Tools.row0(values == null ? EMPTY_FIELD : values); - - Map map = new LinkedHashMap<>(); - for (R record : this) { - RecordImplN key = new RecordImplN(keysRow); - RecordImplN value = new RecordImplN(valuesRow); - - for (Field field : keysRow.fields.fields) - Tools.copyValue(key, field, record, field); - - for (Field field : valuesRow.fields.fields) - Tools.copyValue(value, field, record, field); - - if (map.put(key, value) != null) - throw new InvalidResultException("Key list " + keysRow + " is not unique in Result for " + this); - } - - return map; + return collect(Records.intoMap(recordType().mapper(keys), recordType().mapper(values))); } @Override @@ -502,22 +469,22 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map> intoGroups(Field key) { - return collect(Records.intoGroups(recordType().mapper(key))); + return collect(intoResultGroups(recordType().mapper(key))); } @Override public final Map> intoGroups(int keyFieldIndex) { - return collect(Records.intoGroups(recordType().mapper(keyFieldIndex))); + return collect(intoResultGroups(recordType().mapper(keyFieldIndex))); } @Override public final Map> intoGroups(String keyFieldName) { - return collect(Records.intoGroups(recordType().mapper(keyFieldName))); + return collect(intoResultGroups(recordType().mapper(keyFieldName))); } @Override public final Map> intoGroups(Name keyFieldName) { - return collect(Records.intoGroups(recordType().mapper(keyFieldName))); + return collect(intoResultGroups(recordType().mapper(keyFieldName))); } @Override @@ -582,34 +549,22 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map> intoGroups(int[] keyFieldIndexes) { - return intoGroups(fields(keyFieldIndexes)); + return collect(intoResultGroups(recordType().mapper(keyFieldIndexes))); } @Override public final Map> intoGroups(String[] keyFieldNames) { - return intoGroups(fields(keyFieldNames)); + return collect(intoResultGroups(recordType().mapper(keyFieldNames))); } @Override public final Map> intoGroups(Name[] keyFieldNames) { - return intoGroups(fields(keyFieldNames)); + return collect(intoResultGroups(recordType().mapper(keyFieldNames))); } @Override public final Map> intoGroups(Field[] keys) { - AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys); - - Map> map = new LinkedHashMap<>(); - for (R record : this) { - RecordImplN key = new RecordImplN(keysRow); - - for (Field field : keysRow.fields.fields) - Tools.copyValue(key, field, record, field); - - map.computeIfAbsent(key, k -> new ResultImpl<>(Tools.configuration(this), this.fields)).add(record); - } - - return map; + return collect(intoResultGroups(recordType().mapper(keys))); } @Override @@ -629,81 +584,52 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map> intoGroups(Field[] keys, Field[] values) { - AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys); - AbstractRow valuesRow = Tools.row0(values == null ? EMPTY_FIELD : values); - - Map> map = new LinkedHashMap<>(); - for (R record : this) { - RecordImplN key = new RecordImplN(keysRow); - RecordImplN value = new RecordImplN(valuesRow); - - for (Field field : keysRow.fields.fields) - Tools.copyValue(key, field, record, field); - - for (Field field : valuesRow.fields.fields) - Tools.copyValue(value, field, record, field); - - map.computeIfAbsent(key, k -> new ResultImpl<>(Tools.configuration(this), valuesRow)).add(value); - } - - return map; + return collect(intoResultGroups(recordType().mapper(keys), recordType().mapper(values))); } @Override public final Map> intoGroups(int[] keyFieldIndexes, Class type) { - return intoGroups(keyFieldIndexes, recordType().mapper(Tools.configuration(this), type)); + return collect(Records.intoGroups(recordType().mapper(keyFieldIndexes), recordType().mapper(Tools.configuration(this), type))); } @Override public final Map> intoGroups(String[] keyFieldNames, Class type) { - return intoGroups(keyFieldNames, recordType().mapper(Tools.configuration(this), type)); + return collect(Records.intoGroups(recordType().mapper(keyFieldNames), recordType().mapper(Tools.configuration(this), type))); } @Override public final Map> intoGroups(Name[] keyFieldNames, Class type) { - return intoGroups(keyFieldNames, recordType().mapper(Tools.configuration(this), type)); + return collect(Records.intoGroups(recordType().mapper(keyFieldNames), recordType().mapper(Tools.configuration(this), type))); } @Override public final Map> intoGroups(Field[] keys, Class type) { - return intoGroups(keys, recordType().mapper(Tools.configuration(this), type)); + return collect(Records.intoGroups(recordType().mapper(keys), recordType().mapper(Tools.configuration(this), type))); } @Override public final Map> intoGroups(int[] keyFieldIndexes, RecordMapper mapper) { - return intoGroups(fields(keyFieldIndexes), mapper); + return collect(Records.intoGroups(recordType().mapper(keyFieldIndexes), mapper)); } @Override public final Map> intoGroups(String[] keyFieldNames, RecordMapper mapper) { - return intoGroups(fields(keyFieldNames), mapper); + return collect(Records.intoGroups(recordType().mapper(keyFieldNames), mapper)); } @Override public final Map> intoGroups(Name[] keyFieldNames, RecordMapper mapper) { - return intoGroups(fields(keyFieldNames), mapper); + return collect(Records.intoGroups(recordType().mapper(keyFieldNames), mapper)); } @Override public final Map> intoGroups(Field[] keys, RecordMapper mapper) { - AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys); - - Map> map = new LinkedHashMap<>(); - for (R record : this) { - RecordImplN key = new RecordImplN(keysRow); - - for (Field field : keysRow.fields.fields) - Tools.copyValue(key, field, record, field); - - map.computeIfAbsent(key, k -> new ArrayList<>()).add(mapper.map(record)); - } - - return map; + return collect(Records.intoGroups(recordType().mapper(keys), mapper)); } @Override public final Map> intoGroups(Class keyType) { - return collect(Records.intoGroups(recordType().mapper(Tools.configuration(this), keyType))); + return collect(intoResultGroups(recordType().mapper(Tools.configuration(this), keyType))); } @Override @@ -718,7 +644,7 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map> intoGroups(RecordMapper keyMapper) { - return collect(Records.intoGroups(keyMapper)); + return collect(intoResultGroups(keyMapper)); } @Override @@ -733,7 +659,7 @@ final class ResultImpl extends AbstractResult implements Re @Override public final Map> intoGroups(Table table) { - return collect(Records.intoGroups(recordType().mapper(table))); + return collect(intoResultGroups(recordType().mapper(table))); } @Override @@ -1019,7 +945,7 @@ final class ResultImpl extends AbstractResult implements Re @Override public final List into(Class type) { - return Tools.map(this, recordType().mapper(Tools.configuration(this), type)::map); + return collect(intoList(recordType().mapper(Tools.configuration(this), type))); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultQueryTrait.java b/jOOQ/src/main/java/org/jooq/impl/ResultQueryTrait.java index 829db086a5..7baa0867b2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultQueryTrait.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultQueryTrait.java @@ -37,9 +37,12 @@ */ package org.jooq.impl; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.toList; import static org.jooq.Records.intoGroups; import static org.jooq.Records.intoList; import static org.jooq.Records.intoMap; +import static org.jooq.Records.intoResultGroups; import static org.jooq.Records.intoSet; import static org.jooq.conf.SettingsTools.fetchIntermediateResult; import static org.jooq.impl.Tools.blocking; @@ -61,6 +64,7 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collector; +import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -95,6 +99,7 @@ import org.jooq.Record8; import org.jooq.Record9; import org.jooq.RecordHandler; import org.jooq.RecordMapper; +import org.jooq.Records; import org.jooq.Result; import org.jooq.ResultQuery; import org.jooq.Results; @@ -1031,22 +1036,22 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu @Override default Map> fetchGroups(Field key) { - return collect(intoGroups(mapper(key))); + return collect(intoResultGroups(mapper(key))); } @Override default Map> fetchGroups(int keyFieldIndex) { - return collect(intoGroups(mapper(keyFieldIndex))); + return collect(intoResultGroups(mapper(keyFieldIndex))); } @Override default Map> fetchGroups(String keyFieldName) { - return collect(intoGroups(mapper(keyFieldName))); + return collect(intoResultGroups(mapper(keyFieldName))); } @Override default Map> fetchGroups(Name keyFieldName) { - return collect(intoGroups(mapper(keyFieldName))); + return collect(intoResultGroups(mapper(keyFieldName))); } @Override @@ -1111,87 +1116,87 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu @Override default Map> fetchGroups(Field[] keys) { - return fetch().intoGroups(keys); + return collect(intoResultGroups(mapper(keys))); } @Override default Map> fetchGroups(int[] keyFieldIndexes) { - return fetch().intoGroups(keyFieldIndexes); + return collect(intoResultGroups(mapper(keyFieldIndexes))); } @Override default Map> fetchGroups(String[] keyFieldNames) { - return fetch().intoGroups(keyFieldNames); + return collect(intoResultGroups(mapper(keyFieldNames))); } @Override default Map> fetchGroups(Name[] keyFieldNames) { - return fetch().intoGroups(keyFieldNames); + return collect(intoResultGroups(mapper(keyFieldNames))); } @Override default Map> fetchGroups(Field[] keys, Field[] values) { - return fetch().intoGroups(keys, values); + return collect(intoResultGroups(mapper(keys), mapper(values))); } @Override default Map> fetchGroups(int[] keyFieldIndexes, int[] valueFieldIndexes) { - return fetch().intoGroups(keyFieldIndexes, valueFieldIndexes); + return collect(intoResultGroups(mapper(keyFieldIndexes), mapper(valueFieldIndexes))); } @Override default Map> fetchGroups(String[] keyFieldNames, String[] valueFieldNames) { - return fetch().intoGroups(keyFieldNames, valueFieldNames); + return collect(intoResultGroups(mapper(keyFieldNames), mapper(valueFieldNames))); } @Override default Map> fetchGroups(Name[] keyFieldNames, Name[] valueFieldNames) { - return fetch().intoGroups(keyFieldNames, valueFieldNames); + return collect(intoResultGroups(mapper(keyFieldNames), mapper(valueFieldNames))); } @Override default Map> fetchGroups(Field[] keys, Class type) { - return fetch().intoGroups(keys, type); + return collect(intoGroups(mapper(keys), mapper(Tools.configuration(this), type))); } @Override default Map> fetchGroups(int[] keyFieldIndexes, Class type) { - return fetch().intoGroups(keyFieldIndexes, type); + return collect(intoGroups(mapper(keyFieldIndexes), mapper(Tools.configuration(this), type))); } @Override default Map> fetchGroups(String[] keyFieldNames, Class type) { - return fetch().intoGroups(keyFieldNames, type); + return collect(intoGroups(mapper(keyFieldNames), mapper(Tools.configuration(this), type))); } @Override default Map> fetchGroups(Name[] keyFieldNames, Class type) { - return fetch().intoGroups(keyFieldNames, type); + return collect(intoGroups(mapper(keyFieldNames), mapper(Tools.configuration(this), type))); } @Override default Map> fetchGroups(int[] keyFieldIndexes, RecordMapper mapper) { - return fetch().intoGroups(keyFieldIndexes, mapper); + return collect(intoGroups(mapper(keyFieldIndexes), mapper)); } @Override default Map> fetchGroups(String[] keyFieldNames, RecordMapper mapper) { - return fetch().intoGroups(keyFieldNames, mapper); + return collect(intoGroups(mapper(keyFieldNames), mapper)); } @Override default Map> fetchGroups(Name[] keyFieldNames, RecordMapper mapper) { - return fetch().intoGroups(keyFieldNames, mapper); + return collect(intoGroups(mapper(keyFieldNames), mapper)); } @Override default Map> fetchGroups(Field[] keys, RecordMapper mapper) { - return fetch().intoGroups(keys, mapper); + return collect(intoGroups(mapper(keys), mapper)); } @Override default Map> fetchGroups(Class keyType) { - return collect(intoGroups(mapper(Tools.configuration(this), keyType))); + return collect(intoResultGroups(mapper(Tools.configuration(this), keyType))); } @Override @@ -1206,7 +1211,7 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu @Override default Map> fetchGroups(RecordMapper keyMapper) { - return collect(intoGroups(keyMapper)); + return collect(intoResultGroups(keyMapper)); } @Override @@ -1221,13 +1226,12 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu @Override default Map> fetchGroups(Table table) { - return collect(intoGroups(mapper(table))); + return collect(intoResultGroups(mapper(table))); } @Override default Map> fetchGroups(Table keyTable, Table valueTable) { - // [#9288] TODO: Can't use collect(intoGroups(recordType().mapper(keyTable), recordType().mapper(valueTable))) yet - return fetch().intoGroups(keyTable, valueTable); + return collect(intoResultGroups(mapper(keyTable), mapper(valueTable))); } @Override @@ -1407,7 +1411,7 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu @Override default List fetch(RecordMapper mapper) { - return fetch().map(mapper); + return collect(mapping(mapper, toList())); } default boolean hasLimit1() { @@ -1438,6 +1442,11 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu return new DelayedRecordMapper<>(t -> t.mapper(fieldIndex, converter)); } + @Override + default RecordMapper mapper(int[] fieldIndexes) { + return new DelayedRecordMapper<>(t -> t.mapper(fieldIndexes)); + } + @Override default RecordMapper mapper(String fieldName) { return new DelayedRecordMapper<>(t -> t.mapper(fieldName)); @@ -1453,6 +1462,11 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu return new DelayedRecordMapper<>(t -> t.mapper(fieldName, converter)); } + @Override + default RecordMapper mapper(String[] fieldNames) { + return new DelayedRecordMapper<>(t -> t.mapper(fieldNames)); + } + @Override default RecordMapper mapper(Name fieldName) { return new DelayedRecordMapper<>(t -> t.mapper(fieldName)); @@ -1468,6 +1482,11 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu return new DelayedRecordMapper<>(t -> t.mapper(fieldName, converter)); } + @Override + default RecordMapper mapper(Name[] fieldNames) { + return new DelayedRecordMapper<>(t -> t.mapper(fieldNames)); + } + @Override default RecordMapper mapper(Field field) { return new DelayedRecordMapper<>(t -> t.mapper(field)); @@ -1483,6 +1502,11 @@ interface ResultQueryTrait extends QueryPartInternal, ResultQu return new DelayedRecordMapper<>(t -> t.mapper(field, converter)); } + @Override + default RecordMapper mapper(Field[] fields) { + return new DelayedRecordMapper<>(t -> t.mapper(fields)); + } + @Override default RecordMapper mapper(Table table) { return new DelayedRecordMapper<>(t -> t.mapper(table));