cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r908687 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/
Date Wed, 10 Feb 2010 22:22:05 GMT
Author: aadamchik
Date: Wed Feb 10 22:21:37 2010
New Revision: 908687

URL: http://svn.apache.org/viewvc?rev=908687&view=rev
Log:
CAY-1378 Error unsetting to-many DataObject property

reverting CAY-1009 patch + some trivial method refactoring

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=908687&r1=908686&r2=908687&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Wed Feb 10 22:21:37 2010
@@ -44,6 +44,8 @@
 
 Bug Fixes Since 3.0RC2:
 
+CAY-1378 Error unsetting to-many DataObject property
+	(this also reverts CAY-1009)
 CAY-1379 Error resolving fault, no matching row exists in the database
 CAY-1382 org.apache.cayenne.reflect.EnumConverter not handling null values for ExtendedEnumerations
 CAY-1383 unneeded target in modeler attributes inspection 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=908687&r1=908686&r2=908687&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
Wed Feb 10 22:21:37 2010
@@ -84,7 +84,7 @@
     public ObjRelationship(String name) {
         super(name);
     }
-    
+
     /**
      * @since 3.1
      */
@@ -171,6 +171,7 @@
      * Returns a "complimentary" ObjRelationship going in the opposite direction. Returns
      * null if no such relationship is found.
      */
+    @Override
     public ObjRelationship getReverseRelationship() {
 
         // reverse the list
@@ -178,8 +179,8 @@
         List<DbRelationship> reversed = new ArrayList<DbRelationship>(relationships
                 .size());
 
-        for (DbRelationship rel : relationships) {
-            DbRelationship reverse = rel.getReverseRelationship();
+        for (DbRelationship relationship : relationships) {
+            DbRelationship reverse = relationship.getReverseRelationship();
             if (reverse == null) {
                 return null;
             }
@@ -191,15 +192,16 @@
         if (target == null) {
             return null;
         }
+        
+        Entity source = getSourceEntity();
 
-        Iterator<?> it = target.getRelationships().iterator();
-        while (it.hasNext()) {
-            ObjRelationship rel = (ObjRelationship) it.next();
-            if (target.isSubentityOf((ObjEntity) rel.getTargetEntity())) {
+        for (ObjRelationship relationship : target.getRelationships()) {
+ 
+            if (relationship.getTargetEntity() != source) {
                 continue;
             }
 
-            List<?> otherRels = rel.getDbRelationships();
+            List<?> otherRels = relationship.getDbRelationships();
             if (reversed.size() != otherRels.size()) {
                 continue;
             }
@@ -214,7 +216,7 @@
             }
 
             if (relsMatch) {
-                return rel;
+                return relationship;
             }
         }
 
@@ -782,14 +784,14 @@
     public void setMapKey(String mapKey) {
         this.mapKey = mapKey;
     }
-    
+
     @Override
     public boolean isMandatory() {
         refreshFromDeferredPath();
         if (dbRelationships.size() == 0) {
             return false;
         }
-        
+
         return dbRelationships.get(0).isMandatory();
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java?rev=908687&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java
Wed Feb 10 22:21:37 2010
@@ -0,0 +1,62 @@
+/*****************************************************************
+ *   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.unit.jira;
+
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.testdo.inheritance_flat.Group;
+import org.apache.cayenne.testdo.inheritance_flat.User;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CAY_1378Test extends CayenneCase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteTestData();
+    }
+
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack("InheritanceFlatStack");
+    }
+
+    public void testFlattenedNullifyNullifyDeleteRules() throws Exception {
+
+        DataContext context = createDataContext();
+
+        User user = context.newObject(User.class);
+        user.setName("test_user");
+        Group group = context.newObject(Group.class);
+        group.setName("test_group");
+        group.addToGroupMembers(user);
+        context.commitChanges();
+
+        context.deleteObject(user);
+        assertTrue(group.getGroupMembers().isEmpty());
+
+        context.commitChanges();
+
+        // here Cayenne would throw per CAY-1378 on an attempt to delete a previously
+        // related transient object
+        context.deleteObject(group);
+        context.commitChanges();
+    }
+}



Mime
View raw message