cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r595030 - in /cayenne/main/trunk: docs/doc/src/main/resources/RELEASE-NOTES.txt framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
Date Wed, 14 Nov 2007 20:16:02 GMT
Author: aadamchik
Date: Wed Nov 14 12:15:59 2007
New Revision: 595030

URL: http://svn.apache.org/viewvc?rev=595030&view=rev
Log:
CAY-920 ClassCastException when processing delete rules for Map relationships

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.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=595030&r1=595029&r2=595030&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 Nov 14 12:15:59 2007
@@ -28,6 +28,7 @@
 CAY-899 Default POST_LOAD callbacks break aggregate queries
 CAY-913 ToMany Map relationships cause ClassCastExceptions on commit when the source is Fault
 CAY-914 cdataport classloader trouble
+CAY-920 ClassCastException when processing delete rules for Map relationships
 
 ----------------------------------
 Release: 3.0M2

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java?rev=595030&r1=595029&r2=595030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/DataContextDeleteAction.java
Wed Nov 14 12:15:59 2007
@@ -24,6 +24,7 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DeleteDenyException;
@@ -119,6 +120,24 @@
         object.setObjectContext(null);
     }
 
+    private Collection toCollection(Object object) {
+
+        if (object == null) {
+            return Collections.EMPTY_LIST;
+        }
+
+        // create copies of collections to avoid iterator exceptions
+        if (object instanceof Collection) {
+            return new ArrayList((Collection) object);
+        }
+        else if (object instanceof Map) {
+            return new ArrayList(((Map) object).values());
+        }
+        else {
+            return Collections.singleton(object);
+        }
+    }
+
     private void processDeleteRules(final Persistent object, int oldState)
             throws DeleteDenyException {
 
@@ -130,33 +149,17 @@
             ObjRelationship relationship = (ObjRelationship) it.next();
 
             boolean processFlattened = relationship.isFlattened()
-                    && relationship.isToDependentEntity() && !relationship.isReadOnly();
+                    && relationship.isToDependentEntity()
+                    && !relationship.isReadOnly();
 
             // first check for no action... bail out if no flattened processing is needed
             if (relationship.getDeleteRule() == DeleteRule.NO_ACTION && !processFlattened)
{
                 continue;
             }
 
-            List relatedObjects = Collections.EMPTY_LIST;
-
             ArcProperty property = (ArcProperty) descriptor.getProperty(relationship
                     .getName());
-            Object related = property.readProperty(object);
-
-            if (relationship.isToMany()) {
-
-                List toMany = (List) related;
-                if (toMany.size() > 0) {
-                    // Get a copy of the list so that deleting objects doesn't
-                    // result in concurrent modification exceptions
-                    relatedObjects = new ArrayList(toMany);
-                }
-            }
-            else {
-                if (related != null) {
-                    relatedObjects = Collections.singletonList(related);
-                }
-            }
+            Collection relatedObjects = toCollection(property.readProperty(object));
 
             // no related object, bail out
             if (relatedObjects.size() == 0) {



Mime
View raw message