Support taking a List as well as a varargs array. There are no doubt other

places where this could be done.
This commit is contained in:
Michael Bayne
2007-11-26 21:50:54 +00:00
parent d17db31213
commit 951b201064
4 changed files with 36 additions and 6 deletions
@@ -24,6 +24,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -141,7 +142,7 @@ public abstract class DepotRepository
* complexity is an inherent drawback, and it does execute two separate database queries
* for what the simple method does in one.
*/
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, QueryClause... clauses)
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, List<QueryClause> clauses)
throws PersistenceException
{
DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
@@ -158,6 +159,15 @@ public abstract class DepotRepository
new FindAllQuery.WithCache<T>(_ctx, type, clauses));
}
/**
* A varargs version of {@link #findAll(Class<T>,List<QueryClause>)}.
*/
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, QueryClause... clauses)
throws PersistenceException
{
return findAll(type, Arrays.asList(clauses));
}
/**
* Inserts the supplied persistent object into the database, assigning its primary key (if it
* has one) in the process.
@@ -22,6 +22,7 @@ package com.samskivert.jdbc.depot;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -54,7 +55,7 @@ public class DepotTypes
* are interrogated for their class definition sets through {@link SQLExpression#addClasses}.
*/
public static <T extends PersistentRecord> DepotTypes getDepotTypes (
PersistenceContext ctx, QueryClause... clauses)
PersistenceContext ctx, Collection<QueryClause> clauses)
throws PersistenceException
{
Set<Class<? extends PersistentRecord>> classSet =
@@ -67,6 +68,16 @@ public class DepotTypes
return new DepotTypes(ctx, classSet);
}
/**
* A varargs version of {@link #getDepotTypes(PersistenceContext,Collection<QueryClause>)}.
*/
public static <T extends PersistentRecord> DepotTypes getDepotTypes (
PersistenceContext ctx, QueryClause... clauses)
throws PersistenceException
{
return getDepotTypes(ctx, Arrays.asList(clauses));
}
/**
* Create a new DepotTypes with the given {@link PersistenceContext} and a collection of
* persistent record classes.
@@ -56,7 +56,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
*/
public static class WithCache<T extends PersistentRecord> extends FindAllQuery<T>
{
public WithCache (PersistenceContext ctx, Class<T> type, QueryClause[] clauses)
public WithCache (PersistenceContext ctx, Class<T> type, List<QueryClause> clauses)
throws PersistenceException
{
super(ctx, type);
@@ -167,7 +167,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
return result;
}
protected QueryClause[] _clauses;
protected List<QueryClause> _clauses;
}
/**
@@ -175,7 +175,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
*/
public static class Explicitly<T extends PersistentRecord> extends FindAllQuery<T>
{
public Explicitly (PersistenceContext ctx, Class<T> type, QueryClause[] clauses)
public Explicitly (PersistenceContext ctx, Class<T> type, List<QueryClause> clauses)
throws PersistenceException
{
super(ctx, type);
@@ -21,6 +21,7 @@
package com.samskivert.jdbc.depot.clause;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -41,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
* instantiation of marshallers, which may trigger table creations and schema migrations.
*/
public SelectClause (Class<T> pClass, String[] fields, QueryClause... clauses)
public SelectClause (Class<T> pClass, String[] fields, List<QueryClause> clauses)
{
_pClass = pClass;
_fields = fields;
@@ -102,6 +103,14 @@ public class SelectClause<T extends PersistentRecord> extends QueryClause
}
}
/**
* A varargs version of the constructor.
*/
public SelectClause (Class<T> pClass, String[] fields, QueryClause... clauses)
{
this(pClass, fields, Arrays.asList(clauses));
}
public FieldDefinition lookupDefinition (String field)
{
return _disMap.get(field);