cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1530540 - /cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java
Date Wed, 09 Oct 2013 09:14:02 GMT
Author: dkazimirchyk
Date: Wed Oct  9 09:14:02 2013
New Revision: 1530540

URL: http://svn.apache.org/r1530540
Log:
CAY-1798 ROP: Reverse relationships of prefetched entity objects are not filled during server
to client objects conversion.

Modified:
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java?rev=1530540&r1=1530539&r2=1530540&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/ObjectDetachOperation.java
Wed Oct  9 09:14:02 2013
@@ -30,6 +30,7 @@ import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.PrefetchTreeNode;
+import org.apache.cayenne.reflect.ArcProperty;
 import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyDescriptor;
@@ -98,6 +99,20 @@ public class ObjectDetachOperation {
 
         descriptor.visitProperties(new PropertyVisitor() {
 
+        	private void fillReverseRelationship(Object destinationTarget, ArcProperty property)
{
+				ArcProperty reverseProperty = property.getComplimentaryReverseArc();
+
+				if (reverseProperty != null && reverseProperty instanceof ToOneProperty) {
+
+					ClassDescriptor desc = targetResolver.getClassDescriptor(
+							reverseProperty.getRelationship().getSourceEntity().getName());
+
+					ToOneProperty targetReverseProperty =
+							(ToOneProperty) desc.getProperty(reverseProperty.getName());
+					targetReverseProperty.writeProperty(destinationTarget, null, target);
+				}
+        	}
+
             public boolean visitToOne(ToOneProperty property) {
                 if (prefetchTree != null) {
 
@@ -110,6 +125,10 @@ public class ObjectDetachOperation {
                                 destinationSource,
                                 property.getTargetDescriptor(),
                                 child) : null;
+                                
+                        if (destinationTarget != null) {
+                            fillReverseRelationship(destinationTarget, property);
+                        }
 
                         ToOneProperty targetProperty = (ToOneProperty) targetDescriptor
                                 .getProperty(property.getName());
@@ -142,6 +161,10 @@ public class ObjectDetachOperation {
                                     ? detach(destinationSource, property
                                         .getTargetDescriptor(), child)
                                         : null;
+                                
+                                if (destinationTarget != null) {
+                                    fillReverseRelationship(destinationTarget, property);
+                                }
 
                                 targetMap.put(entry.getKey(), destinationTarget);
                             }
@@ -156,7 +179,11 @@ public class ObjectDetachOperation {
                                         ? detach(destinationSource, property
                                                 .getTargetDescriptor(), child)
                                         : null;
-    
+                                        
+                                if (destinationTarget != null) {
+                                  	fillReverseRelationship(destinationTarget, property);
+                                }
+                                
                                 targetCollection.add(destinationTarget);
                             }
                             targetValue = targetCollection;



Mime
View raw message