cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r517252 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/query/SelectQueryMetadata.java test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
Date Mon, 12 Mar 2007 15:28:58 GMT
Author: aadamchik
Date: Mon Mar 12 08:28:57 2007
New Revision: 517252

URL: http://svn.apache.org/viewvc?view=rev&rev=517252
Log:
CAY-767: "fetchLimit" unaccounted when calculating cache key

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java?view=diff&rev=517252&r1=517251&r2=517252
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
Mon Mar 12 08:28:57 2007
@@ -41,10 +41,11 @@
                 this.cacheKey = query.getName();
             }
             else {
-                // create a unique key based on entity, qualifier and ordering
+                // create a unique key based on entity, qualifier, ordering and fetch
+                // limit
 
                 StringBuffer key = new StringBuffer();
-                
+
                 ObjEntity entity = getObjEntity();
                 if (entity != null) {
                     key.append(entity.getName());
@@ -73,6 +74,10 @@
                     }
                 }
                 
+                if(query.getFetchLimit() > 0) {
+                    key.append('/').append(query.getFetchLimit());
+                }
+
                 this.cacheKey = key.toString();
             }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java?view=diff&rev=517252&r1=517251&r2=517252
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryCacheKeyTest.java
Mon Mar 12 08:28:57 2007
@@ -19,6 +19,8 @@
 package org.apache.cayenne.query;
 
 import org.apache.art.Artist;
+import org.apache.art.Painting;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.unit.CayenneCase;
 
@@ -27,56 +29,133 @@
     public void testNoCache() {
 
         EntityResolver resolver = getDomain().getEntityResolver();
-        
+
         SelectQuery query = new SelectQuery(Artist.class);
-        
+
         QueryMetadata md1 = query.getMetaData(resolver);
         assertEquals(QueryMetadata.NO_CACHE, md1.getCachePolicy());
         assertNull(md1.getCacheKey());
-        
+
         query.setName("XYZ");
         QueryMetadata md2 = query.getMetaData(resolver);
         assertEquals(QueryMetadata.NO_CACHE, md2.getCachePolicy());
         assertNull(md2.getCacheKey());
     }
-    
+
     public void testLocalCache() {
 
         EntityResolver resolver = getDomain().getEntityResolver();
-        
+
         SelectQuery query = new SelectQuery(Artist.class);
 
         query.setCachePolicy(QueryMetadata.LOCAL_CACHE);
-        
+
         QueryMetadata md1 = query.getMetaData(resolver);
         assertEquals(QueryMetadata.LOCAL_CACHE, md1.getCachePolicy());
         assertNotNull(md1.getCacheKey());
     }
-    
+
     public void testSharedCache() {
 
         EntityResolver resolver = getDomain().getEntityResolver();
-        
+
         SelectQuery query = new SelectQuery(Artist.class);
 
         query.setCachePolicy(QueryMetadata.SHARED_CACHE);
-        
+
         QueryMetadata md1 = query.getMetaData(resolver);
         assertEquals(QueryMetadata.SHARED_CACHE, md1.getCachePolicy());
         assertNotNull(md1.getCacheKey());
     }
-    
+
     public void testNamedQuery() {
 
         EntityResolver resolver = getDomain().getEntityResolver();
-        
+
         SelectQuery query = new SelectQuery(Artist.class);
 
         query.setCachePolicy(QueryMetadata.SHARED_CACHE);
         query.setName("XYZ");
-        
+
         QueryMetadata md1 = query.getMetaData(resolver);
         assertEquals(QueryMetadata.SHARED_CACHE, md1.getCachePolicy());
         assertEquals("XYZ", md1.getCacheKey());
+    }
+
+    public void testUniqueKeyEntity() {
+
+        EntityResolver resolver = getDomain().getEntityResolver();
+
+        SelectQuery q1 = new SelectQuery(Artist.class);
+        q1.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+
+        SelectQuery q2 = new SelectQuery(Artist.class);
+        q2.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+
+        SelectQuery q3 = new SelectQuery(Painting.class);
+        q3.setCachePolicy(QueryMetadata.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()));
+    }
+
+    public void testUniqueKeyEntityQualifier() {
+
+        EntityResolver resolver = getDomain().getEntityResolver();
+
+        SelectQuery q1 = new SelectQuery(Artist.class);
+        q1.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q1.setQualifier(ExpressionFactory.matchExp("a", "b"));
+
+        SelectQuery q2 = new SelectQuery(Artist.class);
+        q2.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q2.setQualifier(ExpressionFactory.matchExp("a", "b"));
+
+        SelectQuery q3 = new SelectQuery(Artist.class);
+        q3.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q3.setQualifier(ExpressionFactory.matchExp("a", "c"));
+
+        assertNotNull(q1.getMetaData(resolver).getCacheKey());
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
+                .getMetaData(resolver)
+                .getCacheKey());
+
+        assertFalse(q1.getMetaData(resolver).getCacheKey().equals(
+                q3.getMetaData(resolver).getCacheKey()));
+    }
+
+    public void testUniqueKeyEntityFetchLimit() {
+
+        EntityResolver resolver = getDomain().getEntityResolver();
+
+        SelectQuery q1 = new SelectQuery(Artist.class);
+        q1.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q1.setFetchLimit(5);
+
+        SelectQuery q2 = new SelectQuery(Artist.class);
+        q2.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q2.setFetchLimit(5);
+
+        SelectQuery q3 = new SelectQuery(Artist.class);
+        q3.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+        q3.setFetchLimit(6);
+
+        SelectQuery q4 = new SelectQuery(Artist.class);
+        q4.setCachePolicy(QueryMetadata.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()));
     }
 }



Mime
View raw message