From 9ea2499c2968da3aa5b8eeae108443fc421ae833 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 3 Mar 2015 15:44:48 +0100 Subject: [PATCH] [#3801] Add Result#intoMap and Result#intoGroups variants that take field index or field name --- jOOQ/src/main/java/org/jooq/Result.java | 531 +++++++++++++++++- jOOQ/src/main/java/org/jooq/ResultQuery.java | 526 +++++++++++++++++ .../org/jooq/impl/AbstractResultQuery.java | 188 ++++++- .../main/java/org/jooq/impl/ResultImpl.java | 227 +++++++- .../main/java/org/jooq/impl/SelectImpl.java | 185 +++++- 5 files changed, 1586 insertions(+), 71 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/Result.java b/jOOQ/src/main/java/org/jooq/Result.java index ac3c4b7c2e..15e8d33679 100644 --- a/jOOQ/src/main/java/org/jooq/Result.java +++ b/jOOQ/src/main/java/org/jooq/Result.java @@ -653,6 +653,42 @@ public interface Result extends List, Attachable { */ Map intoMap(Field key) throws IllegalArgumentException, InvalidResultException; + /** + * Return a {@link Map} with one of the result's columns as key and the + * corresponding records as value. + *

+ * An {@link InvalidResultException} is thrown, if the key turns out to be + * non-unique in the result set. Use {@link #intoGroups(int)} instead, if + * your keys are non-unique + * + * @param keyFieldIndex The key field index. Client code must assure that + * this field is unique in the result set. + * @return A Map containing the results + * @throws IllegalArgumentException If the argument keyFieldIndex is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + */ + Map intoMap(int keyFieldIndex) throws IllegalArgumentException, InvalidResultException; + + /** + * Return a {@link Map} with one of the result's columns as key and the + * corresponding records as value. + *

+ * An {@link InvalidResultException} is thrown, if the key turns out to be + * non-unique in the result set. Use {@link #intoGroups(String)} instead, if + * your keys are non-unique + * + * @param keyFieldName The key field name. Client code must assure that this + * field is unique in the result set. + * @return A Map containing the results + * @throws IllegalArgumentException If the argument keyFieldName is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + */ + Map intoMap(String keyFieldName) throws IllegalArgumentException, InvalidResultException; + /** * Return a {@link Map} with one of the result's columns as key and another * one of the result's columns as value @@ -674,6 +710,46 @@ public interface Result extends List, Attachable { */ Map intoMap(Field key, Field value) throws IllegalArgumentException, InvalidResultException; + /** + * Return a {@link Map} with one of the result's columns as key and another + * one of the result's columns as value + *

+ * An {@link InvalidResultException} is thrown, if the key turns out to be + * non-unique in the result set. Use {@link #intoGroups(int, int)} instead, + * if your keys are non-unique + * + * @param keyFieldIndex The key field index. Client code must assure that + * this field is unique in the result set. + * @param valueFieldIndex The value field index + * @return A Map containing the results + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + */ + Map intoMap(int keyFieldIndex, int valueFieldIndex) throws IllegalArgumentException, + InvalidResultException; + + /** + * Return a {@link Map} with one of the result's columns as key and another + * one of the result's columns as value + *

+ * An {@link InvalidResultException} is thrown, if the key turns out to be + * non-unique in the result set. Use {@link #intoGroups(String, String)} + * instead, if your keys are non-unique + * + * @param key The key field name. Client code must assure that this field is + * unique in the result set. + * @param value The value field name + * @return A Map containing the results + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + */ + Map intoMap(String keyFieldName, String valueFieldName) throws IllegalArgumentException, + InvalidResultException; + /** * Return a {@link Map} with results grouped by the given key and mapped * into the given entity type. @@ -697,6 +773,52 @@ public interface Result extends List, Attachable { Map intoMap(Field key, Class type) throws IllegalArgumentException, InvalidResultException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the key is non-unique in + * the result set. Use {@link #intoGroups(int, Class)} instead, if your + * key is non-unique. + * + * @param keyFieldIndex The key. Client code must assure that key is unique + * in the result set. + * @param type The entity type. + * @return A Map containing the result. + * @throws IllegalArgumentException If the argument field index is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map intoMap(int keyFieldIndex, Class type) throws IllegalArgumentException, + InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the key is non-unique in + * the result set. Use {@link #intoGroups(String, Class)} instead, if your + * key is non-unique. + * + * @param keyFieldName The key. Client code must assure that key is unique + * in the result set. + * @param type The entity type. + * @return A Map containing the result. + * @throws IllegalArgumentException If the argument field name is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map intoMap(String keyFieldName, Class type) throws IllegalArgumentException, + InvalidResultException, MappingException; + /** * Return a {@link Map} with results grouped by the given key and mapped by * the given mapper. @@ -720,6 +842,52 @@ public interface Result extends List, Attachable { Map intoMap(Field key, RecordMapper mapper) throws IllegalArgumentException, InvalidResultException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the key is non-unique in + * the result set. Use {@link #intoGroups(int, Class)} instead, if your key + * is non-unique. + * + * @param keyFieldIndex The key. Client code must assure that key is unique + * in the result set. + * @param mapper The mapper callback. + * @return A Map containing the result. + * @throws IllegalArgumentException If the argument field index is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map intoMap(int keyFieldIndex, RecordMapper mapper) throws IllegalArgumentException, + InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the key is non-unique in + * the result set. Use {@link #intoGroups(String, Class)} instead, if your key + * is non-unique. + * + * @param keyFieldName The key. Client code must assure that key is unique + * in the result set. + * @param mapper The mapper callback. + * @return A Map containing the result. + * @throws IllegalArgumentException If the argument field name is not + * contained in {@link #fieldsRow()} + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map intoMap(String keyFieldName, RecordMapper mapper) throws IllegalArgumentException, + InvalidResultException, MappingException; + /** * Return a {@link Map} with the given keys as a map key and the * corresponding record as value. @@ -739,6 +907,44 @@ public interface Result extends List, Attachable { */ Map intoMap(Field[] keys) throws IllegalArgumentException, InvalidResultException; + /** + * Return a {@link Map} with the given keys as a map key and the + * corresponding record as value. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(int[])} instead, if your keys + * are non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + */ + Map intoMap(int[] keyFieldIndexes) throws IllegalArgumentException, InvalidResultException; + + /** + * Return a {@link Map} with the given keys as a map key and the + * corresponding record as value. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(String[])} instead, if your + * keys are non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + */ + Map intoMap(String[] keyFieldNames) throws IllegalArgumentException, InvalidResultException; + /** * Return a {@link Map} with results grouped by the given keys and mapped * into the given entity type. @@ -763,9 +969,58 @@ public interface Result extends List, Attachable { Map, E> intoMap(Field[] keys, Class type) throws IllegalArgumentException, InvalidResultException, MappingException; + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(int[], Class)} instead, if your + * keys are non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map, E> intoMap(int[] keyFieldIndexes, Class type) throws IllegalArgumentException, + InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(String[], Class)} instead, if your + * keys are non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map, E> intoMap(String[] keyFieldNames, Class type) throws IllegalArgumentException, + InvalidResultException, MappingException; + /** * Return a {@link Map} with results grouped by the given keys and mapped by - * the given mapper. *

+ * the given mapper. + *

* An {@link InvalidResultException} is thrown, if the keys are non-unique * in the result set. Use {@link #intoGroups(Field[], Class)} instead, if * your keys are non-unique. @@ -786,6 +1041,54 @@ public interface Result extends List, Attachable { Map, E> intoMap(Field[] keys, RecordMapper mapper) throws IllegalArgumentException, InvalidResultException, MappingException; + /** + * Return a {@link Map} with results grouped by the given keys and mapped by + * the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(int[], Class)} instead, if your + * keys are non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map, E> intoMap(int[] keyFieldIndexes, RecordMapper mapper) throws IllegalArgumentException, + InvalidResultException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given keys and mapped by + * the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #intoGroups(String[], Class)} instead, if + * your keys are non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing the results. + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map, E> intoMap(String[] keyFieldNames, RecordMapper mapper) throws IllegalArgumentException, + InvalidResultException, MappingException; + /** * Return a {@link Map} with the given key table as a map key and the * corresponding record as value. @@ -865,6 +1168,34 @@ public interface Result extends List, Attachable { */ Map> intoGroups(Field key) throws IllegalArgumentException; + /** + * Return a {@link Map} with one of the result's columns as key and a list + * of corresponding records as value. + *

+ * Unlike {@link #intoMap(int)}, this method allows for non-unique keys in + * the result set. + * + * @param keyFieldIndex The key field index. + * @return A Map containing the results + * @throws IllegalArgumentException If the argument field index is not + * contained in {@link #fieldsRow()} + */ + Map> intoGroups(int keyFieldIndex) throws IllegalArgumentException; + + /** + * Return a {@link Map} with one of the result's columns as key and a list + * of corresponding records as value. + *

+ * Unlike {@link #intoMap(String)}, this method allows for non-unique keys in + * the result set. + * + * @param keyFieldName The key field name. + * @return A Map containing the results + * @throws IllegalArgumentException If the argument field name is not + * contained in {@link #fieldsRow()} + */ + Map> intoGroups(String keyFieldName) throws IllegalArgumentException; + /** * Return a {@link Map} with one of the result's columns as key and another * one of the result's columns as value. @@ -882,6 +1213,36 @@ public interface Result extends List, Attachable { */ Map> intoGroups(Field key, Field value) throws IllegalArgumentException; + /** + * Return a {@link Map} with one of the result's columns as key and another + * one of the result's columns as value. + *

+ * Unlike {@link #intoMap(int, int)}, this method allows for non-unique keys + * in the result set. + * + * @param keyFieldIndex The key field index. + * @param valueFieldIndex The value field index. + * @return A Map containing the results + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + */ + Map> intoGroups(int keyFieldIndex, int valueFieldIndex) throws IllegalArgumentException; + + /** + * Return a {@link Map} with one of the result's columns as key and another + * one of the result's columns as value. + *

+ * Unlike {@link #intoMap(String, String)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldName The key field name. + * @param valueFieldName The value field name. + * @return A Map containing the results + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + */ + Map> intoGroups(String keyFieldName, String valueFieldName) throws IllegalArgumentException; + /** * Return a {@link Map} with results grouped by the given key and mapped * into the given entity type. @@ -900,6 +1261,38 @@ public interface Result extends List, Attachable { Map> intoGroups(Field key, Class type) throws IllegalArgumentException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + *

+ * + * @param keyFieldIndex The key field index. + * @param type The entity type. + * @throws IllegalArgumentException If the argument field index is not + * contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(int keyFieldIndex, Class type) throws IllegalArgumentException, + MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + *

+ * + * @param keyFieldName The key field name. + * @param type The entity type. + * @throws IllegalArgumentException If the argument field name is not + * contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(String keyFieldName, Class type) throws IllegalArgumentException, + MappingException; + /** * Return a {@link Map} with results grouped by the given key and mapped by * the given mapper. @@ -916,6 +1309,34 @@ public interface Result extends List, Attachable { Map> intoGroups(Field key, RecordMapper mapper) throws IllegalArgumentException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + * + * @param keyFieldIndex The key field index. + * @param mapper The mapper callback. + * @throws IllegalArgumentException If the argument field index is not + * contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + */ + Map> intoGroups(int keyFieldIndex, RecordMapper mapper) throws IllegalArgumentException, + MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + * + * @param keyFieldName The key field name. + * @param mapper The mapper callback. + * @throws IllegalArgumentException If the argument field name is not + * contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + */ + Map> intoGroups(String keyFieldName, RecordMapper mapper) throws IllegalArgumentException, + MappingException; + /** * Return a {@link Map} with the result grouped by the given keys. *

@@ -930,6 +1351,34 @@ public interface Result extends List, Attachable { */ Map> intoGroups(Field[] keys) throws IllegalArgumentException; + /** + * Return a {@link Map} with the result grouped by the given keys. + *

+ * Unlike {@link #intoMap(int[])}, this method allows for non-unique keys + * in the result set. + * + * @param keyFieldIndexes The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @return A Map containing grouped results + * @throws IllegalArgumentException If any of the argument field indexes is + * not contained in {@link #fieldsRow()} + */ + Map> intoGroups(int[] keyFieldIndexes) throws IllegalArgumentException; + + /** + * Return a {@link Map} with the result grouped by the given keys. + *

+ * Unlike {@link #intoMap(String[])}, this method allows for non-unique keys + * in the result set. + * + * @param keyFieldNames The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @return A Map containing grouped results + * @throws IllegalArgumentException If any of the argument field names is + * not contained in {@link #fieldsRow()} + */ + Map> intoGroups(String[] keyFieldNames) throws IllegalArgumentException; + /** * Return a {@link Map} with results grouped by the given keys and mapped * into the given entity type. @@ -950,6 +1399,46 @@ public interface Result extends List, Attachable { Map> intoGroups(Field[] keys, Class type) throws IllegalArgumentException, MappingException; + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * Unlike {@link #intoMap(int[], Class)}, this method allows for non-unique + * keys in the result set. + * + * @param keyFieldIndexes The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing grouped results + * @throws IllegalArgumentException If the any of the argument field indexes + * is not contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(int[] keyFieldIndexes, Class type) throws IllegalArgumentException, + MappingException; + + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * Unlike {@link #intoMap(String[], Class)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldNames The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing grouped results + * @throws IllegalArgumentException If the any of the argument field names + * is not contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(String[] keyFieldNames, Class type) throws IllegalArgumentException, + MappingException; + /** * Return a {@link Map} with results grouped by the given keys and mapped * into the given entity type. @@ -970,6 +1459,46 @@ public interface Result extends List, Attachable { Map> intoGroups(Field[] keys, RecordMapper mapper) throws IllegalArgumentException, MappingException; + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * Unlike {@link #intoMap(int[], RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldIndexes The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing grouped results + * @throws IllegalArgumentException If the any of the argument field indexes + * is not contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(int[] keyFieldIndexes, RecordMapper mapper) + throws IllegalArgumentException, MappingException; + + /** + * Return a {@link Map} with results grouped by the given keys and mapped + * into the given entity type. + *

+ * Unlike {@link #intoMap(String[], RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldNames The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing grouped results + * @throws IllegalArgumentException If the any of the argument field indexes + * is not contained in {@link #fieldsRow()} + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see DefaultRecordMapper + */ + Map> intoGroups(String[] keyFieldNames, RecordMapper mapper) + throws IllegalArgumentException, MappingException; + /** * Return a {@link Map} with the result grouped by the given key table. *

diff --git a/jOOQ/src/main/java/org/jooq/ResultQuery.java b/jOOQ/src/main/java/org/jooq/ResultQuery.java index 4c3c69b519..416ca0b80a 100644 --- a/jOOQ/src/main/java/org/jooq/ResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/ResultQuery.java @@ -784,6 +784,50 @@ public interface ResultQuery extends Query, Iterable { */ Map fetchMap(Field key) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and the corresponding records as value. + *

+ * An exception is thrown, if the key turns out to be non-unique in the + * result set. Use {@link #fetchGroups(int)} instead, if your keys are + * non-unique + *

+ * The resulting records are attached to the original {@link Configuration} + * by default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param keyFieldIndex The key field. Client code must assure that this + * field is unique in the result set. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + * @see Result#intoMap(int) + */ + Map fetchMap(int keyFieldIndex) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and the corresponding records as value. + *

+ * An exception is thrown, if the key turns out to be non-unique in the + * result set. Use {@link #fetchGroups(String)} instead, if your keys are + * non-unique + *

+ * The resulting records are attached to the original {@link Configuration} + * by default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param keyFieldName The key field. Client code must assure that this + * field is unique in the result set. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + * @see Result#intoMap(String) + */ + Map fetchMap(String keyFieldName) throws DataAccessException; + /** * Execute the query and return a {@link Map} with one of the result's * columns as key and another one of the result's columns as value @@ -805,6 +849,44 @@ public interface ResultQuery extends Query, Iterable { */ Map fetchMap(Field key, Field value) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and another one of the result's columns as value + *

+ * An exception is thrown, if the key turns out to be non-unique in the + * result set. Use {@link #fetchGroups(int, int)} instead, if your keys are + * non-unique + * + * @param keyFieldIndex The key field. Client code must assure that this + * field is unique in the result set. + * @param valueFieldIndex The value field + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + * @see Result#intoMap(int, int) + */ + Map fetchMap(int keyFieldIndex, int valueFieldIndex) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and another one of the result's columns as value + *

+ * An exception is thrown, if the key turns out to be non-unique in the + * result set. Use {@link #fetchGroups(String, String)} instead, if your keys + * are non-unique + * + * @param keyFieldName The key field. Client code must assure that this + * field is unique in the result set. + * @param valueFieldName The value field + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key field returned two or more + * equal values from the result set. + * @see Result#intoMap(String, String) + */ + Map fetchMap(String keyFieldName, String valueFieldName) throws DataAccessException; + /** * Execute the query and return a {@link Map} with keys as a map key and the * corresponding record as value. @@ -823,6 +905,42 @@ public interface ResultQuery extends Query, Iterable { */ Map fetchMap(Field[] keys) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with keys as a map key and the + * corresponding record as value. + *

+ * An exception is thrown, if the keys turn out to be non-unique in the + * result set. Use {@link #fetchGroups(int[])} instead, if your keys are + * non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(int[]) + */ + Map fetchMap(int[] keyFieldIndexes) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with keys as a map key and the + * corresponding record as value. + *

+ * An exception is thrown, if the keys turn out to be non-unique in the + * result set. Use {@link #fetchGroups(String[])} instead, if your keys are + * non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key list is non-unique in the + * result set. + * @see Result#intoMap(String[]) + */ + Map fetchMap(String[] keyFieldNames) throws DataAccessException; + /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped into the given entity type. @@ -846,6 +964,54 @@ public interface ResultQuery extends Query, Iterable { */ Map, E> fetchMap(Field[] keys, Class type) throws DataAccessException, MappingException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(int[], Class)} instead, if + * your keys are non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoMap(int[], Class) + * @see DefaultRecordMapper + */ + Map, E> fetchMap(int[] keyFieldIndexes, Class type) throws DataAccessException, + MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped into the given entity type. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(String[], Class)} instead, if + * your keys are non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoMap(String[], Class) + * @see DefaultRecordMapper + */ + Map, E> fetchMap(String[] keyFieldNames, Class type) throws DataAccessException, + MappingException; + /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped by the given mapper. @@ -870,6 +1036,54 @@ public interface ResultQuery extends Query, Iterable { Map, E> fetchMap(Field[] keys, RecordMapper mapper) throws DataAccessException, MappingException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped by the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(int[], RecordMapper)} instead, + * if your keys are non-unique. + * + * @param keyFieldIndexes The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoMap(int[], Class) + * @see DefaultRecordMapper + */ + Map, E> fetchMap(int[] keyFieldIndexes, RecordMapper mapper) throws DataAccessException, + MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped by the given mapper. + *

+ * An {@link InvalidResultException} is thrown, if the keys are non-unique + * in the result set. Use {@link #fetchGroups(String[], RecordMapper)} + * instead, if your keys are non-unique. + * + * @param keyFieldNames The keys. Client code must assure that keys are + * unique in the result set. If this is null or an + * empty array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing the results. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the keys are non-unique in the result + * set. + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoMap(String[], Class) + * @see DefaultRecordMapper + */ + Map, E> fetchMap(String[] keyFieldNames, RecordMapper mapper) throws DataAccessException, + MappingException; + /** * Execute the query and return a {@link Map} with table as a map key and the * corresponding record as value. @@ -953,6 +1167,44 @@ public interface ResultQuery extends Query, Iterable { */ Map fetchMap(Field key, Class type) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key and mapped into the given entity type. + *

+ * An exception is thrown, if the key turn out to be non-unique in the + * result set. Use {@link #fetchGroups(int, Class)} instead, if your key + * is non-unique. + * + * @param keyFieldIndex The key. Client code must assure that key is unique + * in the result set. + * @param type The entity type. + * @return A Map containing the result. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @see Result#intoMap(int, Class) + */ + Map fetchMap(int keyFieldIndex, Class type) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key and mapped into the given entity type. + *

+ * An exception is thrown, if the key turn out to be non-unique in the + * result set. Use {@link #fetchGroups(String, Class)} instead, if your key + * is non-unique. + * + * @param keyFieldName The key. Client code must assure that key is unique + * in the result set. + * @param type The entity type. + * @return A Map containing the result. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @see Result#intoMap(String, Class) + */ + Map fetchMap(String keyFieldName, Class type) throws DataAccessException; + /** * Execute the query and return a {@link Map} with results grouped by the * given key and mapped by the given mapper. @@ -972,6 +1224,44 @@ public interface ResultQuery extends Query, Iterable { */ Map fetchMap(Field key, RecordMapper mapper) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key and mapped by the given mapper. + *

+ * An exception is thrown, if the key turn out to be non-unique in the + * result set. Use {@link #fetchGroups(int, Class)} instead, if your key is + * non-unique. + * + * @param keyFieldIndex The key. Client code must assure that key is unique + * in the result set. + * @param mapper The mapper callback. + * @return A Map containing the result. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @see Result#intoMap(int, Class) + */ + Map fetchMap(int keyFieldIndex, RecordMapper mapper) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given key and mapped by the given mapper. + *

+ * An exception is thrown, if the key turn out to be non-unique in the + * result set. Use {@link #fetchGroups(String, Class)} instead, if your key + * is non-unique. + * + * @param keyFieldName The key. Client code must assure that key is unique + * in the result set. + * @param mapper The mapper callback. + * @return A Map containing the result. + * @throws DataAccessException if something went wrong executing the query + * @throws InvalidResultException if the key is non-unique in the result + * set. + * @see Result#intoMap(String, Class) + */ + Map fetchMap(String keyFieldName, RecordMapper mapper) throws DataAccessException; + /** * Execute the query and return a {@link Map} with one of the result's * columns as key and a list of corresponding records as value. @@ -991,6 +1281,42 @@ public interface ResultQuery extends Query, Iterable { */ Map> fetchGroups(Field key) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and a list of corresponding records as value. + *

+ * Unlike {@link #fetchMap(int)}, this method allows for non-unique keys in + * the result set. + *

+ * The resulting records are attached to the original {@link Configuration} + * by default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param keyFieldIndex The key field index. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(int) + */ + Map> fetchGroups(int keyFieldIndex) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and a list of corresponding records as value. + *

+ * Unlike {@link #fetchMap(String)}, this method allows for non-unique keys + * in the result set. + *

+ * The resulting records are attached to the original {@link Configuration} + * by default. Use {@link Settings#isAttachRecords()} to override this + * behaviour. + * + * @param keyFieldName The key field name. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(String) + */ + Map> fetchGroups(String keyFieldName) throws DataAccessException; + /** * Execute the query and return a {@link Map} with one of the result's * columns as key and another one of the result's columns as value @@ -1008,6 +1334,36 @@ public interface ResultQuery extends Query, Iterable { */ Map> fetchGroups(Field key, Field value) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and another one of the result's columns as value + *

+ * Unlike {@link #fetchMap(int, int)}, this method allows for non-unique + * keys in the result set. + * + * @param keyFieldIndex The key field index. + * @param valueFieldIndex The value field index. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(int, int) + */ + Map> fetchGroups(int keyFieldIndex, int valueFieldIndex) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with one of the result's + * columns as key and another one of the result's columns as value + *

+ * Unlike {@link #fetchMap(String, String)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldName The key field name. + * @param valueFieldName The value field name. + * @return A Map containing the results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(String, String) + */ + Map> fetchGroups(String keyFieldName, String valueFieldName) throws DataAccessException; + /** * Execute the query and return a {@link Map} with the result grouped by the * given keys. @@ -1024,6 +1380,38 @@ public interface ResultQuery extends Query, Iterable { */ Map> fetchGroups(Field[] keys) throws DataAccessException; + /** + * Execute the query and return a {@link Map} with the result grouped by the + * given keys. + *

+ * Unlike {@link #fetchMap(int[])}, this method allows for non-unique keys + * in the result set. + * + * @param keyFieldIndexes The keys used for result grouping. If this is + * null or an empty array, the resulting map will + * contain at most one entry. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(int[]) + */ + Map> fetchGroups(int[] keyFieldIndexes) throws DataAccessException; + + /** + * Execute the query and return a {@link Map} with the result grouped by the + * given keys. + *

+ * Unlike {@link #fetchMap(String[])}, this method allows for non-unique + * keys in the result set. + * + * @param keyFieldNames The keys used for result grouping. If this is + * null or an empty array, the resulting map will + * contain at most one entry. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @see Result#intoGroups(String[]) + */ + Map> fetchGroups(String[] keyFieldNames) throws DataAccessException; + /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped into the given entity type. @@ -1043,6 +1431,44 @@ public interface ResultQuery extends Query, Iterable { */ Map> fetchGroups(Field[] keys, Class type) throws MappingException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped into the given entity type. + *

+ * Unlike {@link #fetchMap(int[], Class)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldIndexes The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(int[], Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(int[] keyFieldIndexes, Class type) throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped into the given entity type. + *

+ * Unlike {@link #fetchMap(String[], Class)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldNames The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param type The entity type. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(String[], Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(String[] keyFieldNames, Class type) throws MappingException; + /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped by the given mapper. @@ -1062,6 +1488,46 @@ public interface ResultQuery extends Query, Iterable { */ Map> fetchGroups(Field[] keys, RecordMapper mapper) throws MappingException; + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped by the given mapper. + *

+ * Unlike {@link #fetchMap(int[], RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldIndexes The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(int[], Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(int[] keyFieldIndexes, RecordMapper mapper) + throws MappingException; + + /** + * Execute the query and return a {@link Map} with results grouped by the + * given keys and mapped by the given mapper. + *

+ * Unlike {@link #fetchMap(String[], RecordMapper)}, this method allows for + * non-unique keys in the result set. + * + * @param keyFieldNames The keys. If this is null or an empty + * array, the resulting map will contain at most one entry. + * @param mapper The mapper callback. + * @return A Map containing grouped results + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(String[], Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(String[] keyFieldNames, RecordMapper mapper) + throws MappingException; + /** * Execute the query and return a {@link Map} with the result grouped by the * given table. @@ -1131,6 +1597,36 @@ public interface ResultQuery extends Query, Iterable { Map> fetchGroups(Field key, Class type) throws DataAccessException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + * + * @param keyFieldIndex The key field index. + * @param type The entity type. + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(int, Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(int keyFieldIndex, Class type) throws DataAccessException, + MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped + * into the given entity type. + * + * @param keyFieldName The key field name. + * @param type The entity type. + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(String, Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(String keyFieldName, Class type) throws DataAccessException, + MappingException; + /** * Return a {@link Map} with results grouped by the given key and mapped by * the given mapper. @@ -1148,6 +1644,36 @@ public interface ResultQuery extends Query, Iterable { Map> fetchGroups(Field key, RecordMapper mapper) throws DataAccessException, MappingException; + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + * + * @param keyFieldIndex The key field index. + * @param mapper The mapper callback. + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(int, Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(int keyFieldIndex, RecordMapper mapper) throws DataAccessException, + MappingException; + + /** + * Return a {@link Map} with results grouped by the given key and mapped by + * the given mapper. + * + * @param keyFieldName The key field name. + * @param mapper The mapper callback. + * @throws DataAccessException if something went wrong executing the query + * @throws MappingException wrapping any reflection or data type conversion + * exception that might have occurred while mapping records + * @see Result#intoGroups(String, Class) + * @see DefaultRecordMapper + */ + Map> fetchGroups(String keyFieldName, RecordMapper mapper) throws DataAccessException, + MappingException; + /** * Execute the query and return the generated result as an Object matrix. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java index 81cda7961b..c698a2b105 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractResultQuery.java @@ -75,8 +75,6 @@ import org.jooq.RecordMapper; import org.jooq.Result; import org.jooq.ResultQuery; import org.jooq.Table; -import org.jooq.exception.DataAccessException; -import org.jooq.exception.DataTypeException; import org.jooq.tools.Convert; import org.jooq.tools.JooqLogger; @@ -118,13 +116,13 @@ abstract class AbstractResultQuery extends AbstractQuery imple @SuppressWarnings("unchecked") @Override - public final ResultQuery bind(String param, Object value) throws IllegalArgumentException, DataTypeException { + public final ResultQuery bind(String param, Object value) { return (ResultQuery) super.bind(param, value); } @SuppressWarnings("unchecked") @Override - public final ResultQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException { + public final ResultQuery bind(int index, Object value) { return (ResultQuery) super.bind(index, value); } @@ -561,26 +559,106 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoMap(key); } + @Override + public final Map fetchMap(int keyFieldIndex) { + return fetch().intoMap(keyFieldIndex); + } + + @Override + public final Map fetchMap(String keyFieldName) { + return fetch().intoMap(keyFieldName); + } + @Override public final Map fetchMap(Field key, Field value) { return fetch().intoMap(key, value); } + @Override + public final Map fetchMap(int keyFieldIndex, int valueFieldIndex) { + return fetch().intoMap(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map fetchMap(String keyFieldName, String valueFieldName) { + return fetch().intoMap(keyFieldName, valueFieldName); + } + + @Override + public final Map fetchMap(Field key, Class type) { + return fetch().intoMap(key, type); + } + + @Override + public final Map fetchMap(int keyFieldIndex, Class type) { + return fetch().intoMap(keyFieldIndex, type); + } + + @Override + public final Map fetchMap(String keyFieldName, Class type) { + return fetch().intoMap(keyFieldName, type); + } + + @Override + public final Map fetchMap(Field key, RecordMapper mapper) { + return fetch().intoMap(key, mapper); + } + + @Override + public final Map fetchMap(int keyFieldIndex, RecordMapper mapper) { + return fetch().intoMap(keyFieldIndex, mapper); + } + + @Override + public final Map fetchMap(String keyFieldName, RecordMapper mapper) { + return fetch().intoMap(keyFieldName, mapper); + } + @Override public final Map fetchMap(Field[] keys) { return fetch().intoMap(keys); } + @Override + public final Map fetchMap(int[] keyFieldIndexes) { + return fetch().intoMap(keyFieldIndexes); + } + + @Override + public final Map fetchMap(String[] keyFieldNames) { + return fetch().intoMap(keyFieldNames); + } + @Override public final Map, E> fetchMap(Field[] keys, Class type) { return fetch().intoMap(keys, type); } + @Override + public final Map, E> fetchMap(int[] keyFieldIndexes, Class type) { + return fetch().intoMap(keyFieldIndexes, type); + } + + @Override + public final Map, E> fetchMap(String[] keyFieldNames, Class type) { + return fetch().intoMap(keyFieldNames, type); + } + @Override public final Map, E> fetchMap(Field[] keys, RecordMapper mapper) { return fetch().intoMap(keys, mapper); } + @Override + public final Map, E> fetchMap(int[] keyFieldIndexes, RecordMapper mapper) { + return fetch().intoMap(keyFieldIndexes, mapper); + } + + @Override + public final Map, E> fetchMap(String[] keyFieldNames, RecordMapper mapper) { + return fetch().intoMap(keyFieldNames, mapper); + } + @Override public final Map fetchMap(Table table) { return fetch().intoMap(table); @@ -596,16 +674,6 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoMap(table, mapper); } - @Override - public final Map fetchMap(Field key, Class type) { - return fetch().intoMap(key, type); - } - - @Override - public final Map fetchMap(Field key, RecordMapper mapper) { - return fetch().intoMap(key, mapper); - } - @Override public final List> fetchMaps() { return fetch().intoMaps(); @@ -616,21 +684,101 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoGroups(key); } + @Override + public final Map> fetchGroups(int keyFieldIndex) { + return fetch().intoGroups(keyFieldIndex); + } + + @Override + public final Map> fetchGroups(String keyFieldName) { + return fetch().intoGroups(keyFieldName); + } + @Override public final Map> fetchGroups(Field key, Field value) { return fetch().intoGroups(key, value); } + @Override + public final Map> fetchGroups(int keyFieldIndex, int valueFieldIndex) { + return fetch().intoGroups(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map> fetchGroups(String keyFieldName, String valueFieldName) { + return fetch().intoGroups(keyFieldName, valueFieldName); + } + + @Override + public final Map> fetchGroups(Field key, Class type) { + return fetch().intoGroups(key, type); + } + + @Override + public final Map> fetchGroups(int keyFieldIndex, Class type) { + return fetch().intoGroups(keyFieldIndex, type); + } + + @Override + public final Map> fetchGroups(String keyFieldName, Class type) { + return fetch().intoGroups(keyFieldName, type); + } + + @Override + public final Map> fetchGroups(Field key, RecordMapper mapper) { + return fetch().intoGroups(key, mapper); + } + + @Override + public final Map> fetchGroups(int keyFieldIndex, RecordMapper mapper) { + return fetch().intoGroups(keyFieldIndex, mapper); + } + + @Override + public final Map> fetchGroups(String keyFieldName, RecordMapper mapper) { + return fetch().intoGroups(keyFieldName, mapper); + } + @Override public final Map> fetchGroups(Field[] keys) { return fetch().intoGroups(keys); } + @Override + public final Map> fetchGroups(int[] keyFieldIndexes) { + return fetch().intoGroups(keyFieldIndexes); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames) { + return fetch().intoGroups(keyFieldNames); + } + @Override public final Map> fetchGroups(Field[] keys, Class type) { return fetch().intoGroups(keys, type); } + @Override + public final Map> fetchGroups(int[] keyFieldIndexes, Class type) { + return fetch().intoGroups(keyFieldIndexes, type); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames, Class type) { + return fetch().intoGroups(keyFieldNames, type); + } + + @Override + public final Map> fetchGroups(int[] keyFieldIndexes, RecordMapper mapper) { + return fetch().intoGroups(keyFieldIndexes, mapper); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames, RecordMapper mapper) { + return fetch().intoGroups(keyFieldNames, mapper); + } + @Override public final Map> fetchGroups(Field[] keys, RecordMapper mapper) { return fetch().intoGroups(keys, mapper); @@ -651,16 +799,6 @@ abstract class AbstractResultQuery extends AbstractQuery imple return fetch().intoGroups(table, mapper); } - @Override - public final Map> fetchGroups(Field key, Class type) { - return fetch().intoGroups(key, type); - } - - @Override - public final Map> fetchGroups(Field key, RecordMapper mapper) { - return fetch().intoGroups(key, mapper); - } - @Override public final Object[][] fetchArrays() { return fetch().intoArrays(); @@ -668,7 +806,7 @@ abstract class AbstractResultQuery extends AbstractQuery imple @SuppressWarnings("unchecked") @Override - public final R[] fetchArray() throws DataAccessException { + public final R[] fetchArray() { Result r = fetch(); return r.toArray((R[]) Array.newInstance(getRecordType(), r.size())); } diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index 240f972923..f5965d9257 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -216,6 +216,36 @@ class ResultImpl implements Result, AttachableInternal { return fields.fields().clone(); } + // @Override [#4113] TODO: Make this public + final Field[] fields(Field... f) { + Field[] result = new Field[f.length]; + + for (int i = 0; i < f.length; i++) + result[i] = field(f[i]); + + return result; + } + + // @Override [#4113] TODO: Make this public + final Field[] fields(int... indexes) { + Field[] result = new Field[indexes.length]; + + for (int i = 0; i < indexes.length; i++) + result[i] = field(indexes[i]); + + return result; + } + + // @Override [#4113] TODO: Make this public + final Field[] fields(String... names) { + Field[] result = new Field[names.length]; + + for (int i = 0; i < names.length; i++) + result[i] = field(names[i]); + + return result; + } + @Override public final boolean isEmpty() { return records.isEmpty(); @@ -978,19 +1008,29 @@ class ResultImpl implements Result, AttachableInternal { } return list; - } @Override public final Map intoMap(Field key) { - int index = indexOrFail(fieldsRow(), key); + return intoMap0(indexOrFail(fieldsRow(), key)); + } + + @Override + public final Map intoMap(int keyFieldIndex) { + return intoMap0(keyFieldIndex); + } + + @Override + public final Map intoMap(String keyFieldName) { + return intoMap(field(keyFieldName)); + } + + private final Map intoMap0(int keyFieldIndex) { Map map = new LinkedHashMap(); - for (R record : this) { - if (map.put((K) record.getValue(index), record) != null) { - throw new InvalidResultException("Key " + key + " is not unique in Result for " + this); - } - } + for (R record : this) + if (map.put((K) record.getValue(keyFieldIndex), record) != null) + throw new InvalidResultException("Key " + keyFieldIndex + " is not unique in Result for " + this); return map; } @@ -1000,17 +1040,39 @@ class ResultImpl implements Result, AttachableInternal { int kIndex = indexOrFail(fieldsRow(), key); int vIndex = indexOrFail(fieldsRow(), value); + return intoMap0(kIndex, vIndex); + } + + @Override + public final Map intoMap(int keyFieldIndex, int valueFieldIndex) { + return intoMap0(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map intoMap(String keyFieldName, String valueFieldName) { + return intoMap(field(keyFieldName), field(valueFieldName)); + } + + private final Map intoMap0(int kIndex, int vIndex) { Map map = new LinkedHashMap(); - for (R record : this) { - if (map.put((K) record.getValue(kIndex), (V) record.getValue(vIndex)) != null) { - throw new InvalidResultException("Key " + key + " is not unique in Result for " + this); - } - } + for (R record : this) + if (map.put((K) record.getValue(kIndex), (V) record.getValue(vIndex)) != null) + throw new InvalidResultException("Key " + kIndex + " is not unique in Result for " + this); return map; } + @Override + public final Map intoMap(int[] keyFieldIndexes) { + return intoMap(fields(keyFieldIndexes)); + } + + @Override + public final Map intoMap(String[] keyFieldNames) { + return intoMap(fields(keyFieldNames)); + } + @Override public final Map intoMap(Field[] keys) { if (keys == null) { @@ -1033,11 +1095,31 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map, E> intoMap(int[] keyFieldIndexes, Class type) { + return intoMap(fields(keyFieldIndexes), type); + } + + @Override + public final Map, E> intoMap(String[] keyFieldNames, Class type) { + return intoMap(fields(keyFieldNames), type); + } + @Override public final Map, E> intoMap(Field[] keys, Class type) { return intoMap(keys, Utils.configuration(this).recordMapperProvider().provide(fields, type)); } + @Override + public final Map, E> intoMap(int[] keyFieldIndexes, RecordMapper mapper) { + return intoMap(fields(keyFieldIndexes), mapper); + } + + @Override + public final Map, E> intoMap(String[] keyFieldNames, RecordMapper mapper) { + return intoMap(fields(keyFieldNames), mapper); + } + @Override public final Map, E> intoMap(Field[] keys, RecordMapper mapper) { if (keys == null) { @@ -1095,32 +1177,66 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map intoMap(int keyFieldIndex, Class type) { + return intoMap(keyFieldIndex, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + + @Override + public final Map intoMap(String keyFieldName, Class type) { + return intoMap(keyFieldName, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + @Override public final Map intoMap(Field key, Class type) { return intoMap(key, Utils.configuration(this).recordMapperProvider().provide(fields, type)); } + @Override + public final Map intoMap(int keyFieldIndex, RecordMapper mapper) { + return intoMap0(keyFieldIndex, mapper); + } + + @Override + public final Map intoMap(String keyFieldName, RecordMapper mapper) { + return intoMap(field(keyFieldName), mapper); + } + @Override public final Map intoMap(Field key, RecordMapper mapper) { - int index = indexOrFail(fieldsRow(), key); + return intoMap0(indexOrFail(fieldsRow(), key), mapper); + } + + private final Map intoMap0(int keyFieldIndex, RecordMapper mapper) { Map map = new LinkedHashMap(); - for (R record : this) { - if (map.put((K) record.getValue(index), mapper.map(record)) != null) { - throw new InvalidResultException("Key " + key + " is not unique in Result for " + this); - } - } + for (R record : this) + if (map.put((K) record.getValue(keyFieldIndex), mapper.map(record)) != null) + throw new InvalidResultException("Key " + keyFieldIndex + " is not unique in Result for " + this); return map; } @Override public final Map> intoGroups(Field key) { - int index = indexOrFail(fieldsRow(), key); + return intoGroups0(indexOrFail(fieldsRow(), key)); + } + + @Override + public final Map> intoGroups(int keyFieldIndex) { + return intoGroups0(keyFieldIndex); + } + + @Override + public final Map> intoGroups(String keyFieldName) { + return intoGroups(field(keyFieldName)); + } + + private final Map> intoGroups0(int keyFieldIndex) { Map> map = new LinkedHashMap>(); for (R record : this) { - K val = (K) record.getValue(index); + K val = (K) record.getValue(keyFieldIndex); Result result = map.get(val); if (result == null) { @@ -1139,6 +1255,20 @@ class ResultImpl implements Result, AttachableInternal { int kIndex = indexOrFail(fieldsRow(), key); int vIndex = indexOrFail(fieldsRow(), value); + return intoGroups0(kIndex, vIndex); + } + + @Override + public final Map> intoGroups(int keyFieldIndex, int valueFieldIndex) { + return (Map) intoGroups0(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map> intoGroups(String keyFieldName, String valueFieldName) { + return (Map) intoGroups(field(keyFieldName), field(valueFieldName)); + } + + private final Map> intoGroups0(int kIndex, int vIndex) { Map> map = new LinkedHashMap>(); for (R record : this) { @@ -1157,6 +1287,16 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map> intoGroups(int keyFieldIndex, Class type) { + return intoGroups(keyFieldIndex, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + + @Override + public final Map> intoGroups(String keyFieldName, Class type) { + return intoGroups(keyFieldName, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + @Override public final Map> intoGroups(Field key, Class type) { return intoGroups(key, Utils.configuration(this).recordMapperProvider().provide(fields, type)); @@ -1164,11 +1304,24 @@ class ResultImpl implements Result, AttachableInternal { @Override public final Map> intoGroups(Field key, RecordMapper mapper) { - int index = indexOrFail(fieldsRow(), key); + return intoGroups0(indexOrFail(fieldsRow(), key), mapper); + } + + @Override + public final Map> intoGroups(int keyFieldIndex, RecordMapper mapper) { + return intoGroups0(keyFieldIndex, mapper); + } + + @Override + public final Map> intoGroups(String keyFieldName, RecordMapper mapper) { + return intoGroups(field(keyFieldName), mapper); + } + + private final Map> intoGroups0(int keyFieldIndex, RecordMapper mapper) { Map> map = new LinkedHashMap>(); for (R record : this) { - K keyVal = (K) record.getValue(index); + K keyVal = (K) record.getValue(keyFieldIndex); List list = map.get(keyVal); if (list == null) { @@ -1182,6 +1335,16 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public final Map> intoGroups(int[] keyFieldIndexes) { + return intoGroups(fields(keyFieldIndexes)); + } + + @Override + public final Map> intoGroups(String[] keyFieldNames) { + return intoGroups(fields(keyFieldNames)); + } + @Override public final Map> intoGroups(Field[] keys) { if (keys == null) { @@ -1208,11 +1371,31 @@ class ResultImpl implements Result, AttachableInternal { return map; } + @Override + public Map> intoGroups(int[] keyFieldIndexes, Class type) { + return intoGroups(keyFieldIndexes, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + + @Override + public Map> intoGroups(String[] keyFieldNames, Class type) { + return intoGroups(keyFieldNames, Utils.configuration(this).recordMapperProvider().provide(fields, type)); + } + @Override public final Map> intoGroups(Field[] keys, Class type) { return intoGroups(keys, Utils.configuration(this).recordMapperProvider().provide(fields, type)); } + @Override + public final Map> intoGroups(int[] keyFieldIndexes, RecordMapper mapper) { + return intoGroups(fields(keyFieldIndexes), mapper); + } + + @Override + public final Map> intoGroups(String[] keyFieldNames, RecordMapper mapper) { + return intoGroups(fields(keyFieldNames), mapper); + } + @Override public final Map> intoGroups(Field[] keys, RecordMapper mapper) { if (keys == null) { diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java index 3476280476..d1db731100 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java @@ -117,7 +117,6 @@ import org.jooq.Table; import org.jooq.TableField; import org.jooq.TableLike; import org.jooq.WindowDefinition; -import org.jooq.exception.DataAccessException; /** * A wrapper for a {@link SelectQuery} @@ -1965,7 +1964,7 @@ class SelectImpl... keyFields) throws DataAccessException { + public final SelectImpl onKey(TableField... keyFields) { conditionStep = ConditionStep.ON; getQuery().addJoinOnKey(joinTable, joinType, keyFields); joinTable = null; @@ -2537,26 +2536,106 @@ class SelectImpl fetchMap(int keyFieldIndex) { + return getDelegate().fetchMap(keyFieldIndex); + } + + @Override + public final Map fetchMap(String keyFieldName) { + return getDelegate().fetchMap(keyFieldName); + } + @Override public final Map fetchMap(Field key, Field value) { return getDelegate().fetchMap(key, value); } + @Override + public final Map fetchMap(int keyFieldIndex, int valueFieldIndex) { + return getDelegate().fetchMap(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map fetchMap(String keyFieldName, String valueFieldName) { + return getDelegate().fetchMap(keyFieldName, valueFieldName); + } + + @Override + public final Map fetchMap(Field key, Class type) { + return getDelegate().fetchMap(key, type); + } + + @Override + public final Map fetchMap(int keyFieldIndex, Class type) { + return getDelegate().fetchMap(keyFieldIndex, type); + } + + @Override + public final Map fetchMap(String keyFieldName, Class type) { + return getDelegate().fetchMap(keyFieldName, type); + } + + @Override + public final Map fetchMap(Field key, RecordMapper mapper) { + return getDelegate().fetchMap(key, mapper); + } + + @Override + public final Map fetchMap(int keyFieldIndex, RecordMapper mapper) { + return getDelegate().fetchMap(keyFieldIndex, mapper); + } + + @Override + public final Map fetchMap(String keyFieldName, RecordMapper mapper) { + return getDelegate().fetchMap(keyFieldName, mapper); + } + @Override public final Map fetchMap(Field[] keys) { return getDelegate().fetchMap(keys); } + @Override + public final Map fetchMap(int[] keyFieldIndexes) { + return getDelegate().fetchMap(keyFieldIndexes); + } + + @Override + public final Map fetchMap(String[] keyFieldNames) { + return getDelegate().fetchMap(keyFieldNames); + } + @Override public final Map, E> fetchMap(Field[] keys, Class type) { return getDelegate().fetchMap(keys, type); } + @Override + public final Map, E> fetchMap(int[] keyFieldIndexes, Class type) { + return getDelegate().fetchMap(keyFieldIndexes, type); + } + + @Override + public final Map, E> fetchMap(String[] keyFieldNames, Class type) { + return getDelegate().fetchMap(keyFieldNames, type); + } + @Override public final Map, E> fetchMap(Field[] keys, RecordMapper mapper) { return getDelegate().fetchMap(keys, mapper); } + @Override + public final Map, E> fetchMap(int[] keyFieldIndexes, RecordMapper mapper) { + return getDelegate().fetchMap(keyFieldIndexes, mapper); + } + + @Override + public final Map, E> fetchMap(String[] keyFieldNames, RecordMapper mapper) { + return getDelegate().fetchMap(keyFieldNames, mapper); + } + @Override public final Map fetchMap(Table table) { return getDelegate().fetchMap(table); @@ -2572,16 +2651,6 @@ class SelectImpl Map fetchMap(Field key, Class type) { - return getDelegate().fetchMap(key, type); - } - - @Override - public final Map fetchMap(Field key, RecordMapper mapper) { - return getDelegate().fetchMap(key, mapper); - } - @Override public final List> fetchMaps() { return getDelegate().fetchMaps(); @@ -2592,26 +2661,106 @@ class SelectImpl> fetchGroups(int keyFieldIndex) { + return getDelegate().fetchGroups(keyFieldIndex); + } + + @Override + public final Map> fetchGroups(String keyFieldName) { + return getDelegate().fetchGroups(keyFieldName); + } + @Override public final Map> fetchGroups(Field key, Field value) { return getDelegate().fetchGroups(key, value); } + @Override + public final Map> fetchGroups(int keyFieldIndex, int valueFieldIndex) { + return getDelegate().fetchGroups(keyFieldIndex, valueFieldIndex); + } + + @Override + public final Map> fetchGroups(String keyFieldName, String valueFieldName) { + return getDelegate().fetchGroups(keyFieldName, valueFieldName); + } + + @Override + public final Map> fetchGroups(Field key, Class type) { + return getDelegate().fetchGroups(key, type); + } + + @Override + public final Map> fetchGroups(int keyFieldIndex, Class type) { + return getDelegate().fetchGroups(keyFieldIndex, type); + } + + @Override + public final Map> fetchGroups(String keyFieldName, Class type) { + return getDelegate().fetchGroups(keyFieldName, type); + } + + @Override + public final Map> fetchGroups(Field key, RecordMapper mapper) { + return getDelegate().fetchGroups(key, mapper); + } + + @Override + public final Map> fetchGroups(int keyFieldIndex, RecordMapper mapper) { + return getDelegate().fetchGroups(keyFieldIndex, mapper); + } + + @Override + public final Map> fetchGroups(String keyFieldName, RecordMapper mapper) { + return getDelegate().fetchGroups(keyFieldName, mapper); + } + @Override public final Map> fetchGroups(Field[] keys) { return getDelegate().fetchGroups(keys); } + @Override + public final Map> fetchGroups(int[] keyFieldIndexes) { + return getDelegate().fetchGroups(keyFieldIndexes); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames) { + return getDelegate().fetchGroups(keyFieldNames); + } + @Override public final Map> fetchGroups(Field[] keys, Class type) { return getDelegate().fetchGroups(keys, type); } + @Override + public final Map> fetchGroups(int[] keyFieldIndexes, Class type) { + return getDelegate().fetchGroups(keyFieldIndexes, type); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames, Class type) { + return getDelegate().fetchGroups(keyFieldNames, type); + } + @Override public final Map> fetchGroups(Field[] keys, RecordMapper mapper) { return getDelegate().fetchGroups(keys, mapper); } + @Override + public final Map> fetchGroups(int[] keyFieldIndexes, RecordMapper mapper) { + return getDelegate().fetchGroups(keyFieldIndexes, mapper); + } + + @Override + public final Map> fetchGroups(String[] keyFieldNames, RecordMapper mapper) { + return getDelegate().fetchGroups(keyFieldNames, mapper); + } + @Override public final Map> fetchGroups(Table table) { return getDelegate().fetchGroups(table); @@ -2627,16 +2776,6 @@ class SelectImpl Map> fetchGroups(Field key, Class type) { - return getDelegate().fetchGroups(key, type); - } - - @Override - public final Map> fetchGroups(Field key, RecordMapper mapper) { - return getDelegate().fetchGroups(key, mapper); - } - @Override public final Object[][] fetchArrays() { return getDelegate().fetchArrays();