From 79a466c42a272089abeeb5b2967e75753f57a6de Mon Sep 17 00:00:00 2001 From: samskivert Date: Wed, 3 Sep 2008 00:55:07 +0000 Subject: [PATCH] Any collection of anything that extends QueryClause is generally all we need. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2375 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/jdbc/depot/DepotRepository.java | 18 +++++++++++++++--- .../com/samskivert/jdbc/depot/DepotTypes.java | 2 +- .../samskivert/jdbc/depot/FindAllQuery.java | 10 +++++++--- .../jdbc/depot/clause/SelectClause.java | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 3bfb3aa3..72971769 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -25,6 +25,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; 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 load ( + Class type, Collection 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 load (Class type, QueryClause... clauses) throws PersistenceException @@ -142,7 +153,8 @@ 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, List clauses) + protected List findAll ( + Class type, Collection clauses) throws PersistenceException { DepotMarshaller marsh = _ctx.getMarshaller(type); @@ -160,7 +172,7 @@ public abstract class DepotRepository } /** - * A varargs version of {@link #findAll(Class,List)}. + * A varargs version of {@link #findAll(Class,Collection)}. */ protected List findAll (Class type, QueryClause... clauses) throws PersistenceException diff --git a/src/java/com/samskivert/jdbc/depot/DepotTypes.java b/src/java/com/samskivert/jdbc/depot/DepotTypes.java index ac1e18d4..e416636e 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotTypes.java +++ b/src/java/com/samskivert/jdbc/depot/DepotTypes.java @@ -55,7 +55,7 @@ public class DepotTypes * are interrogated for their class definition sets through {@link SQLExpression#addClasses}. */ public static DepotTypes getDepotTypes ( - PersistenceContext ctx, Collection clauses) + PersistenceContext ctx, Collection clauses) throws PersistenceException { Set> classSet = diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index 51adb3a2..976299df 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -24,7 +24,9 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; + import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -59,7 +61,8 @@ public abstract class FindAllQuery */ public static class WithCache extends FindAllQuery { - public WithCache (PersistenceContext ctx, Class type, List clauses) + public WithCache (PersistenceContext ctx, Class type, + Collection clauses) throws PersistenceException { super(ctx, type); @@ -192,7 +195,7 @@ public abstract class FindAllQuery } } - protected List _clauses; + protected Collection _clauses; } /** @@ -200,7 +203,8 @@ public abstract class FindAllQuery */ public static class Explicitly extends FindAllQuery { - public Explicitly (PersistenceContext ctx, Class type, List clauses) + public Explicitly (PersistenceContext ctx, Class type, + Collection 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 3489929b..b081d9ff 100644 --- a/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java +++ b/src/java/com/samskivert/jdbc/depot/clause/SelectClause.java @@ -42,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, List clauses) + public SelectClause (Class pClass, String[] fields, Collection clauses) { _pClass = pClass; _fields = fields;