You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/01/21 22:16:15 UTC

svn commit: r1234420 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java

Author: aadamchik
Date: Sat Jan 21 21:16:15 2012
New Revision: 1234420

URL: http://svn.apache.org/viewvc?rev=1234420&view=rev
Log:
CAY-1616 Remove internal dependencies on deprecated ObjectContext.localObject

refactoring

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java?rev=1234420&r1=1234419&r2=1234420&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java Sat Jan 21 21:16:15 2012
@@ -46,8 +46,8 @@ import org.apache.cayenne.reflect.ToOneP
  */
 public class DeepMergeOperation {
 
-    private Map<ObjectId, Persistent> seen;
-    private ShallowMergeOperation shallowMergeOperation;
+    private final Map<ObjectId, Persistent> seen;
+    private final ShallowMergeOperation shallowMergeOperation;
 
     public DeepMergeOperation(ObjectContext context) {
         this.seen = new HashMap<ObjectId, Persistent>();
@@ -58,18 +58,25 @@ public class DeepMergeOperation {
         seen.clear();
     }
 
+    /**
+     * @deprecated since 3.1 use {@link #merge(Persistent, ClassDescriptor)}.
+     */
     public Object merge(Object object, ClassDescriptor descriptor) {
         if (!(object instanceof Persistent)) {
             throw new CayenneRuntimeException("Expected Persistent, got: " + object);
         }
 
-        final Persistent source = (Persistent) object;
-        ObjectId id = source.getObjectId();
+        return merge((Persistent) object, descriptor);
+    }
+
+    public Object merge(final Persistent peerInParentContext, ClassDescriptor descriptor) {
+
+        ObjectId id = peerInParentContext.getObjectId();
 
         // sanity check
         if (id == null) {
             throw new CayenneRuntimeException("Server returned an object without an id: "
-                    + source);
+                    + peerInParentContext);
         }
 
         Object seenTarget = seen.get(id);
@@ -77,16 +84,17 @@ public class DeepMergeOperation {
             return seenTarget;
         }
 
-        final Persistent target = shallowMergeOperation.merge(source);
+        final Persistent target = shallowMergeOperation.merge(peerInParentContext);
         seen.put(id, target);
 
-        descriptor = descriptor.getSubclassDescriptor(source.getClass());
+        descriptor = descriptor.getSubclassDescriptor(peerInParentContext.getClass());
         descriptor.visitProperties(new PropertyVisitor() {
 
             public boolean visitToOne(ToOneProperty property) {
 
-                if (!property.isFault(source)) {
-                    Object destinationSource = property.readProperty(source);
+                if (!property.isFault(peerInParentContext)) {
+                    Persistent destinationSource = (Persistent) property
+                            .readProperty(peerInParentContext);
 
                     Object destinationTarget = destinationSource != null ? merge(
                             destinationSource,
@@ -101,8 +109,8 @@ public class DeepMergeOperation {
             }
 
             public boolean visitToMany(ToManyProperty property) {
-                if (!property.isFault(source)) {
-                    Object value = property.readProperty(source);
+                if (!property.isFault(peerInParentContext)) {
+                    Object value = property.readProperty(peerInParentContext);
                     Object targetValue;
 
                     if (property instanceof ToManyMapProperty) {
@@ -112,7 +120,7 @@ public class DeepMergeOperation {
                         for (Entry entry : map.entrySet()) {
                             Object destinationSource = entry.getValue();
                             Object destinationTarget = destinationSource != null ? merge(
-                                    destinationSource,
+                                    (Persistent) destinationSource,
                                     property.getTargetDescriptor()) : null;
 
                             targetMap.put(entry.getKey(), destinationTarget);
@@ -125,7 +133,7 @@ public class DeepMergeOperation {
 
                         for (Object destinationSource : collection) {
                             Object destinationTarget = destinationSource != null ? merge(
-                                    destinationSource,
+                                    (Persistent) destinationSource,
                                     property.getTargetDescriptor()) : null;
 
                             targetCollection.add(destinationTarget);