From 951b20106403a750811341462d1fe898e0011c37 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 26 Nov 2007 21:50:54 +0000 Subject: [PATCH] Support taking a List as well as a varargs array. There are no doubt other places where this could be done. --- .../com/samskivert/jdbc/depot/DepotRepository.java | 12 +++++++++++- src/java/com/samskivert/jdbc/depot/DepotTypes.java | 13 ++++++++++++- .../com/samskivert/jdbc/depot/FindAllQuery.java | 6 +++--- .../samskivert/jdbc/depot/clause/SelectClause.java | 11 ++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 4b1d376..a78f56c 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -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 List findAll (Class type, QueryClause... clauses) + protected List findAll (Class type, List clauses) throws PersistenceException { DepotMarshaller marsh = _ctx.getMarshaller(type); @@ -158,6 +159,15 @@ public abstract class DepotRepository new FindAllQuery.WithCache(_ctx, type, clauses)); } + /** + * A varargs version of {@link #findAll(Class,List)}. + */ + protected List findAll (Class 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. diff --git a/src/java/com/samskivert/jdbc/depot/DepotTypes.java b/src/java/com/samskivert/jdbc/depot/DepotTypes.java index b2d9d40..681e133 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotTypes.java +++ b/src/java/com/samskivert/jdbc/depot/DepotTypes.java @@ -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 DepotTypes getDepotTypes ( - PersistenceContext ctx, QueryClause... clauses) + PersistenceContext ctx, Collection clauses) throws PersistenceException { Set> classSet = @@ -67,6 +68,16 @@ public class DepotTypes return new DepotTypes(ctx, classSet); } + /** + * A varargs version of {@link #getDepotTypes(PersistenceContext,Collection)}. + */ + public static 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. diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index c15f81b..d7fb828 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -56,7 +56,7 @@ public abstract class FindAllQuery */ public static class WithCache extends FindAllQuery { - public WithCache (PersistenceContext ctx, Class type, QueryClause[] clauses) + public WithCache (PersistenceContext ctx, Class type, List clauses) throws PersistenceException { super(ctx, type); @@ -167,7 +167,7 @@ public abstract class FindAllQuery return result; } - protected QueryClause[] _clauses; + protected List _clauses; } /** @@ -175,7 +175,7 @@ public abstract class FindAllQuery */ public static class Explicitly extends FindAllQuery { - public Explicitly (PersistenceContext ctx, Class type, QueryClause[] clauses) + public Explicitly (PersistenceContext ctx, Class type, List clauses) throws PersistenceException { super(ctx, type); diff --git a/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java b/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java index fbefa04..3489929 100644 --- a/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java +++ b/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java @@ -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 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 pClass, String[] fields, QueryClause... clauses) + public SelectClause (Class pClass, String[] fields, List clauses) { _pClass = pClass; _fields = fields; @@ -102,6 +103,14 @@ public class SelectClause extends QueryClause } } + /** + * A varargs version of the constructor. + */ + public SelectClause (Class pClass, String[] fields, QueryClause... clauses) + { + this(pClass, fields, Arrays.asList(clauses)); + } + public FieldDefinition lookupDefinition (String field) { return _disMap.get(field);