diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 8c4a4ab..cd91e4c 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -28,6 +28,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; 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 - * 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. + * Loads up all persistent records that match the supplied set of raw primary keys. */ - protected List> makeKeys ( + protected List loadAll ( Class type, Collection> primaryKeys) throws DatabaseException { @@ -158,18 +157,17 @@ public abstract class DepotRepository for (Comparable key : primaryKeys) { keys.add(marsh.makePrimaryKey(key)); } - return keys; + return loadAll(keys); } /** * Loads up all persistent records that match the supplied set of primary keys. */ - protected List loadAll (Class type, Collection> keys) + protected List loadAll (Collection> keys) throws DatabaseException { - // if we have precisely one query clause and it's a KeySet, then we can skip the key lookup - // phase and go right to phase two of our two phase query process - return _ctx.invoke(new FindAllQuery.WithKeys(_ctx, type, keys)); + return (keys.size() == 0) ? Collections.emptyList() : + _ctx.invoke(new FindAllQuery.WithKeys(_ctx, keys)); } /** diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index 7d2cf9d..93e17ec 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -120,10 +120,10 @@ public abstract class FindAllQuery */ public static class WithKeys extends FindAllQuery { - public WithKeys (PersistenceContext ctx, Class type, Collection> keys) + public WithKeys (PersistenceContext ctx, Collection> keys) throws DatabaseException { - super(ctx, type); + super(ctx, keys.iterator().next().getPersistentClass()); _keys = keys; }