[#1711] Add <K, V> Map<K, List<V>> ResultQuery.fetchGroups(Class<K>, Class<V>) and many others

This commit is contained in:
lukaseder 2015-09-04 17:53:45 +02:00
parent 956b763bcb
commit 65557affd0
4 changed files with 720 additions and 9 deletions

View File

@ -1440,6 +1440,148 @@ public interface Result<R extends Record> extends List<R>, Attachable {
<E> Map<List<?>, E> intoMap(Name[] keyFieldNames, RecordMapper<? super R, E> mapper) throws IllegalArgumentException,
InvalidResultException, MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(Class)} instead, if your keys
* are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K> Map<K, R> intoMap(Class<? extends K> keyType) throws MappingException, InvalidResultException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(Class, Class)} instead, if your
* keys are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> intoMap(Class<? extends K> keyType, Class<? extends V> valueType)
throws MappingException, InvalidResultException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(Class, RecordMapper)} instead,
* if your keys are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> intoMap(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper)
throws InvalidResultException, MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(RecordMapper)} instead, if your
* keys are non-unique.
*
* @param keyMapper The key mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K> Map<K, R> intoMap(RecordMapper<? super R, K> keyMapper) throws InvalidResultException, MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(RecordMapper, Class)} instead,
* if your keys are non-unique.
*
* @param keyMapper The key mapper.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> intoMap(RecordMapper<? super R, K> keyMapper, Class<V> valueType)
throws InvalidResultException, MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(RecordMapper, RecordMapper)}
* instead, if your keys are non-unique.
*
* @param keyMapper The key mapper.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the keys are non-unique in the result
* set.
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> intoMap(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper)
throws InvalidResultException, MappingException;
/**
* Return a {@link Map} with the given key table as a map key and the
* corresponding record as value.
@ -1963,6 +2105,128 @@ public interface Result<R extends Record> extends List<R>, Attachable {
<E> Map<Record, List<E>> intoGroups(Name[] keyFieldNames, RecordMapper<? super R, E> mapper)
throws IllegalArgumentException, MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(Class)}, this method allows for non-unique keys in
* the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K> Map<K, Result<R>> intoGroups(Class<? extends K> keyType) throws MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(Class, Class)}, this method allows for non-unique
* keys in the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> intoGroups(Class<? extends K> keyType, Class<? extends V> valueType) throws MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(Class, RecordMapper)}, this method allows for
* non-unique keys in the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> intoGroups(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper)
throws MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(RecordMapper, RecordMapper)}, this method allows
* for non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K> Map<K, Result<R>> intoGroups(RecordMapper<? super R, K> keyMapper) throws MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(RecordMapper, Class)}, this method allows for
* non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> intoGroups(RecordMapper<? super R, K> keyMapper, Class<V> valueType) throws MappingException;
/**
* Return a {@link Map} with results grouped by the given key entity and
* mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #intoMap(RecordMapper, RecordMapper)}, this method allows
* for non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> intoGroups(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper)
throws MappingException;
/**
* Return a {@link Map} with the result grouped by the given key table.
* <p>

View File

@ -1596,12 +1596,163 @@ public interface ResultQuery<R extends Record> extends Query, Iterable<R> {
MappingException;
/**
* Execute the query and return a {@link Map} with table as a map key and the
* corresponding record as value.
* Execute the query and return a {@link Map} with results grouped by the
* given key entity.
* <p>
* An exception is thrown, if the keys turn out to be non-unique in the
* result set. Use {@link #fetchGroups(Table)} instead, if your keys are
* non-unique.
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(Class)} instead, if your keys
* are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(Class)
* @see DefaultRecordMapper
*/
<K> Map<K, R> fetchMap(Class<? extends K> keyType)
throws DataAccessException, MappingException, InvalidResultException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(Class, Class)} instead, if
* your keys are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(Class, Class)
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> fetchMap(Class<? extends K> keyType, Class<? extends V> valueType)
throws DataAccessException, MappingException, InvalidResultException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(Class, RecordMapper)} instead,
* if your keys are non-unique.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(Class, RecordMapper)
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> fetchMap(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper)
throws DataAccessException, InvalidResultException, MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(RecordMapper)} instead, if
* your keys are non-unique.
*
* @param keyMapper The key mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(RecordMapper)
* @see DefaultRecordMapper
*/
<K> Map<K, R> fetchMap(RecordMapper<? super R, K> keyMapper) throws DataAccessException,
InvalidResultException, MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(RecordMapper, Class)} instead,
* if your keys are non-unique.
*
* @param keyMapper The key mapper.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(RecordMapper, Class)
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> fetchMap(RecordMapper<? super R, K> keyMapper, Class<V> valueType) throws DataAccessException,
InvalidResultException, MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #fetchGroups(RecordMapper, RecordMapper)}
* instead, if your keys are non-unique.
*
* @param keyMapper The key mapper.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @see Result#intoMap(RecordMapper, RecordMapper)
* @see DefaultRecordMapper
*/
<K, V> Map<K, V> fetchMap(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper)
throws DataAccessException, InvalidResultException, MappingException;
/**
* Execute the query and return a {@link Map} with table as a map key and
* the corresponding record as value.
* <p>
* An {@link InvalidResultException} is thrown, if the keys turn out to be
* non-unique in the result set. Use {@link #fetchGroups(Table)} instead, if
* your keys are non-unique.
*
* @param table The key table. Client code must assure that keys are unique
* in the result set. May not be <code>null</code>.
@ -2165,6 +2316,131 @@ public interface ResultQuery<R extends Record> extends Query, Iterable<R> {
<E> Map<Record, List<E>> fetchGroups(Name[] keyFieldNames, RecordMapper<? super R, E> mapper)
throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(Class)}, this method allows for non-unique keys
* in the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K> Map<K, Result<R>> fetchGroups(Class<? extends K> keyType) throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(Class, Class)}, this method allows for non-unique
* keys in the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> fetchGroups(Class<? extends K> keyType, Class<? extends V> valueType)
throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(Class, RecordMapper)}, this method allows for
* non-unique keys in the result set.
*
* @param keyType The key type. If this is <code>null</code>, the resulting
* map will contain at most one entry.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> fetchGroups(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper)
throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(RecordMapper, RecordMapper)}, this method allows
* for non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K> Map<K, Result<R>> fetchGroups(RecordMapper<? super R, K> keyMapper) throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(RecordMapper, Class)}, this method allows for
* non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @param valueType The value type.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> fetchGroups(RecordMapper<? super R, K> keyMapper, Class<V> valueType)
throws MappingException;
/**
* Execute the query and return a {@link Map} with results grouped by the
* given key entity and mapped into the given entity type.
* <p>
* The grouping semantics is governed by the key type's
* {@link Object#equals(Object)} and {@link Object#hashCode()}
* implementation, not necessarily the values as fetched from the database.
* <p>
* Unlike {@link #fetchMap(RecordMapper, RecordMapper)}, this method allows
* for non-unique keys in the result set.
*
* @param keyMapper The key mapper.
* @param valueMapper The value mapper.
* @return A Map containing grouped results
* @throws MappingException wrapping any reflection or data type conversion
* exception that might have occurred while mapping records
* @see DefaultRecordMapper
*/
<K, V> Map<K, List<V>> fetchGroups(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper)
throws MappingException;
/**
* Execute the query and return a {@link Map} with the result grouped by the
* given table.

View File

@ -861,6 +861,36 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
return fetch().intoMap(keyFieldNames, mapper);
}
@Override
public final <K> Map<K, R> fetchMap(Class<? extends K> keyType) {
return fetch().intoMap(keyType);
}
@Override
public final <K, V> Map<K, V> fetchMap(Class<? extends K> keyType, Class<? extends V> valueType) {
return fetch().intoMap(keyType, valueType);
}
@Override
public final <K, V> Map<K, V> fetchMap(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper) {
return fetch().intoMap(keyType, valueMapper);
}
@Override
public final <K> Map<K, R> fetchMap(RecordMapper<? super R, K> keyMapper) {
return fetch().intoMap(keyMapper);
}
@Override
public final <K, V> Map<K, V> fetchMap(RecordMapper<? super R, K> keyMapper, Class<V> valueType) {
return fetch().intoMap(keyMapper, valueType);
}
@Override
public final <K, V> Map<K, V> fetchMap(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper) {
return fetch().intoMap(keyMapper, valueMapper);
}
@Override
public final <S extends Record> Map<S, R> fetchMap(Table<S> table) {
return fetch().intoMap(table);
@ -1021,6 +1051,36 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
return fetch().intoGroups(keys, mapper);
}
@Override
public final <K> Map<K, Result<R>> fetchGroups(Class<? extends K> keyType) {
return fetch().intoGroups(keyType);
}
@Override
public final <K, V> Map<K, List<V>> fetchGroups(Class<? extends K> keyType, Class<? extends V> valueType) {
return fetch().intoGroups(keyType, valueType);
}
@Override
public final <K, V> Map<K, List<V>> fetchGroups(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper) {
return fetch().intoGroups(keyType, valueMapper);
}
@Override
public final <K> Map<K, Result<R>> fetchGroups(RecordMapper<? super R, K> keyMapper) {
return fetch().intoGroups(keyMapper);
}
@Override
public final <K, V> Map<K, List<V>> fetchGroups(RecordMapper<? super R, K> keyMapper, Class<V> valueType) {
return fetch().intoGroups(keyMapper, valueType);
}
@Override
public final <K, V> Map<K, List<V>> fetchGroups(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper) {
return fetch().intoGroups(keyMapper, valueMapper);
}
@Override
public final <S extends Record> Map<S, Result<R>> fetchGroups(Table<S> table) {
return fetch().intoGroups(table);

View File

@ -1254,6 +1254,58 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
return map;
}
@Override
public final <K> Map<K, R> intoMap(Class<? extends K> keyType) {
return intoMap(Utils.configuration(this).recordMapperProvider().provide(fields, keyType));
}
@Override
public final <K, V> Map<K, V> intoMap(Class<? extends K> keyType, Class<? extends V> valueType) {
return intoMap(
Utils.configuration(this).recordMapperProvider().provide(fields, keyType),
Utils.configuration(this).recordMapperProvider().provide(fields, valueType)
);
}
@Override
public final <K, V> Map<K, V> intoMap(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper) {
return intoMap(Utils.configuration(this).recordMapperProvider().provide(fields, keyType), valueMapper);
}
@Override
public final <K> Map<K, R> intoMap(RecordMapper<? super R, K> keyMapper) {
Map<K, R> map = new LinkedHashMap<K, R>();
for (R record : this) {
K key = keyMapper.map(record);
if (map.put(key, record) != null)
throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this);
}
return map;
}
@Override
public final <K, V> Map<K, V> intoMap(RecordMapper<? super R, K> keyMapper, Class<V> valueType) {
return intoMap(keyMapper, Utils.configuration(this).recordMapperProvider().provide(fields, valueType));
}
@Override
public final <K, V> Map<K, V> intoMap(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper) {
Map<K, V> map = new LinkedHashMap<K, V>();
for (R record : this) {
K key = keyMapper.map(record);
V value = valueMapper.map(record);
if (map.put(key, value) != null)
throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this);
}
return map;
}
@Override
public final <S extends Record> Map<S, R> intoMap(Table<S> table) {
Map<S, R> map = new LinkedHashMap<S, R>();
@ -1261,9 +1313,8 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
for (R record : this) {
S key = record.into(table);
if (map.put(key, record) != null) {
if (map.put(key, record) != null)
throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this);
}
}
return map;
@ -1281,9 +1332,8 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
for (R record : this) {
S key = record.into(table);
if (map.put(key, mapper.map(record)) != null) {
if (map.put(key, mapper.map(record)) != null)
throw new InvalidResultException("Key list " + key + " is not unique in Result for " + this);
}
}
return map;
@ -1579,6 +1629,67 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
return map;
}
@Override
public final <K> Map<K, Result<R>> intoGroups(Class<? extends K> keyType) {
return intoGroups(Utils.configuration(this).recordMapperProvider().provide(fields, keyType));
}
@Override
public final <K, V> Map<K, List<V>> intoGroups(Class<? extends K> keyType, Class<? extends V> valueType) {
return intoGroups(
Utils.configuration(this).recordMapperProvider().provide(fields, keyType),
Utils.configuration(this).recordMapperProvider().provide(fields, valueType)
);
}
@Override
public final <K, V> Map<K, List<V>> intoGroups(Class<? extends K> keyType, RecordMapper<? super R, V> valueMapper) {
return intoGroups(Utils.configuration(this).recordMapperProvider().provide(fields, keyType), valueMapper);
}
@Override
public final <K> Map<K, Result<R>> intoGroups(RecordMapper<? super R, K> keyMapper) {
Map<K, Result<R>> map = new LinkedHashMap<K, Result<R>>();
for (R record : this) {
K key = keyMapper.map(record);
Result<R> result = map.get(key);
if (result == null) {
result = new ResultImpl(configuration(), fields());
map.put(key, result);
}
result.add(record);
}
return map;
}
@Override
public final <K, V> Map<K, List<V>> intoGroups(RecordMapper<? super R, K> keyMapper, Class<V> valueType) {
return intoGroups(keyMapper, Utils.configuration(this).recordMapperProvider().provide(fields, valueType));
}
@Override
public final <K, V> Map<K, List<V>> intoGroups(RecordMapper<? super R, K> keyMapper, RecordMapper<? super R, V> valueMapper) {
Map<K, List<V>> map = new LinkedHashMap<K, List<V>>();
for (R record : this) {
K key = keyMapper.map(record);
List<V> list = map.get(key);
if (list == null) {
list = new ArrayList<V>();
map.put(key, list);
}
list.add(valueMapper.map(record));
}
return map;
}
@Override
public final <S extends Record> Map<S, Result<R>> intoGroups(Table<S> table) {
Map<S, Result<R>> map = new LinkedHashMap<S, Result<R>>();