cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r629614 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/util/ test/java/org/apache/cayenne/ test/resources/dml/
Date Wed, 20 Feb 2008 21:17:05 GMT
Author: aadamchik
Date: Wed Feb 20 13:16:58 2008
New Revision: 629614

URL: http://svn.apache.org/viewvc?rev=629614&view=rev
Log:
CAY-986 LOCAL_CACHE policy fails when query is paged

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextPaginatedListCachingTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java?rev=629614&r1=629613&r2=629614&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/ObjectContextQueryAction.java
Wed Feb 20 13:16:58 2008
@@ -80,6 +80,10 @@
             if (interceptRelationshipQuery() != DONE) {
                 if (interceptRefreshQuery() != DONE) {
                     if (interceptLocalCache() != DONE) {
+                        // when changing the flow below, make sure to update
+                        // 'getCacheObjectFactory' method that mimics the interceptors
+                        // below 'interceptLocalCache'. See comment in an inner class
+                        // factory in this method...
                         if (interceptPaginatedQuery() != DONE) {
                             runQuery();
                         }
@@ -146,7 +150,7 @@
                 Object object = actingContext.getGraphManager().getNode(
                         oidQuery.getObjectId());
                 if (object != null) {
-                    
+
                     // do not return hollow objects
                     if (((Persistent) object).getPersistenceState() == PersistenceState.HOLLOW)
{
                         return !DONE;
@@ -222,13 +226,12 @@
 
         return !DONE;
     }
-    
-    
+
     /**
      * @since 3.0
      */
     protected abstract boolean interceptPaginatedQuery();
-    
+
     /**
      * @since 3.0
      */
@@ -283,7 +286,12 @@
         return new QueryCacheEntryFactory() {
 
             public Object createObject() {
-                runQuery();
+                // must follow the same logic as 'execute' below locla cache interceptor
+                // method... reuse that code somehow???
+                if (interceptPaginatedQuery() != DONE) {
+                    runQuery();
+                }
+
                 return response.firstList();
             }
         };

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingTest.java?rev=629614&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingTest.java
Wed Feb 20 13:16:58 2008
@@ -0,0 +1,74 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne;
+
+import java.util.List;
+
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.query.Ordering;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.UnitLocalConnection;
+
+public class CayenneContextPaginatedListCachingTest extends CayenneCase {
+
+    protected UnitLocalConnection connection;
+    protected CayenneContext context;
+
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
+        connection = new UnitLocalConnection(
+                serverChannel,
+                LocalConnection.HESSIAN_SERIALIZATION);
+        ClientChannel clientChannel = new ClientChannel(connection);
+        context = new CayenneContext(clientChannel);
+    }
+
+    public void testLocalCache() throws Exception {
+        deleteTestData();
+        createTestData("prepare");
+
+        SelectQuery query = new SelectQuery(ClientMtTable1.class);
+        query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, Ordering.ASC);
+        query.setPageSize(3);
+        query.setCachePolicy(QueryMetadata.LOCAL_CACHE);
+
+        List<?> result1 = context.performQuery(query);
+        assertEquals(7, result1.size());
+
+        // ensure we can resolve all objects without a failure...
+        for(Object x : result1) {
+            ((ClientMtTable1) x).getGlobalAttribute1();
+        }
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextPaginatedListCachingTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextPaginatedListCachingTest.xml?rev=629614&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextPaginatedListCachingTest.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextPaginatedListCachingTest.xml
Wed Feb 20 13:16:58 2008
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-lazy-init="true">	
+	<!-- ======================================= -->
+	<!-- Named Queries -->
+	<!-- ======================================= -->
+	
+	<bean id="INSERT_MT_TABLE11" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (1, 'g1',
's1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE12" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (2, 'g2',
's2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE13" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (3, 'g3',
's3')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE14" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (4, 'g4',
's4')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE15" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (5, 'g5',
's5')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE16" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (6, 'g6',
's6')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="INSERT_MT_TABLE17" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.cayenne.testdo.mt.MtTable1</value></constructor-arg>
+		<constructor-arg><value>
+		insert into MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) values (7, 'g7',
's7')
+		</value></constructor-arg>
+	</bean>
+	
+	
+	<!-- ======================================= -->
+	<!-- Data Sets -->
+	<!-- ======================================= -->	
+	<bean id="prepare" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="INSERT_MT_TABLE11"/>
+				<ref bean="INSERT_MT_TABLE12"/>
+				<ref bean="INSERT_MT_TABLE13"/>
+				<ref bean="INSERT_MT_TABLE14"/>
+				<ref bean="INSERT_MT_TABLE15"/>
+				<ref bean="INSERT_MT_TABLE16"/>
+				<ref bean="INSERT_MT_TABLE17"/>
+			</list>
+		</constructor-arg>
+	</bean>
+</beans>
\ No newline at end of file



Mime
View raw message