Support taking a List as well as a varargs array. There are no doubt other
places where this could be done. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2259 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -24,6 +24,7 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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
|
* 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, QueryClause... clauses)
|
protected <T extends PersistentRecord> List<T> findAll (Class<T> type, List<QueryClause> clauses)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
|
DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
|
||||||
@@ -158,6 +159,15 @@ public abstract class DepotRepository
|
|||||||
new FindAllQuery.WithCache<T>(_ctx, type, clauses));
|
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
|
* Inserts the supplied persistent object into the database, assigning its primary key (if it
|
||||||
* has one) in the process.
|
* has one) in the process.
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package com.samskivert.jdbc.depot;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -54,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, QueryClause... clauses)
|
PersistenceContext ctx, Collection<QueryClause> clauses)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
Set<Class<? extends PersistentRecord>> classSet =
|
Set<Class<? extends PersistentRecord>> classSet =
|
||||||
@@ -67,6 +68,16 @@ public class DepotTypes
|
|||||||
return new DepotTypes(ctx, classSet);
|
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
|
* Create a new DepotTypes with the given {@link PersistenceContext} and a collection of
|
||||||
* persistent record classes.
|
* 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 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
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
super(ctx, type);
|
super(ctx, type);
|
||||||
@@ -167,7 +167,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
|||||||
return result;
|
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 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
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
super(ctx, type);
|
super(ctx, type);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
package com.samskivert.jdbc.depot.clause;
|
package com.samskivert.jdbc.depot.clause;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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
|
* 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, QueryClause... clauses)
|
public SelectClause (Class<T> pClass, String[] fields, List<QueryClause> clauses)
|
||||||
{
|
{
|
||||||
_pClass = pClass;
|
_pClass = pClass;
|
||||||
_fields = fields;
|
_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)
|
public FieldDefinition lookupDefinition (String field)
|
||||||
{
|
{
|
||||||
return _disMap.get(field);
|
return _disMap.get(field);
|
||||||
|
|||||||
Reference in New Issue
Block a user