cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1485947 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/query/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/query/
Date Fri, 24 May 2013 06:30:21 GMT
Author: aadamchik
Date: Fri May 24 06:30:21 2013
New Revision: 1485947

URL: http://svn.apache.org/r1485947
Log:
CAY-1825 Simplify API for setting up query caching

for SelectQuery

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java?rev=1485947&r1=1485946&r2=1485947&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
Fri May 24 06:30:21 2013
@@ -36,12 +36,12 @@ import org.apache.cayenne.util.XMLEncode
 import org.apache.cayenne.util.XMLSerializable;
 
 /**
- * A query that selects persistent objects of a certain type or "raw data" (aka DataRows).
- * Supports expression qualifier, multiple orderings and a number of other parameters that
- * serve as runtime hints to Cayenne on how to optimize the fetch and result processing.
+ * A query that selects persistent objects of a certain type or "raw data" (aka
+ * DataRows). Supports expression qualifier, multiple orderings and a number of
+ * other parameters that serve as runtime hints to Cayenne on how to optimize
+ * the fetch and result processing.
  */
-public class SelectQuery<T> extends QualifiedQuery implements ParameterizedQuery,
-        XMLSerializable, Select<T> {
+public class SelectQuery<T> extends QualifiedQuery implements ParameterizedQuery, XMLSerializable,
Select<T> {
 
     public static final String DISTINCT_PROPERTY = "cayenne.SelectQuery.distinct";
     public static final boolean DISTINCT_DEFAULT = false;
@@ -50,11 +50,12 @@ public class SelectQuery<T> extends Qual
     protected boolean distinct;
 
     SelectQueryMetadata metaData = new SelectQueryMetadata();
-    
+
     /**
      * Creates a SelectQuery that selects objects of a given persistent class.
-     *
-     * @param rootClass the Class of objects fetched by this query.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
      * 
      * @since 3.2
      */
@@ -63,32 +64,37 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates a SelectQuery that selects objects of a given persistent class that match
-     * supplied qualifier.
-     *
-     * @param rootClass the Class of objects fetched by this query.
-     * @param qualifier an Expression indicating which objects should be fetched.
+     * Creates a SelectQuery that selects objects of a given persistent class
+     * that match supplied qualifier.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
      * 
      * @since 3.2
      */
     public static <T> SelectQuery<T> query(Class<T> rootClass, Expression
qualifier) {
         return new SelectQuery<T>(rootClass, qualifier);
     }
-    
+
     /**
-     * Creates a SelectQuery that selects objects of a given persistent class that match
-     * supplied qualifier.
-     *
-     * @param rootClass the Class of objects fetched by this query.
-     * @param qualifier an Expression indicating which objects should be fetched.
-     * @param orderings defines how to order the results, may be null.
+     * Creates a SelectQuery that selects objects of a given persistent class
+     * that match supplied qualifier.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * @param orderings
+     *            defines how to order the results, may be null.
      * 
      * @since 3.2
      */
     public static <T> SelectQuery<T> query(Class<T> rootClass, Expression
qualifier, List<Ordering> orderings) {
         return new SelectQuery<T>(rootClass, qualifier, orderings);
     }
-    
+
     /**
      * Creates a SelectQuery that selects DataRows that correspond to a given
      * persistent class that match supplied qualifier.
@@ -118,18 +124,22 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Creates a SelectQuery with null qualifier, for the specifed ObjEntity
-     *
-     * @param root the ObjEntity this SelectQuery is for.
+     * 
+     * @param root
+     *            the ObjEntity this SelectQuery is for.
      */
     public SelectQuery(ObjEntity root) {
         this(root, null);
     }
 
     /**
-     * Creates a SelectQuery for the specified ObjEntity with the given qualifier.
-     *
-     * @param root the ObjEntity this SelectQuery is for.
-     * @param qualifier an Expression indicating which objects should be fetched
+     * Creates a SelectQuery for the specified ObjEntity with the given
+     * qualifier.
+     * 
+     * @param root
+     *            the ObjEntity this SelectQuery is for.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched
      */
     public SelectQuery(ObjEntity root, Expression qualifier) {
         this(root, qualifier, null);
@@ -138,10 +148,13 @@ public class SelectQuery<T> extends Qual
     /**
      * Creates a SelectQuery for the specified ObjEntity with the given
      * qualifier and orderings.
-     *
-     * @param root the ObjEntity this SelectQuery is for.
-     * @param qualifier an Expression indicating which objects should be fetched.
-     * @param orderings defines how to order the results, may be null.
+     * 
+     * @param root
+     *            the ObjEntity this SelectQuery is for.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * @param orderings
+     *            defines how to order the results, may be null.
      * @since 3.1
      */
     public SelectQuery(ObjEntity root, Expression qualifier, List<Ordering> orderings)
{
@@ -151,32 +164,39 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates a SelectQuery that selects all objects of a given persistent class.
-     *
-     * @param rootClass the Class of objects fetched by this query.
+     * Creates a SelectQuery that selects all objects of a given persistent
+     * class.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
      */
     public SelectQuery(Class<T> rootClass) {
         this(rootClass, null);
     }
-    
+
     /**
-     * Creates a SelectQuery that selects objects of a given persistent class that match
-     * supplied qualifier.
-     *
-     * @param rootClass the Class of objects fetched by this query.
-     * @param qualifier an Expression indicating which objects should be fetched.
+     * Creates a SelectQuery that selects objects of a given persistent class
+     * that match supplied qualifier.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
      */
     public SelectQuery(Class<T> rootClass, Expression qualifier) {
         this(rootClass, qualifier, null);
     }
 
     /**
-     * Creates a SelectQuery that selects objects of a given persistent class that match
-     * supplied qualifier.
-     *
-     * @param rootClass the Class of objects fetched by this query.
-     * @param qualifier an Expression indicating which objects should be fetched.
-     * @param orderings defines how to order the results, may be null.
+     * Creates a SelectQuery that selects objects of a given persistent class
+     * that match supplied qualifier.
+     * 
+     * @param rootClass
+     *            the Class of objects fetched by this query.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * @param orderings
+     *            defines how to order the results, may be null.
      * @since 3.1
      */
     public SelectQuery(Class<T> rootClass, Expression qualifier, List<Ordering>
orderings) {
@@ -186,8 +206,9 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Creates a SelectQuery for the specified DbEntity.
-     *
-     * @param root the DbEntity this SelectQuery is for.
+     * 
+     * @param root
+     *            the DbEntity this SelectQuery is for.
      * @since 1.1
      */
     public SelectQuery(DbEntity root) {
@@ -195,10 +216,13 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates a SelectQuery for the specified DbEntity with the given qualifier.
-     *
-     * @param root the DbEntity this SelectQuery is for.
-     * @param qualifier an Expression indicating which objects should be fetched.
+     * Creates a SelectQuery for the specified DbEntity with the given
+     * qualifier.
+     * 
+     * @param root
+     *            the DbEntity this SelectQuery is for.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
      * @since 1.1
      */
     public SelectQuery(DbEntity root, Expression qualifier) {
@@ -206,11 +230,15 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates a SelectQuery for the specified DbEntity with the given qualifier and orderings.
-     *
-     * @param root the DbEntity this SelectQuery is for.
-     * @param qualifier an Expression indicating which objects should be fetched.
-     * @param orderings defines how to order the results, may be null.
+     * Creates a SelectQuery for the specified DbEntity with the given qualifier
+     * and orderings.
+     * 
+     * @param root
+     *            the DbEntity this SelectQuery is for.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * @param orderings
+     *            defines how to order the results, may be null.
      * @since 3.1
      */
     public SelectQuery(DbEntity root, Expression qualifier, List<Ordering> orderings)
{
@@ -227,20 +255,23 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates SelectQuery with <code>objEntityName</code> and <code>qualifier</code>
-     * parameters.
+     * Creates SelectQuery with <code>objEntityName</code> and
+     * <code>qualifier</code> parameters.
      */
     public SelectQuery(String objEntityName, Expression qualifier) {
         this(objEntityName, qualifier, null);
     }
 
     /**
-     * Creates a SelectQuery that selects objects of a given persistent class that match
-     * supplied qualifier.
-     *
-     * @param objEntityName the name of the ObjEntity to fetch from.
-     * @param qualifier an Expression indicating which objects should be fetched.
-     * @param orderings defines how to order the results, may be null.
+     * Creates a SelectQuery that selects objects of a given persistent class
+     * that match supplied qualifier.
+     * 
+     * @param objEntityName
+     *            the name of the ObjEntity to fetch from.
+     * @param qualifier
+     *            an Expression indicating which objects should be fetched.
+     * @param orderings
+     *            defines how to order the results, may be null.
      * @since 3.1
      */
     public SelectQuery(String objEntityName, Expression qualifier, List<Ordering> orderings)
{
@@ -265,23 +296,23 @@ public class SelectQuery<T> extends Qual
             QueryMetadataWrapper wrapper = new QueryMetadataWrapper(metaData);
             wrapper.override(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY, Boolean.TRUE);
             return wrapper;
-        }
-        else {
+        } else {
             return metaData;
         }
     }
 
     /**
-     * Routes itself and if there are any prefetches configured, creates prefetch queries
-     * and routes them as well.
-     *
+     * Routes itself and if there are any prefetches configured, creates
+     * prefetch queries and routes them as well.
+     * 
      * @since 1.2
      */
     @Override
     public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)
{
         super.route(router, resolver, substitutedQuery);
 
-        // suppress prefetches for paginated queries.. instead prefetches will be resolved
+        // suppress prefetches for paginated queries.. instead prefetches will
+        // be resolved
         // per row...
         if (metaData.getPageSize() <= 0) {
             routePrefetches(router, resolver);
@@ -290,7 +321,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Creates and routes extra disjoint prefetch queries.
-     *
+     * 
      * @since 1.2
      */
     void routePrefetches(QueryRouter router, EntityResolver resolver) {
@@ -299,7 +330,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Calls "makeSelect" on the visitor.
-     *
+     * 
      * @since 1.2
      */
     @Override
@@ -309,7 +340,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Initializes query parameters using a set of properties.
-     *
+     * 
      * @since 1.1
      */
     public void initWithProperties(Map<String, ?> properties) {
@@ -322,16 +353,14 @@ public class SelectQuery<T> extends Qual
         Object distinct = properties.get(DISTINCT_PROPERTY);
 
         // init ivars from properties
-        this.distinct = (distinct != null)
-                ? "true".equalsIgnoreCase(distinct.toString())
-                : DISTINCT_DEFAULT;
+        this.distinct = (distinct != null) ? "true".equalsIgnoreCase(distinct.toString())
: DISTINCT_DEFAULT;
 
         metaData.initWithProperties(properties);
     }
 
     /**
      * Prints itself as XML to the provided PrintWriter.
-     *
+     * 
      * @since 1.1
      */
     public void encodeAsXML(XMLEncoder encoder) {
@@ -346,20 +375,16 @@ public class SelectQuery<T> extends Qual
         if (root instanceof String) {
             rootType = MapLoader.OBJ_ENTITY_ROOT;
             rootString = root.toString();
-        }
-        else if (root instanceof ObjEntity) {
+        } else if (root instanceof ObjEntity) {
             rootType = MapLoader.OBJ_ENTITY_ROOT;
             rootString = ((ObjEntity) root).getName();
-        }
-        else if (root instanceof DbEntity) {
+        } else if (root instanceof DbEntity) {
             rootType = MapLoader.DB_ENTITY_ROOT;
             rootString = ((DbEntity) root).getName();
-        }
-        else if (root instanceof Procedure) {
+        } else if (root instanceof Procedure) {
             rootType = MapLoader.PROCEDURE_ROOT;
             rootString = ((Procedure) root).getName();
-        }
-        else if (root instanceof Class<?>) {
+        } else if (root instanceof Class<?>) {
             rootType = MapLoader.JAVA_CLASS_ROOT;
             rootString = ((Class<?>) root).getName();
         }
@@ -401,19 +426,19 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * A shortcut for {@link #queryWithParameters(Map, boolean)}that prunes parts of
-     * qualifier that have no parameter value set.
+     * A shortcut for {@link #queryWithParameters(Map, boolean)}that prunes
+     * parts of qualifier that have no parameter value set.
      */
     public SelectQuery<T> queryWithParameters(Map<String, ?> parameters) {
         return queryWithParameters(parameters, true);
     }
 
     /**
-     * Returns a query built using this query as a prototype, using a set of parameters to
-     * build the qualifier.
-     *
-     * @see org.apache.cayenne.exp.Expression#expWithParameters(java.util.Map, boolean)
-     *      parameter substitution.
+     * Returns a query built using this query as a prototype, using a set of
+     * parameters to build the qualifier.
+     * 
+     * @see org.apache.cayenne.exp.Expression#expWithParameters(java.util.Map,
+     *      boolean) parameter substitution.
      */
     public SelectQuery<T> queryWithParameters(Map<String, ?> parameters, boolean
pruneMissing) {
         // create a query replica
@@ -436,9 +461,10 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Creates and returns a new SelectQuery built using this query as a prototype and
-     * substituting qualifier parameters with the values from the map.
-     *
+     * Creates and returns a new SelectQuery built using this query as a
+     * prototype and substituting qualifier parameters with the values from the
+     * map.
+     * 
      * @since 1.1
      */
     public SelectQuery<T> createQuery(Map<String, ?> parameters) {
@@ -464,7 +490,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Adds ordering specification to this query orderings.
-     *
+     * 
      * @since 3.0
      */
     public void addOrdering(String sortPathSpec, SortOrder order) {
@@ -473,7 +499,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Removes ordering.
-     *
+     * 
      * @since 1.1
      */
     public void removeOrdering(Ordering ordering) {
@@ -504,19 +530,20 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
-     * Sets <code>distinct</code> property that determines whether this query
returns
-     * distinct row.
+     * Sets <code>distinct</code> property that determines whether this query
+     * returns distinct row.
      */
     public void setDistinct(boolean distinct) {
         this.distinct = distinct;
     }
 
     /**
-     * Adds one or more aliases for the qualifier expression path. Aliases serve to
-     * instruct Cayenne to generate separate sets of joins for overlapping paths, that
-     * maybe needed for complex conditions. An example of an <i>implicit</i>
splits is this
-     * method: {@link ExpressionFactory#matchAllExp(String, Object...)}.
-     *
+     * Adds one or more aliases for the qualifier expression path. Aliases serve
+     * to instruct Cayenne to generate separate sets of joins for overlapping
+     * paths, that maybe needed for complex conditions. An example of an
+     * <i>implicit</i> splits is this method:
+     * {@link ExpressionFactory#matchAllExp(String, Object...)}.
+     * 
      * @since 3.0
      */
     public void aliasPathSplits(String path, String... aliases) {
@@ -539,19 +566,19 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Adds a prefetch with specified relationship path to the query.
-     *
+     * 
      * @since 3.2
      */
     public PrefetchTreeNode addPrefetch(PrefetchTreeNode prefetchElement) {
         String path = prefetchElement.getPath();
         int semantics = prefetchElement.getSemantics();
-        
+
         return metaData.addPrefetch(path, semantics);
     }
-    
+
     /**
      * Adds a prefetch with specified relationship path to the query.
-     *
+     * 
      * @since 1.2 signature changed to return created PrefetchTreeNode.
      */
     public PrefetchTreeNode addPrefetch(String prefetchPath) {
@@ -567,7 +594,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Removes prefetch.
-     *
+     * 
      * @since 1.1
      */
     public void removePrefetch(String prefetchPath) {
@@ -579,8 +606,8 @@ public class SelectQuery<T> extends Qual
      * rows as opposed to DataObjects, <code>false</code> for DataObjects. This
      * is a hint to QueryEngine executing this query.
      * 
-     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)}
-     *             to create DataRow query instead.
+     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)} to
+     *             create DataRow query instead.
      */
     public boolean isFetchingDataRows() {
         return (root instanceof DbEntity) || metaData.isFetchingDataRows();
@@ -594,8 +621,8 @@ public class SelectQuery<T> extends Qual
      * setting has no effect, and data rows are always fetched. </i>
      * </p>
      * 
-     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)}
-     *             to create DataRow query instead.
+     * @deprecated since 3.2, use {@link #dataRowQuery(Class, Expression)} to
+     *             create DataRow query instead.
      */
     public void setFetchingDataRows(boolean flag) {
         metaData.setFetchingDataRows(flag);
@@ -630,8 +657,40 @@ public class SelectQuery<T> extends Qual
     }
 
     /**
+     * Instructs Cayenne to look for query results in the "local" cache when
+     * running the query. This is a short-hand notation for:
+     * 
+     * <pre>
+     * query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+     * query.setCacheGroups(&quot;group1&quot;, &quot;group2&quot;);
+     * </pre>
+     * 
+     * @since 3.2
+     */
+    public void useLocalCache(String... cacheGroups) {
+        setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+        setCacheGroups(cacheGroups);
+    }
+
+    /**
+     * Instructs Cayenne to look for query results in the "shared" cache when
+     * running the query. This is a short-hand notation for:
+     * 
+     * <pre>
+     * query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+     * query.setCacheGroups(&quot;group1&quot;, &quot;group2&quot;);
+     * </pre>
+     * 
+     * @since 3.2
+     */
+    public void useSharedCache(String... cacheGroups) {
+        setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        setCacheGroups(cacheGroups);
+    }
+
+    /**
      * Returns the fetchOffset.
-     *
+     * 
      * @since 3.0
      */
     public int getFetchOffset() {
@@ -668,16 +727,19 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Sets <code>pageSize</code> property.
-     *
-     * By setting a page size, the Collection returned by performing a query will return
-     * <i>hollow</i> DataObjects. This is considerably faster and uses a tiny
fraction of the memory
-     * compared to a non-paged query when large numbers of objects are returned in the result.
-     * When a hollow DataObject is accessed all DataObjects on the same page will be faulted
into
-     * memory. There will be a small delay when faulting objects while the data is fetched
-     * from the data source, but otherwise you do not need to do anything special to access
data
-     * in hollow objects. The first page is always faulted into memory immediately.
-     *
-     * @param pageSize The pageSize to set
+     * 
+     * By setting a page size, the Collection returned by performing a query
+     * will return <i>hollow</i> DataObjects. This is considerably faster and
+     * uses a tiny fraction of the memory compared to a non-paged query when
+     * large numbers of objects are returned in the result. When a hollow
+     * DataObject is accessed all DataObjects on the same page will be faulted
+     * into memory. There will be a small delay when faulting objects while the
+     * data is fetched from the data source, but otherwise you do not need to do
+     * anything special to access data in hollow objects. The first page is
+     * always faulted into memory immediately.
+     * 
+     * @param pageSize
+     *            The pageSize to set
      */
     public void setPageSize(int pageSize) {
         metaData.setPageSize(pageSize);
@@ -685,7 +747,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Returns a list that internally stores orderings, creating it on demand.
-     *
+     * 
      * @since 1.2
      */
     List<Ordering> nonNullOrderings() {
@@ -698,7 +760,7 @@ public class SelectQuery<T> extends Qual
 
     /**
      * Sets statement's fetch size (0 for default size)
-     *
+     * 
      * @since 3.0
      */
     public void setStatementFetchSize(int size) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java?rev=1485947&r1=1485946&r2=1485947&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
Fri May 24 06:30:21 2013
@@ -20,11 +20,9 @@ package org.apache.cayenne.access;
 
 import java.util.List;
 
-import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.QueryCacheStrategy;
 import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
@@ -70,8 +68,8 @@ public class DataContextPaginatedQueryTe
 
         createArtistsDataSet();
 
-        SelectQuery query = new SelectQuery(Artist.class);
-        query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+        SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
+        query.addOrdering(Artist.ARTIST_NAME.asc());
         query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
         query.setPageSize(5);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java?rev=1485947&r1=1485946&r2=1485947&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
Fri May 24 06:30:21 2013
@@ -48,7 +48,7 @@ public class SelectQueryCacheKeyTest ext
 
     public void testLocalCache() {
 
-        SelectQuery query = new SelectQuery(Artist.class);
+        SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
 
         query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
 
@@ -57,9 +57,28 @@ public class SelectQueryCacheKeyTest ext
         assertNotNull(md1.getCacheKey());
     }
 
+    public void testUseLocalCache() {
+
+        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
+        q1.useLocalCache();
+
+        QueryMetadata md1 = q1.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+        assertEquals(0, md1.getCacheGroups().length);
+        
+        SelectQuery<Artist> q2 = new SelectQuery<Artist>(Artist.class);
+        q2.useLocalCache("g1", "g2");
+
+        QueryMetadata md2 = q2.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md2.getCacheStrategy());
+        assertNotNull(md2.getCacheKey());
+        assertEquals(2, md2.getCacheGroups().length);
+    }
+
     public void testSharedCache() {
 
-        SelectQuery query = new SelectQuery(Artist.class);
+        SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
 
         query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
 
@@ -67,6 +86,25 @@ public class SelectQueryCacheKeyTest ext
         assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
         assertNotNull(md1.getCacheKey());
     }
+    
+    public void testUseSharedCache() {
+
+        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
+        q1.useSharedCache();
+
+        QueryMetadata md1 = q1.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+        assertEquals(0, md1.getCacheGroups().length);
+        
+        SelectQuery<Artist> q2 = new SelectQuery<Artist>(Artist.class);
+        q2.useSharedCache("g1", "g2");
+
+        QueryMetadata md2 = q2.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md2.getCacheStrategy());
+        assertNotNull(md2.getCacheKey());
+        assertEquals(2, md2.getCacheGroups().length);
+    }
 
     public void testNamedQuery() {
 
@@ -92,12 +130,9 @@ public class SelectQueryCacheKeyTest ext
         q3.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
 
         assertNotNull(q1.getMetaData(resolver).getCacheKey());
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2.getMetaData(resolver).getCacheKey());
 
-        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(
-                q3.getMetaData(resolver).getCacheKey()));
+        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(q3.getMetaData(resolver).getCacheKey()));
     }
 
     public void testUniqueKeyEntityQualifier() {
@@ -115,12 +150,9 @@ public class SelectQueryCacheKeyTest ext
         q3.setQualifier(ExpressionFactory.matchExp("a", "c"));
 
         assertNotNull(q1.getMetaData(resolver).getCacheKey());
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2.getMetaData(resolver).getCacheKey());
 
-        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(
-                q3.getMetaData(resolver).getCacheKey()));
+        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(q3.getMetaData(resolver).getCacheKey()));
     }
 
     public void testUniqueKeyEntityFetchLimit() {
@@ -141,13 +173,9 @@ public class SelectQueryCacheKeyTest ext
         q4.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
 
         assertNotNull(q1.getMetaData(resolver).getCacheKey());
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
-
-        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(
-                q3.getMetaData(resolver).getCacheKey()));
-        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(
-                q4.getMetaData(resolver).getCacheKey()));
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2.getMetaData(resolver).getCacheKey());
+
+        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(q3.getMetaData(resolver).getCacheKey()));
+        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(q4.getMetaData(resolver).getCacheKey()));
     }
 }



Mime
View raw message