Merge pull request #1815 from idugic/master

#1709 update
This commit is contained in:
Lukas Eder 2012-09-11 12:58:22 -07:00
commit dcdceadfb1
6 changed files with 78 additions and 45 deletions

View File

@ -143,10 +143,10 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals(BOOK_IDS, new ArrayList<Integer>(map2.keySet()));
assertEquals(BOOK_TITLES, new ArrayList<String>(map2.values()));
// Key list -> Record
// ------------------
// Keys -> Record
// --------------
Map<List<?>, B> map3 = create().selectFrom(TBook()).orderBy(TBook_ID())
.fetchMap(TBook_ID(), TBook_LANGUAGE_ID(), TBook_TITLE());
.fetchMap(new Field<?>[] { TBook_ID(), TBook_LANGUAGE_ID(), TBook_TITLE() });
assertEquals(4, map3.keySet().size());
for (List<?> keyList : map3.keySet()) {
@ -251,14 +251,39 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals(BOOK_TITLES.get(i * 2 + 1), map4Values.get(i).get(1));
}
// Key list -> Record
// ----------------------
// Keys -> Record
// --------------
// Grouping by BOOK.AUTHOR_ID, BOOK.LANGUAGE_ID
Map<List<?>, Result<B>> map5 = create().selectFrom(TBook()).orderBy(TBook_ID())
.fetchGroups(TBook_ID(), TBook_LANGUAGE_ID(), TBook_TITLE());
assertEquals(4, map5.size());
.fetchGroups(new Field<?>[] { TBook_AUTHOR_ID(), TBook_LANGUAGE_ID() });
for (List<?> keyList : map5.keySet()) {
Result<B> result = map5.get(keyList);
Iterator<Entry<List<?>, Result<B>>> iterator = map5.entrySet().iterator();
Entry<List<?>, Result<B>> entry1_en = iterator.next();
assertEquals(2, entry1_en.getValue().size());
assertEquals(entry1_en.getKey().get(0), entry1_en.getValue().get(0).getValue(TBook_AUTHOR_ID()));
assertEquals(entry1_en.getKey().get(0), entry1_en.getValue().get(1).getValue(TBook_AUTHOR_ID()));
assertEquals(entry1_en.getKey().get(1), entry1_en.getValue().get(0).getValue(TBook_LANGUAGE_ID()));
assertEquals(entry1_en.getKey().get(1), entry1_en.getValue().get(1).getValue(TBook_LANGUAGE_ID()));
Entry<List<?>, Result<B>> entry2_pt = iterator.next();
assertEquals(1, entry2_pt.getValue().size());
assertEquals(entry2_pt.getKey().get(0), entry2_pt.getValue().get(0).getValue(TBook_AUTHOR_ID()));
assertEquals(entry2_pt.getKey().get(1), entry2_pt.getValue().get(0).getValue(TBook_LANGUAGE_ID()));
Entry<List<?>, Result<B>> entry2_de = iterator.next();
assertEquals(1, entry2_de.getValue().size());
assertEquals(entry2_de.getKey().get(0), entry2_de.getValue().get(0).getValue(TBook_AUTHOR_ID()));
assertEquals(entry2_de.getKey().get(1), entry2_de.getValue().get(0).getValue(TBook_LANGUAGE_ID()));
assertFalse(iterator.hasNext());
// Grouping by BOOK.AUTHOR_ID, BOOK.LANGUAGE_ID, BOOK.TITLE
Map<List<?>, Result<B>> map6 = create().selectFrom(TBook()).orderBy(TBook_ID())
.fetchGroups(new Field<?>[] { TBook_ID(), TBook_LANGUAGE_ID(), TBook_TITLE() });
assertEquals(4, map6.size());
for (List<?> keyList : map6.keySet()) {
Result<B> result = map6.get(keyList);
assertEquals(1, result.size());
assertEquals(keyList.get(0), result.get(0).getValue(TBook_ID()));
assertEquals(keyList.get(1), result.get(0).getValue(TBook_LANGUAGE_ID()));

View File

@ -1836,20 +1836,20 @@ public interface Result<R extends Record> extends FieldProvider, List<R>, Attach
<K, V> Map<K, V> intoMap(Field<K> key, Field<V> value);
/**
* Return a {@link Map} with keys list as a map key and the corresponding
* record as value.
* Return a {@link Map} with the given keys as a map key and the
* corresponding record as value.
* <p>
* An {@link InvalidResultException} is thrown, if the key list is
* non-unique in the result set. Use {@link #intoGroups(Field...)} instead,
* if your key list is non-unique.
* An {@link InvalidResultException} is thrown, if the keys are non-unique
* in the result set. Use {@link #intoGroups(Field[])} instead, if your keys
* are non-unique.
*
* @param keys The key list. Client code must assure that this key list is
* unique in the result set.
* @param keys The keys. Client code must assure that keys are unique in the
* result set.
* @return A Map containing the results.
* @throws InvalidResultException if the key list is non-unique in the
* result set.
* @throws InvalidResultException if the keys are non-unique in the result
* set.
*/
Map<List<?>, R> intoMap(Field<?>... keys);
Map<List<?>, R> intoMap(Field<?>[] keys);
/**
* Return a {@link Map} with one of the result's columns as key and a list
@ -1881,15 +1881,15 @@ public interface Result<R extends Record> extends FieldProvider, List<R>, Attach
/**
* Execute the query and return a {@link Map} with the result grouped by the
* given key list.
* given keys.
* <p>
* Unlike {@link #intoMap(Field...)}, this method allows for non-unique key
* list in the result set.
* Unlike {@link #intoMap(Field[])}, this method allows for non-unique keys
* in the result set.
*
* @param keys The key list.
* @param keys The keys.
* @return A Map containing grouped results
*/
Map<List<?>, Result<R>> intoGroups(Field<?>... keys);
Map<List<?>, Result<R>> intoGroups(Field<?>[] keys);
/**
* Return a {@link Map} with results grouped by the given key and mapped

View File

@ -502,22 +502,22 @@ public interface ResultQuery<R extends Record> extends Query {
<K, V> Map<K, V> fetchMap(Field<K> key, Field<V> value) throws DataAccessException;
/**
* Execute the query and return a {@link Map} with keys list as a map key
* and the corresponding record as value.
* Execute the query and return a {@link Map} with keys as a map key and the
* corresponding record as value.
* <p>
* An exception is thrown, if the key list turns out to be non-unique in the
* result set. Use {@link #fetchGroups(Field...)} instead, if your key list
* is non-unique.
* An exception is thrown, if the keys turn out to be non-unique in the
* result set. Use {@link #fetchGroups(Field[])} instead, if your keys are
* non-unique.
*
* @param keys The key list. Client code must assure that this key list is
* unique in the result set.
* @param keys 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(Field...)
* @see Result#intoMap(Field[])
*/
Map<List<?>, R> fetchMap(Field<?>... keys) throws DataAccessException;
Map<List<?>, R> fetchMap(Field<?>[] keys) throws DataAccessException;
/**
* Execute the query and return a {@link Map} with one of the result's
@ -557,17 +557,17 @@ public interface ResultQuery<R extends Record> extends Query {
/**
* Execute the query and return a {@link Map} with the result grouped by the
* given key list.
* given keys.
* <p>
* Unlike {@link #fetchMap(Field...)}, this method allows for non-unique key
* list in the result set.
* Unlike {@link #fetchMap(Field[])}, this method allows for non-unique keys
* in the result set.
*
* @param keys The key list used for result grouping.
* @param keys The keys used for result grouping.
* @return A Map containing grouped results
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoGroups(Field...)
* @see Result#intoGroups(Field[])
*/
Map<List<?>, Result<R>> fetchGroups(Field<?>... keys) throws DataAccessException;
Map<List<?>, Result<R>> fetchGroups(Field<?>[] keys) throws DataAccessException;
/**
* Return a {@link Map} with results grouped by the given key and mapped

View File

@ -234,7 +234,7 @@ abstract class AbstractDelegatingSelect<R extends Record>
}
@Override
public final Map<List<?>, R> fetchMap(Field<?>... keys) {
public final Map<List<?>, R> fetchMap(Field<?>[] keys) {
return getDelegate().fetchMap(keys);
}
@ -259,7 +259,7 @@ abstract class AbstractDelegatingSelect<R extends Record>
}
@Override
public final Map<List<?>, Result<R>> fetchGroups(Field<?>... keys) {
public final Map<List<?>, Result<R>> fetchGroups(Field<?>[] keys) {
return getDelegate().fetchGroups(keys);
}

View File

@ -417,7 +417,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final Map<List<?>, R> fetchMap(Field<?>... keys) {
public final Map<List<?>, R> fetchMap(Field<?>[] keys) {
return fetch().intoMap(keys);
}
@ -442,7 +442,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
}
@Override
public final Map<List<?>, Result<R>> fetchGroups(Field<?>... keys) {
public final Map<List<?>, Result<R>> fetchGroups(Field<?>[] keys) {
return fetch().intoGroups(keys);
}

View File

@ -1400,7 +1400,11 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
}
@Override
public final Map<List<?>, R> intoMap(Field<?>... keys) {
public final Map<List<?>, R> intoMap(Field<?>[] keys) {
if (keys == null || keys.length == 0) {
throw new IllegalArgumentException("Keys must not be null or empty.");
}
Map<List<?>, R> map = new LinkedHashMap<List<?>, R>();
for (R record : this) {
@ -1457,7 +1461,11 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
}
@Override
public final Map<List<?>, Result<R>> intoGroups(Field<?>... keys) {
public final Map<List<?>, Result<R>> intoGroups(Field<?>[] keys) {
if (keys == null || keys.length == 0) {
throw new IllegalArgumentException("Keys must not be null or empty.");
}
Map<List<?>, Result<R>> map = new LinkedHashMap<List<?>, Result<R>>();
for (R record : this) {