Revision: 9373
Author: [email protected]
Date: Tue Dec  7 13:58:29 2010
Log: Integrate r9372 into GWT 2.1 branch.
Suppress redundant PERSIST updates.

http://code.google.com/p/google-web-toolkit/source/detail?r=9373

Modified:
/releases/2.1/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestContext.java /releases/2.1/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java

=======================================
--- /releases/2.1/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestContext.java Thu Dec 2 03:55:49 2010 +++ /releases/2.1/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestContext.java Tue Dec 7 13:58:29 2010
@@ -114,7 +114,7 @@
   }

   private static final String PARENT_OBJECT = "parentObject";
-
+ private final Set<SimpleProxyId<?>> createdIds = new HashSet<SimpleProxyId<?>>(); private final List<AbstractRequest<?>> invocations = new ArrayList<AbstractRequest<?>>();
   private boolean locked;
   private final AbstractRequestFactory requestFactory;
@@ -148,8 +148,9 @@
   public <T extends BaseProxy> T create(Class<T> clazz) {
     checkLocked();

-    AutoBean<T> created = requestFactory.createProxy(clazz,
-        requestFactory.allocateId(clazz));
+    SimpleProxyId<T> id = requestFactory.allocateId(clazz);
+    createdIds.add(id);
+    AutoBean<T> created = requestFactory.createProxy(clazz, id);
     return takeOwnership(created);
   }

@@ -791,7 +792,8 @@
       SimpleProxyId<?> id = getId(op);
       if (id.isEphemeral()) {
         processReturnOperation(id, op);
-      } else if (id.wasEphemeral()) {
+      } else if (id.wasEphemeral() && createdIds.contains(id)) {
+        // Only send a PERSIST if this RequestContext created the id.
         processReturnOperation(id, op, WriteOperation.PERSIST,
             WriteOperation.UPDATE);
       } else {
=======================================
--- /releases/2.1/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java Wed Nov 24 06:41:26 2010 +++ /releases/2.1/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java Tue Dec 7 13:58:29 2010
@@ -23,6 +23,7 @@
 import com.google.gwt.requestfactory.shared.SimpleBarProxy;
 import com.google.gwt.requestfactory.shared.SimpleBarRequest;
 import com.google.gwt.requestfactory.shared.SimpleFooProxy;
+import com.google.gwt.requestfactory.shared.SimpleFooRequest;
 import com.google.gwt.requestfactory.shared.SimpleRequestFactory;

 /**
@@ -137,6 +138,37 @@
           }
         });
   }
+
+  public void testFetchsAfterCreateDontUpdate() {
+    final int[] count = {0};
+ final HandlerRegistration registration = EntityProxyChange.registerForProxyType(
+        req.getEventBus(), SimpleFooProxy.class,
+        new EntityProxyChange.Handler<SimpleFooProxy>() {
+ public void onProxyChange(EntityProxyChange<SimpleFooProxy> event) {
+            count[0]++;
+          }
+        });
+    delayTestFinish(TEST_DELAY);
+    SimpleFooRequest context = req.simpleFooRequest();
+    SimpleFooProxy proxy = context.create(SimpleFooProxy.class);
+    context.persistAndReturnSelf().using(proxy).fire(
+        new Receiver<SimpleFooProxy>() {
+          @Override
+          public void onSuccess(SimpleFooProxy response) {
+            // Persist and Update events
+            assertEquals(2, count[0]);
+ req.find(response.stableId()).fire(new Receiver<SimpleFooProxy>() {
+              @Override
+              public void onSuccess(SimpleFooProxy response) {
+                // No new events
+                assertEquals(2, count[0]);
+                registration.removeHandler();
+                finishTestAndReset();
+              }
+            });
+          }
+        });
+  }

   /**
    * Demonstrates behavior when fetching an unpersisted id. The setup is

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to