cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1234421 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/remote/ main/java/org/apache/cayenne/util/ test/java/org/apache/cayenne/util/
Date Sat, 21 Jan 2012 21:16:54 GMT
Author: aadamchik
Date: Sat Jan 21 21:16:54 2012
New Revision: 1234421

URL: http://svn.apache.org/viewvc?rev=1234421&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/remote/ClientChannel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java?rev=1234421&r1=1234420&r2=1234421&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java
Sat Jan 21 21:16:54 2012
@@ -41,7 +41,6 @@ import org.apache.cayenne.map.EntityReso
 import org.apache.cayenne.query.EntityResultSegment;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
-import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.util.DeepMergeOperation;
 import org.apache.cayenne.util.ToStringBuilder;
 
@@ -230,11 +229,7 @@ public class ClientChannel implements Da
                     + object);
         }
 
-        // have to resolve descriptor here for every object, as often a query will not
-        // have any info indicating the entity type
-        ClassDescriptor descriptor = resolver.getClassDescriptor(id.getEntityName());
-
-        return merger.merge(object, descriptor);
+        return merger.merge(object);
     }
 
     public GraphDiff onSync(

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=1234421&r1=1234420&r2=1234421&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:54 2012
@@ -29,6 +29,7 @@ import org.apache.cayenne.CayenneRuntime
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyVisitor;
@@ -46,30 +47,43 @@ import org.apache.cayenne.reflect.ToOneP
  */
 public class DeepMergeOperation {
 
-    private final Map<ObjectId, Persistent> seen;
+    private final EntityResolver entityResolver;
     private final ShallowMergeOperation shallowMergeOperation;
 
     public DeepMergeOperation(ObjectContext context) {
-        this.seen = new HashMap<ObjectId, Persistent>();
+        this.entityResolver = context.getEntityResolver();
         this.shallowMergeOperation = new ShallowMergeOperation(context);
     }
 
+    /**
+     * @deprecated since 3.1 - unused as the object is now stateless
+     */
     public void reset() {
-        seen.clear();
+        // noop
     }
 
     /**
-     * @deprecated since 3.1 use {@link #merge(Persistent, ClassDescriptor)}.
+     * @deprecated since 3.1 use {@link #merge(Persistent)}.
      */
     public Object merge(Object object, ClassDescriptor descriptor) {
+
         if (!(object instanceof Persistent)) {
             throw new CayenneRuntimeException("Expected Persistent, got: " + object);
         }
 
-        return merge((Persistent) object, descriptor);
+        return merge((Persistent) object);
+    }
+
+    public Object merge(final Persistent peerInParentContext) {
+        ClassDescriptor descriptor = entityResolver
+                .getClassDescriptor(peerInParentContext.getObjectId().getEntityName());
+        return merge(peerInParentContext, descriptor, new HashMap<ObjectId, Persistent>());
     }
 
-    public Object merge(final Persistent peerInParentContext, ClassDescriptor descriptor)
{
+    private Object merge(
+            final Persistent peerInParentContext,
+            ClassDescriptor descriptor,
+            final Map<ObjectId, Persistent> seen) {
 
         ObjectId id = peerInParentContext.getObjectId();
 
@@ -98,7 +112,8 @@ public class DeepMergeOperation {
 
                     Object destinationTarget = destinationSource != null ? merge(
                             destinationSource,
-                            property.getTargetDescriptor()) : null;
+                            property.getTargetDescriptor(),
+                            seen) : null;
 
                     Object oldTarget = property.isFault(target) ? null : property
                             .readProperty(target);
@@ -121,7 +136,8 @@ public class DeepMergeOperation {
                             Object destinationSource = entry.getValue();
                             Object destinationTarget = destinationSource != null ? merge(
                                     (Persistent) destinationSource,
-                                    property.getTargetDescriptor()) : null;
+                                    property.getTargetDescriptor(),
+                                    seen) : null;
 
                             targetMap.put(entry.getKey(), destinationTarget);
                         }
@@ -134,7 +150,8 @@ public class DeepMergeOperation {
                         for (Object destinationSource : collection) {
                             Object destinationTarget = destinationSource != null ? merge(
                                     (Persistent) destinationSource,
-                                    property.getTargetDescriptor()) : null;
+                                    property.getTargetDescriptor(),
+                                    seen) : null;
 
                             targetCollection.add(destinationTarget);
                         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java?rev=1234421&r1=1234420&r2=1234421&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceTest.java
Sat Jan 21 21:16:54 2012
@@ -22,9 +22,7 @@ package org.apache.cayenne.util;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.testdo.inherit.Department;
 import org.apache.cayenne.testdo.inherit.Employee;
 import org.apache.cayenne.testdo.inherit.Manager;
@@ -37,9 +35,6 @@ import org.apache.cayenne.unit.di.server
 public class DeepMergeOperationInheritanceTest extends ServerCase {
 
     @Inject
-    private EntityResolver resolver;
-
-    @Inject
     private DataContext context;
 
     @Inject
@@ -50,8 +45,6 @@ public class DeepMergeOperationInheritan
 
     public void testDeepMergeExistingSubclass() {
 
-        final ClassDescriptor d = resolver.getClassDescriptor("Department");
-
         final Department d1 = context.newObject(Department.class);
         d1.setName("D1");
 
@@ -83,7 +76,7 @@ public class DeepMergeOperationInheritan
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
             public void execute() {
-                Department d2 = (Department) op.merge(d1, d);
+                Department d2 = (Department) op.merge(d1);
                 assertNotNull(d2);
                 assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
 
@@ -102,8 +95,6 @@ public class DeepMergeOperationInheritan
 
     public void testDeepMergeNonExistentSubclass() {
 
-        final ClassDescriptor d = resolver.getClassDescriptor("Department");
-
         final Department d1 = context.newObject(Department.class);
         d1.setName("D1");
 
@@ -131,7 +122,7 @@ public class DeepMergeOperationInheritan
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
             public void execute() {
-                Department d2 = (Department) op.merge(d1, d);
+                Department d2 = (Department) op.merge(d1);
                 assertNotNull(d2);
                 assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationTest.java?rev=1234421&r1=1234420&r2=1234421&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/DeepMergeOperationTest.java
Sat Jan 21 21:16:54 2012
@@ -22,23 +22,17 @@ package org.apache.cayenne.util;
 import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.DeepMergeOperation;
 
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class DeepMergeOperationTest extends ServerCase {
 
     @Inject
-    private ServerRuntime runtime;
-
-    @Inject
     private DataChannelInterceptor queryInterceptor;
 
     @Inject
@@ -49,11 +43,6 @@ public class DeepMergeOperationTest exte
 
     public void testDeepMergeNonExistent() {
 
-        final ClassDescriptor d = runtime
-                .getDataDomain()
-                .getEntityResolver()
-                .getClassDescriptor("Artist");
-
         final Artist a = context.newObject(Artist.class);
         a.setArtistName("AAA");
         context.commitChanges();
@@ -63,7 +52,7 @@ public class DeepMergeOperationTest exte
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
             public void execute() {
-                Artist a2 = (Artist) op.merge(a, d);
+                Artist a2 = (Artist) op.merge(a);
                 assertNotNull(a2);
                 assertEquals(PersistenceState.COMMITTED, a2.getPersistenceState());
                 assertEquals(a.getArtistName(), a2.getArtistName());
@@ -73,11 +62,6 @@ public class DeepMergeOperationTest exte
 
     public void testDeepMergeModified() {
 
-        final ClassDescriptor d = runtime
-                .getDataDomain()
-                .getEntityResolver()
-                .getClassDescriptor("Artist");
-
         final Artist a = context.newObject(Artist.class);
         a.setArtistName("AAA");
         context.commitChanges();
@@ -89,7 +73,7 @@ public class DeepMergeOperationTest exte
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
 
             public void execute() {
-                Artist a2 = (Artist) op.merge(a, d);
+                Artist a2 = (Artist) op.merge(a);
                 assertNotNull(a2);
                 assertEquals(PersistenceState.MODIFIED, a2.getPersistenceState());
                 assertSame(a1, a2);



Mime
View raw message