[jOOQ/jOOQ#9288] Added mappers for int[], String[], Name[], Field<?>[]

This includes:

- [jOOQ/jOOQ#3619] Result.intoGroups() and intoMap() do not run through
RecordListener
This commit is contained in:
Lukas Eder 2021-05-19 14:15:29 +02:00
parent 48e882081e
commit 8d39ea9f3f
6 changed files with 226 additions and 162 deletions

View File

@ -82,7 +82,7 @@ public final class Records {
* List&lt;String&gt; titles =
* ctx.select(BOOK.TITLE)
* .from(BOOK)
* .collect(toList());
* .collect(intoList());
* </pre></code>
* <p>
* This is the same as the following, but allows for omitting repeating the
@ -109,7 +109,7 @@ public final class Records {
* List&lt;String&gt; titles =
* ctx.select(BOOK.TITLE)
* .from(BOOK)
* .collect(toList(r -&gt; r.get(BOOK.TITLE)));
* .collect(intoList(r -&gt; r.get(BOOK.TITLE)));
* </pre></code>
* <p>
* This is the same as the following:
@ -136,7 +136,7 @@ public final class Records {
* Set&lt;String&gt; titles =
* ctx.select(BOOK.TITLE)
* .from(BOOK)
* .collect(toSet());
* .collect(intoSet());
* </pre></code>
* <p>
* This is the same as the following, but allows for omitting repeating the
@ -163,7 +163,7 @@ public final class Records {
* Set&lt;String&gt; titles =
* ctx.select(BOOK.TITLE)
* .from(BOOK)
* .collect(toSet(r -&gt; r.get(BOOK.TITLE)));
* .collect(intoSet(r -&gt; r.get(BOOK.TITLE)));
* </pre></code>
* <p>
* This is the same as the following:
@ -193,7 +193,7 @@ public final class Records {
* Map&lt;Integer, String&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toMap());
* .collect(intoMap());
* </pre></code>
* <p>
* This is the same as the following, but allows for omitting repeating the
@ -224,7 +224,7 @@ public final class Records {
* Map&lt;Integer, Record2&lt;Integer, String&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toMap(r -&gt; r.get(BOOK.ID)));
* .collect(intoMap(r -&gt; r.get(BOOK.ID)));
* </pre></code>
* <p>
* This is the same as the following:
@ -255,7 +255,7 @@ public final class Records {
* Map&lt;Integer, String&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toMap(r -&gt; r.get(BOOK.ID), r -&gt; r.get(BOOK.TITLE)));
* .collect(intoMap(r -&gt; r.get(BOOK.ID), r -&gt; r.get(BOOK.TITLE)));
* </pre></code>
* <p>
* This is the same as the following:
@ -292,7 +292,7 @@ public final class Records {
* Map&lt;Integer, List&lt;String&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toGroups());
* .collect(intoGroups());
* </pre></code>
* <p>
* This is the same as the following, but allows for omitting repeating the
@ -321,7 +321,7 @@ public final class Records {
* Map&lt;Integer, List&lt;Record2&lt;Integer, String&gt;&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toGroups(r -&gt; r.get(BOOK.ID)));
* .collect(intoGroups(r -&gt; r.get(BOOK.ID)));
* </pre></code>
* <p>
* This is the same as the following:
@ -333,26 +333,8 @@ public final class Records {
* .fetchGroups(BOOK.ID);
* </pre></code>
*/
@SuppressWarnings("unchecked")
public static final <K, R extends Record> Collector<R, ?, Map<K, Result<R>>> intoGroups(Function<? super R, ? extends K> keyMapper) {
return Collectors.groupingBy(
keyMapper,
LinkedHashMap::new,
Collector.<R, Result<R>[], Result<R>>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 <K, R extends Record> Collector<R, ?, Map<K, List<R>>> intoGroups(Function<? super R, ? extends K> keyMapper) {
return intoGroups(keyMapper, r -> r);
}
/**
@ -367,7 +349,7 @@ public final class Records {
* Map&lt;Integer, List&lt;String&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(toGroups(r -&gt; r.get(BOOK.ID), r -&gt; r.get(BOOK.TITLE)));
* .collect(intoGroups(r -&gt; r.get(BOOK.ID), r -&gt; r.get(BOOK.TITLE)));
* </pre></code>
* <p>
* 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}.
* <p>
* For example:
* <p>
* <code><pre>
* Map&lt;Integer, Result&lt;Record2&lt;Integer, String&gt;&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(intoResultGroups(r -&gt; r.get(BOOK.ID)));
* </pre></code>
* <p>
* This is the same as the following:
* <p>
* <code><pre>
* Map&lt;Integer, Result&lt;Record2&lt;Integer, String&gt;&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .fetchGroups(BOOK.ID);
* </pre></code>
*/
public static final <K, R extends Record> Collector<R, ?, Map<K, Result<R>>> intoResultGroups(Function<? super R, ? extends K> 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.
* <p>
* For example:
* <p>
* <code><pre>
* Map&lt;Integer, Result&lt;Record1&lt;String&gt;&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .collect(intoResultGroups(r -&gt; r.get(BOOK.ID), r -&gt; r.get(BOOK.TITLE)));
* </pre></code>
* <p>
* This is the same as the following:
* <p>
* <code><pre>
* Map&lt;Integer, Result&lt;Record1&lt;String&gt;&gt;&gt; books =
* ctx.select(BOOK.ID, BOOK.TITLE)
* .from(BOOK)
* .fetchGroups(BOOK.ID, BOOK.TITLE);
* </pre></code>
*/
@SuppressWarnings("unchecked")
public static final <K, V extends Record, R extends Record> Collector<R, ?, Map<K, Result<V>>> intoResultGroups(
Function<? super R, ? extends K> keyMapper,
Function<? super R, ? extends V> valueMapper
) {
return Collectors.groupingBy(
keyMapper,
LinkedHashMap::new,
Collector.<R, Result<V>[], Result<V>>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]
)
);
}
/**

View File

@ -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;

View File

@ -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<R extends Record> extends AbstractQueryPart implements Re
return r -> r.get(fieldIndex, converter);
}
@Override
public final RecordMapper<R, Record> mapper(int[] fieldIndexes) {
return mapper(fields(fieldIndexes));
}
@Override
public final RecordMapper<R, ?> mapper(String fieldName) {
return mapper(field(fieldName));
@ -120,6 +129,11 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
return r -> r.get(fieldName, converter);
}
@Override
public final RecordMapper<R, Record> mapper(String[] fieldNames) {
return mapper(fields(fieldNames));
}
@Override
public final RecordMapper<R, ?> mapper(Name fieldName) {
return mapper(field(fieldName));
@ -135,6 +149,11 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
return r -> r.get(fieldName, converter);
}
@Override
public final RecordMapper<R, Record> mapper(Name[] fieldNames) {
return mapper(fields(fieldNames));
}
@SuppressWarnings("unchecked")
@Override
public final <T> RecordMapper<R, T> mapper(Field<T> field) {
@ -153,6 +172,18 @@ final class FieldsImpl<R extends Record> extends AbstractQueryPart implements Re
return (RecordMapper<R, U>) mapper(indexOrFail(fieldsRow(), field), converter);
}
@Override
public final RecordMapper<R, Record> 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 <S extends Record> RecordMapper<R, S> mapper(Table<S> table) {
return r -> r.into(table);

View File

@ -75,6 +75,12 @@ interface Mappable<R extends Record> {
@NotNull
<U> RecordMapper<R, U> mapper(int fieldIndex, Converter<?, ? extends U> converter);
/**
* Create a record mapper that extracts values by field index.
*/
@NotNull
RecordMapper<R, Record> mapper(int[] fieldIndexes);
/**
* Create a record mapper that extracts a value by field name.
*/
@ -95,6 +101,12 @@ interface Mappable<R extends Record> {
@NotNull
<U> RecordMapper<R, U> mapper(String fieldName, Converter<?, ? extends U> converter);
/**
* Create a record mapper that extracts values by field name.
*/
@NotNull
RecordMapper<R, Record> mapper(String[] fieldNames);
/**
* Create a record mapper that extracts a value by field name.
*/
@ -115,6 +127,12 @@ interface Mappable<R extends Record> {
@NotNull
<U> RecordMapper<R, U> mapper(Name fieldName, Converter<?, ? extends U> converter);
/**
* Create a record mapper that extracts values by field name.
*/
@NotNull
RecordMapper<R, Record> mapper(Name[] fieldNames);
/**
* Create a record mapper that extracts a value by field reference.
*/
@ -135,6 +153,12 @@ interface Mappable<R extends Record> {
@NotNull
<T, U> RecordMapper<R, U> mapper(Field<T> field, Converter<? super T, ? extends U> converter);
/**
* Create a record mapper that extracts values by field reference.
*/
@NotNull
RecordMapper<R, Record> mapper(Field<?>[] fields);
/**
* Create a record mapper that maps records to a new
* {@link RecordQualifier#getRecordType()}.

View File

@ -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<R extends Record> extends AbstractResult<R> implements Re
@Override
public final Map<Record, R> intoMap(int[] keyFieldIndexes) {
return intoMap(fields(keyFieldIndexes));
return collect(Records.intoMap(recordType().mapper(keyFieldIndexes)));
}
@Override
public final Map<Record, R> intoMap(String[] keyFieldNames) {
return intoMap(fields(keyFieldNames));
return collect(Records.intoMap(recordType().mapper(keyFieldNames)));
}
@Override
public final Map<Record, R> intoMap(Name[] keyFieldNames) {
return intoMap(fields(keyFieldNames));
return collect(Records.intoMap(recordType().mapper(keyFieldNames)));
}
@Override
public final Map<Record, R> intoMap(Field<?>[] keys) {
AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys);
Map<Record, R> 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<Record, Record> 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<Record, Record> 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<Record, Record> 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<Record, Record> intoMap(Field<?>[] keys, Field<?>[] values) {
AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys);
AbstractRow valuesRow = Tools.row0(values == null ? EMPTY_FIELD : values);
Map<Record, Record> 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<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <K> Map<K, Result<R>> intoGroups(Field<K> key) {
return collect(Records.intoGroups(recordType().mapper(key)));
return collect(intoResultGroups(recordType().mapper(key)));
}
@Override
public final Map<?, Result<R>> intoGroups(int keyFieldIndex) {
return collect(Records.intoGroups(recordType().mapper(keyFieldIndex)));
return collect(intoResultGroups(recordType().mapper(keyFieldIndex)));
}
@Override
public final Map<?, Result<R>> intoGroups(String keyFieldName) {
return collect(Records.intoGroups(recordType().mapper(keyFieldName)));
return collect(intoResultGroups(recordType().mapper(keyFieldName)));
}
@Override
public final Map<?, Result<R>> intoGroups(Name keyFieldName) {
return collect(Records.intoGroups(recordType().mapper(keyFieldName)));
return collect(intoResultGroups(recordType().mapper(keyFieldName)));
}
@Override
@ -582,34 +549,22 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public final Map<Record, Result<R>> intoGroups(int[] keyFieldIndexes) {
return intoGroups(fields(keyFieldIndexes));
return collect(intoResultGroups(recordType().mapper(keyFieldIndexes)));
}
@Override
public final Map<Record, Result<R>> intoGroups(String[] keyFieldNames) {
return intoGroups(fields(keyFieldNames));
return collect(intoResultGroups(recordType().mapper(keyFieldNames)));
}
@Override
public final Map<Record, Result<R>> intoGroups(Name[] keyFieldNames) {
return intoGroups(fields(keyFieldNames));
return collect(intoResultGroups(recordType().mapper(keyFieldNames)));
}
@Override
public final Map<Record, Result<R>> intoGroups(Field<?>[] keys) {
AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys);
Map<Record, Result<R>> 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<R extends Record> extends AbstractResult<R> implements Re
@Override
public final Map<Record, Result<Record>> intoGroups(Field<?>[] keys, Field<?>[] values) {
AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys);
AbstractRow valuesRow = Tools.row0(values == null ? EMPTY_FIELD : values);
Map<Record, Result<Record>> 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 <E> Map<Record, List<E>> intoGroups(int[] keyFieldIndexes, Class<? extends E> 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 <E> Map<Record, List<E>> intoGroups(String[] keyFieldNames, Class<? extends E> 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 <E> Map<Record, List<E>> intoGroups(Name[] keyFieldNames, Class<? extends E> 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 <E> Map<Record, List<E>> intoGroups(Field<?>[] keys, Class<? extends E> 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 <E> Map<Record, List<E>> intoGroups(int[] keyFieldIndexes, RecordMapper<? super R, E> mapper) {
return intoGroups(fields(keyFieldIndexes), mapper);
return collect(Records.intoGroups(recordType().mapper(keyFieldIndexes), mapper));
}
@Override
public final <E> Map<Record, List<E>> intoGroups(String[] keyFieldNames, RecordMapper<? super R, E> mapper) {
return intoGroups(fields(keyFieldNames), mapper);
return collect(Records.intoGroups(recordType().mapper(keyFieldNames), mapper));
}
@Override
public final <E> Map<Record, List<E>> intoGroups(Name[] keyFieldNames, RecordMapper<? super R, E> mapper) {
return intoGroups(fields(keyFieldNames), mapper);
return collect(Records.intoGroups(recordType().mapper(keyFieldNames), mapper));
}
@Override
public final <E> Map<Record, List<E>> intoGroups(Field<?>[] keys, RecordMapper<? super R, E> mapper) {
AbstractRow keysRow = Tools.row0(keys == null ? EMPTY_FIELD : keys);
Map<Record, List<E>> 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 <K> Map<K, Result<R>> intoGroups(Class<? extends K> 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<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <K> Map<K, Result<R>> intoGroups(RecordMapper<? super R, K> keyMapper) {
return collect(Records.intoGroups(keyMapper));
return collect(intoResultGroups(keyMapper));
}
@Override
@ -733,7 +659,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <S extends Record> Map<S, Result<R>> intoGroups(Table<S> table) {
return collect(Records.intoGroups(recordType().mapper(table)));
return collect(intoResultGroups(recordType().mapper(table)));
}
@Override
@ -1019,7 +945,7 @@ final class ResultImpl<R extends Record> extends AbstractResult<R> implements Re
@Override
public final <E> List<E> into(Class<? extends E> type) {
return Tools.map(this, recordType().mapper(Tools.configuration(this), type)::map);
return collect(intoList(recordType().mapper(Tools.configuration(this), type)));
}
@Override

View File

@ -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<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <K> Map<K, Result<R>> fetchGroups(Field<K> key) {
return collect(intoGroups(mapper(key)));
return collect(intoResultGroups(mapper(key)));
}
@Override
default Map<?, Result<R>> fetchGroups(int keyFieldIndex) {
return collect(intoGroups(mapper(keyFieldIndex)));
return collect(intoResultGroups(mapper(keyFieldIndex)));
}
@Override
default Map<?, Result<R>> fetchGroups(String keyFieldName) {
return collect(intoGroups(mapper(keyFieldName)));
return collect(intoResultGroups(mapper(keyFieldName)));
}
@Override
default Map<?, Result<R>> fetchGroups(Name keyFieldName) {
return collect(intoGroups(mapper(keyFieldName)));
return collect(intoResultGroups(mapper(keyFieldName)));
}
@Override
@ -1111,87 +1116,87 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@Override
default Map<Record, Result<R>> fetchGroups(Field<?>[] keys) {
return fetch().intoGroups(keys);
return collect(intoResultGroups(mapper(keys)));
}
@Override
default Map<Record, Result<R>> fetchGroups(int[] keyFieldIndexes) {
return fetch().intoGroups(keyFieldIndexes);
return collect(intoResultGroups(mapper(keyFieldIndexes)));
}
@Override
default Map<Record, Result<R>> fetchGroups(String[] keyFieldNames) {
return fetch().intoGroups(keyFieldNames);
return collect(intoResultGroups(mapper(keyFieldNames)));
}
@Override
default Map<Record, Result<R>> fetchGroups(Name[] keyFieldNames) {
return fetch().intoGroups(keyFieldNames);
return collect(intoResultGroups(mapper(keyFieldNames)));
}
@Override
default Map<Record, Result<Record>> fetchGroups(Field<?>[] keys, Field<?>[] values) {
return fetch().intoGroups(keys, values);
return collect(intoResultGroups(mapper(keys), mapper(values)));
}
@Override
default Map<Record, Result<Record>> fetchGroups(int[] keyFieldIndexes, int[] valueFieldIndexes) {
return fetch().intoGroups(keyFieldIndexes, valueFieldIndexes);
return collect(intoResultGroups(mapper(keyFieldIndexes), mapper(valueFieldIndexes)));
}
@Override
default Map<Record, Result<Record>> fetchGroups(String[] keyFieldNames, String[] valueFieldNames) {
return fetch().intoGroups(keyFieldNames, valueFieldNames);
return collect(intoResultGroups(mapper(keyFieldNames), mapper(valueFieldNames)));
}
@Override
default Map<Record, Result<Record>> fetchGroups(Name[] keyFieldNames, Name[] valueFieldNames) {
return fetch().intoGroups(keyFieldNames, valueFieldNames);
return collect(intoResultGroups(mapper(keyFieldNames), mapper(valueFieldNames)));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(Field<?>[] keys, Class<? extends E> type) {
return fetch().intoGroups(keys, type);
return collect(intoGroups(mapper(keys), mapper(Tools.configuration(this), type)));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(int[] keyFieldIndexes, Class<? extends E> type) {
return fetch().intoGroups(keyFieldIndexes, type);
return collect(intoGroups(mapper(keyFieldIndexes), mapper(Tools.configuration(this), type)));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(String[] keyFieldNames, Class<? extends E> type) {
return fetch().intoGroups(keyFieldNames, type);
return collect(intoGroups(mapper(keyFieldNames), mapper(Tools.configuration(this), type)));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(Name[] keyFieldNames, Class<? extends E> type) {
return fetch().intoGroups(keyFieldNames, type);
return collect(intoGroups(mapper(keyFieldNames), mapper(Tools.configuration(this), type)));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(int[] keyFieldIndexes, RecordMapper<? super R, E> mapper) {
return fetch().intoGroups(keyFieldIndexes, mapper);
return collect(intoGroups(mapper(keyFieldIndexes), mapper));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(String[] keyFieldNames, RecordMapper<? super R, E> mapper) {
return fetch().intoGroups(keyFieldNames, mapper);
return collect(intoGroups(mapper(keyFieldNames), mapper));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(Name[] keyFieldNames, RecordMapper<? super R, E> mapper) {
return fetch().intoGroups(keyFieldNames, mapper);
return collect(intoGroups(mapper(keyFieldNames), mapper));
}
@Override
default <E> Map<Record, List<E>> fetchGroups(Field<?>[] keys, RecordMapper<? super R, E> mapper) {
return fetch().intoGroups(keys, mapper);
return collect(intoGroups(mapper(keys), mapper));
}
@Override
default <K> Map<K, Result<R>> fetchGroups(Class<? extends K> keyType) {
return collect(intoGroups(mapper(Tools.configuration(this), keyType)));
return collect(intoResultGroups(mapper(Tools.configuration(this), keyType)));
}
@Override
@ -1206,7 +1211,7 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <K> Map<K, Result<R>> fetchGroups(RecordMapper<? super R, K> keyMapper) {
return collect(intoGroups(keyMapper));
return collect(intoResultGroups(keyMapper));
}
@Override
@ -1221,13 +1226,12 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <S extends Record> Map<S, Result<R>> fetchGroups(Table<S> table) {
return collect(intoGroups(mapper(table)));
return collect(intoResultGroups(mapper(table)));
}
@Override
default <S extends Record, T extends Record> Map<S, Result<T>> fetchGroups(Table<S> keyTable, Table<T> 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<R extends Record> extends QueryPartInternal, ResultQu
@Override
default <E> List<E> fetch(RecordMapper<? super R, E> mapper) {
return fetch().map(mapper);
return collect(mapping(mapper, toList()));
}
default boolean hasLimit1() {
@ -1438,6 +1442,11 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
return new DelayedRecordMapper<>(t -> t.mapper(fieldIndex, converter));
}
@Override
default RecordMapper<R, Record> mapper(int[] fieldIndexes) {
return new DelayedRecordMapper<>(t -> t.mapper(fieldIndexes));
}
@Override
default RecordMapper<R, ?> mapper(String fieldName) {
return new DelayedRecordMapper<>(t -> t.mapper(fieldName));
@ -1453,6 +1462,11 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
return new DelayedRecordMapper<>(t -> t.mapper(fieldName, converter));
}
@Override
default RecordMapper<R, Record> mapper(String[] fieldNames) {
return new DelayedRecordMapper<>(t -> t.mapper(fieldNames));
}
@Override
default RecordMapper<R, ?> mapper(Name fieldName) {
return new DelayedRecordMapper<>(t -> t.mapper(fieldName));
@ -1468,6 +1482,11 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
return new DelayedRecordMapper<>(t -> t.mapper(fieldName, converter));
}
@Override
default RecordMapper<R, Record> mapper(Name[] fieldNames) {
return new DelayedRecordMapper<>(t -> t.mapper(fieldNames));
}
@Override
default <T> RecordMapper<R, T> mapper(Field<T> field) {
return new DelayedRecordMapper<>(t -> t.mapper(field));
@ -1483,6 +1502,11 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
return new DelayedRecordMapper<>(t -> t.mapper(field, converter));
}
@Override
default RecordMapper<R, Record> mapper(Field<?>[] fields) {
return new DelayedRecordMapper<>(t -> t.mapper(fields));
}
@Override
default <S extends Record> RecordMapper<R, S> mapper(Table<S> table) {
return new DelayedRecordMapper<>(t -> t.mapper(table));