Any collection of anything that extends QueryClause is generally all we need.

This commit is contained in:
Michael Bayne
2008-09-03 00:55:07 +00:00
parent beef018b03
commit 2fd131c0d2
4 changed files with 24 additions and 8 deletions
@@ -25,6 +25,7 @@ import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -122,7 +123,17 @@ public abstract class DepotRepository
} }
/** /**
* Loads the first persistent object that matches the supplied key. * Loads the first persistent object that matches the supplied query clauses.
*/
protected <T extends PersistentRecord> T load (
Class<T> type, Collection<? extends QueryClause> clauses)
throws PersistenceException
{
return load(type, clauses.toArray(new QueryClause[clauses.size()]));
}
/**
* Loads the first persistent object that matches the supplied query clauses.
*/ */
protected <T extends PersistentRecord> T load (Class<T> type, QueryClause... clauses) protected <T extends PersistentRecord> T load (Class<T> type, QueryClause... clauses)
throws PersistenceException throws PersistenceException
@@ -142,7 +153,8 @@ public abstract class DepotRepository
* complexity is an inherent drawback, and it does execute two separate database queries * complexity is an inherent drawback, and it does execute two separate database queries
* for what the simple method does in one. * for what the simple method does in one.
*/ */
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, List<QueryClause> clauses) protected <T extends PersistentRecord> List<T> findAll (
Class<T> type, Collection<? extends QueryClause> clauses)
throws PersistenceException throws PersistenceException
{ {
DepotMarshaller<T> marsh = _ctx.getMarshaller(type); DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
@@ -160,7 +172,7 @@ public abstract class DepotRepository
} }
/** /**
* A varargs version of {@link #findAll(Class<T>,List<QueryClause>)}. * A varargs version of {@link #findAll(Class<T>,Collection<QueryClause>)}.
*/ */
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, QueryClause... clauses) protected <T extends PersistentRecord> List<T> findAll (Class<T> type, QueryClause... clauses)
throws PersistenceException throws PersistenceException
@@ -55,7 +55,7 @@ public class DepotTypes
* are interrogated for their class definition sets through {@link SQLExpression#addClasses}. * are interrogated for their class definition sets through {@link SQLExpression#addClasses}.
*/ */
public static <T extends PersistentRecord> DepotTypes getDepotTypes ( public static <T extends PersistentRecord> DepotTypes getDepotTypes (
PersistenceContext ctx, Collection<QueryClause> clauses) PersistenceContext ctx, Collection<? extends QueryClause> clauses)
throws PersistenceException throws PersistenceException
{ {
Set<Class<? extends PersistentRecord>> classSet = Set<Class<? extends PersistentRecord>> classSet =
@@ -24,7 +24,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -59,7 +61,8 @@ public abstract class FindAllQuery<T extends PersistentRecord>
*/ */
public static class WithCache<T extends PersistentRecord> extends FindAllQuery<T> public static class WithCache<T extends PersistentRecord> extends FindAllQuery<T>
{ {
public WithCache (PersistenceContext ctx, Class<T> type, List<QueryClause> clauses) public WithCache (PersistenceContext ctx, Class<T> type,
Collection<? extends QueryClause> clauses)
throws PersistenceException throws PersistenceException
{ {
super(ctx, type); super(ctx, type);
@@ -192,7 +195,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
} }
} }
protected List<QueryClause> _clauses; protected Collection<? extends QueryClause> _clauses;
} }
/** /**
@@ -200,7 +203,8 @@ public abstract class FindAllQuery<T extends PersistentRecord>
*/ */
public static class Explicitly<T extends PersistentRecord> extends FindAllQuery<T> public static class Explicitly<T extends PersistentRecord> extends FindAllQuery<T>
{ {
public Explicitly (PersistenceContext ctx, Class<T> type, List<QueryClause> clauses) public Explicitly (PersistenceContext ctx, Class<T> type,
Collection<? extends QueryClause> clauses)
throws PersistenceException throws PersistenceException
{ {
super(ctx, type); super(ctx, type);
@@ -42,7 +42,7 @@ public class SelectClause<T extends PersistentRecord> extends QueryClause
* class, as dictated by the key and query clauses. A persistence context is supplied for * class, as dictated by the key and query clauses. A persistence context is supplied for
* instantiation of marshallers, which may trigger table creations and schema migrations. * instantiation of marshallers, which may trigger table creations and schema migrations.
*/ */
public SelectClause (Class<T> pClass, String[] fields, List<QueryClause> clauses) public SelectClause (Class<T> pClass, String[] fields, Collection<? extends QueryClause> clauses)
{ {
_pClass = pClass; _pClass = pClass;
_fields = fields; _fields = fields;