Actually, if we use Key we don't need to specify the type. It's already in the

keys. So we can have loadAll(Class,Collection<Comparable>) and
loadAll(Collection<Key>) and not run into type erasure problems. Yay!
This commit is contained in:
Michael Bayne
2008-09-06 02:06:44 +00:00
parent 9a21071c82
commit 2f335c4dc8
2 changed files with 9 additions and 11 deletions
@@ -28,6 +28,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -144,11 +145,9 @@ public abstract class DepotRepository
} }
/** /**
* Converts the supplied set of raw keys into {@link Key} records so they can easily be passed * Loads up all persistent records that match the supplied set of raw primary keys.
* to {@link #loadAll}. We'd just accept a collection of raw keys, but that would have the same
* type erasure as the loadAll version that accepts a collection of keys. Alas.
*/ */
protected <T extends PersistentRecord> List<Key<T>> makeKeys ( protected <T extends PersistentRecord> List<T> loadAll (
Class<T> type, Collection<? extends Comparable<?>> primaryKeys) Class<T> type, Collection<? extends Comparable<?>> primaryKeys)
throws DatabaseException throws DatabaseException
{ {
@@ -158,18 +157,17 @@ public abstract class DepotRepository
for (Comparable<?> key : primaryKeys) { for (Comparable<?> key : primaryKeys) {
keys.add(marsh.makePrimaryKey(key)); keys.add(marsh.makePrimaryKey(key));
} }
return keys; return loadAll(keys);
} }
/** /**
* Loads up all persistent records that match the supplied set of primary keys. * Loads up all persistent records that match the supplied set of primary keys.
*/ */
protected <T extends PersistentRecord> List<T> loadAll (Class<T> type, Collection<Key<T>> keys) protected <T extends PersistentRecord> List<T> loadAll (Collection<Key<T>> keys)
throws DatabaseException throws DatabaseException
{ {
// if we have precisely one query clause and it's a KeySet, then we can skip the key lookup return (keys.size() == 0) ? Collections.<T>emptyList() :
// phase and go right to phase two of our two phase query process _ctx.invoke(new FindAllQuery.WithKeys<T>(_ctx, keys));
return _ctx.invoke(new FindAllQuery.WithKeys<T>(_ctx, type, keys));
} }
/** /**
@@ -120,10 +120,10 @@ public abstract class FindAllQuery<T extends PersistentRecord>
*/ */
public static class WithKeys<T extends PersistentRecord> extends FindAllQuery<T> public static class WithKeys<T extends PersistentRecord> extends FindAllQuery<T>
{ {
public WithKeys (PersistenceContext ctx, Class<T> type, Collection<Key<T>> keys) public WithKeys (PersistenceContext ctx, Collection<Key<T>> keys)
throws DatabaseException throws DatabaseException
{ {
super(ctx, type); super(ctx, keys.iterator().next().getPersistentClass());
_keys = keys; _keys = keys;
} }