cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r671550 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/ test/java/org/apache/cayenne/ test/resources/dml/
Date Wed, 25 Jun 2008 13:47:57 GMT
Author: aadamchik
Date: Wed Jun 25 06:47:56 2008
New Revision: 671550

URL: http://svn.apache.org/viewvc?rev=671550&view=rev
Log:
CAY-1082  ROP: RefreshQuery fails to refresh to-many relationships

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextRefreshQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextRefreshQueryTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java?rev=671550&r1=671549&r2=671550&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
Wed Jun 25 06:47:56 2008
@@ -24,8 +24,14 @@
 
 import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.cache.QueryCache;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.RefreshQuery;
+import org.apache.cayenne.reflect.AttributeProperty;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.PropertyVisitor;
+import org.apache.cayenne.reflect.ToManyProperty;
+import org.apache.cayenne.reflect.ToOneProperty;
 import org.apache.cayenne.remote.RemoteIncrementalFaultList;
 import org.apache.cayenne.util.ListResponse;
 import org.apache.cayenne.util.ObjectContextQueryAction;
@@ -137,8 +143,14 @@
     }
 
     private void invalidateLocally(CayenneContextGraphManager graphManager, Iterator<?>
it) {
+        if (!it.hasNext()) {
+            return;
+        }
+
+        EntityResolver resolver = actingContext.getEntityResolver();
+
         while (it.hasNext()) {
-            Persistent object = (Persistent) it.next();
+            final Persistent object = (Persistent) it.next();
 
             // we don't care about NEW objects,
             // but we still do care about HOLLOW, since snapshot might still be
@@ -147,11 +159,34 @@
                 continue;
             }
 
-            object.setPersistenceState(PersistenceState.HOLLOW);
+            ObjectId id = object.getObjectId();
+
+            // per CAY-1082 ROP objects (unlike CayenneDataObject) require all
+            // relationship faults invalidation.
+            ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
+            PropertyVisitor arcInvalidator = new PropertyVisitor() {
+
+                public boolean visitAttribute(AttributeProperty property) {
+                    return true;
+                }
+
+                public boolean visitToMany(ToManyProperty property) {
+                    property.invalidate(object);
+                    return true;
+                }
 
+                public boolean visitToOne(ToOneProperty property) {
+                    property.invalidate(object);
+                    return true;
+                }
+            };
+
+            descriptor.visitProperties(arcInvalidator);
+            object.setPersistenceState(PersistenceState.HOLLOW);
+            
             // remove cached changes
-            graphManager.changeLog.unregisterNode(object.getObjectId());
-            graphManager.stateLog.unregisterNode(object.getObjectId());
+            graphManager.changeLog.unregisterNode(id);
+            graphManager.stateLog.unregisterNode(id);
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java?rev=671550&r1=671549&r2=671550&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java
Wed Jun 25 06:47:56 2008
@@ -103,6 +103,6 @@
         assertSame(newTarget, o1.getTargets().get(new Integer(newId)));
         
         assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-        assertEquals(PersistenceState.HOLLOW, newTarget.getPersistenceState());
+        assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState());
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextRefreshQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextRefreshQueryTest.java?rev=671550&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextRefreshQueryTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextRefreshQueryTest.java
Wed Jun 25 06:47:56 2008
@@ -0,0 +1,64 @@
+/*****************************************************************
+ *   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 org.apache.art.Artist;
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.query.RefreshQuery;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CayenneContextRefreshQueryTest extends CayenneCase {
+
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    }
+    
+    private CayenneContext createClientContext() {
+        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
+        LocalConnection connection = new LocalConnection(serverChannel);
+        ClientChannel clientChannel = new ClientChannel(connection);
+        return new CayenneContext(clientChannel);
+    }
+    
+    public void testRefreshToMany() throws Exception {
+
+        deleteTestData();
+        createTestData("testRefreshObjectToMany");
+
+        CayenneContext context = createClientContext();
+
+        ClientMtTable1 a = DataObjectUtils.objectForPK(context, ClientMtTable1.class, 1);
+        assertEquals(2, a.getTable2Array().size());
+
+        createTestData("testRefreshObjectToManyUpdate");
+
+        RefreshQuery refresh = new RefreshQuery(a);
+        context.performGenericQuery(refresh);
+        assertEquals(PersistenceState.HOLLOW, a.getPersistenceState());
+        assertEquals(1, a.getTable2Array().size());
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextRefreshQueryTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextRefreshQueryTest.xml?rev=671550&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextRefreshQueryTest.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextRefreshQueryTest.xml
Wed Jun 25 06:47:56 2008
@@ -0,0 +1,55 @@
+<?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 -->
+	<!-- ======================================= -->
+	
+	<!-- ARTIST -->
+	<bean id="A1" 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="P11" 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_TABLE2 (TABLE2_ID, TABLE1_ID, GLOBAL_ATTRIBUTE) values (1, 1, 'g1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="P12" 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_TABLE2 (TABLE2_ID, TABLE1_ID, GLOBAL_ATTRIBUTE) values (2, 1, 'g1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="PU2" 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>
+		DELETE FROM MT_TABLE2 WHERE TABLE2_ID = 1
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="testRefreshObjectToMany" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="P11"/>
+				<ref bean="P12"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testRefreshObjectToManyUpdate" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="PU2"/>
+			</list>
+		</constructor-arg>
+	</bean>
+</beans>
\ No newline at end of file



Mime
View raw message