Reviewers: bobv, rjrjr,

Description:
Copied from the issue tracker:

The real issue seems to be in how
com.google.gwt.requestfactory.client.impl.RequestFactoryEditorDelegate
determines whether it shouldFlush() or not: it only deals with "am I in
'read-only' mode or not" (if request==null, edited proxies cannot have
been made mutable, so we're in the "display" case). It looks to me like
it should also check whether 'request' is "locked" (which can only be
done if 'request' is an AbstractRequestContext –it should be, unless
someone gave his own implementation, in which case he would have to
handle the case himself–, so we can use
AbstractRequestContext#isLocked()).

FYI: the tests run fine in isolation in Eclipse, but if I run the whole
EditorTest class, sometimes testReuse() makes test() fail; I suspect
this has to do with the implementation of SimpleFoo service methods; and
trying to run the tests through Ant fails when compiling the tests (not
finding the jsr303 TCK classes).
However, because the tests run fine in isolation, I believe this fixes
the issue with ListEditor. One possible "fix" for my issues launching
the tests would be to merge test() and testReuse()...

Please review this at http://gwt-code-reviews.appspot.com/1284801/show

Affected files:
user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java
  user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java


Index: user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java
===================================================================
--- user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java (revision 9528) +++ user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java (working copy)
@@ -28,6 +28,7 @@
 import com.google.gwt.requestfactory.shared.RequestContext;
 import com.google.gwt.requestfactory.shared.RequestFactory;
 import com.google.gwt.requestfactory.shared.WriteOperation;
+import com.google.gwt.requestfactory.shared.impl.AbstractRequestContext;

 import java.util.ArrayList;
 import java.util.List;
@@ -136,6 +137,9 @@

   @Override
   protected boolean shouldFlush() {
+    if (request instanceof AbstractRequestContext) {
+      return !((AbstractRequestContext) request).isLocked();
+    }
     return request != null;
   }
 }
Index: user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java
===================================================================
--- user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java (revision 9528) +++ user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java (working copy)
@@ -263,4 +263,39 @@
           }
         });
   }
+
+  /**
+ * Tests the editor can be re-used while the initial context is locked and
+   * therefore its attached proxies are frozen..
+   *
+   * @see http://code.google.com/p/google-web-toolkit/issues/detail?id=5752
+   */
+  public void testReuse() {
+    delayTestFinish(TEST_TIMEOUT);
+    final SimpleFooEditor editor = new SimpleFooEditor();
+
+    final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
+    driver.initialize(req, editor);
+
+ req.simpleFooRequest().findSimpleFooById(1L).with(driver.getPaths()).fire(
+        new Receiver<SimpleFooProxy>() {
+          @Override
+          public void onSuccess(SimpleFooProxy response) {
+
+            SimpleFooRequest context = req.simpleFooRequest();
+            driver.edit(response, context);
+            context.persistAndReturnSelf().using(response).with(
+                driver.getPaths()).to(new Receiver<SimpleFooProxy>() {
+              @Override
+              public void onSuccess(SimpleFooProxy response) {
+                // just testing that it doesn't throw (see issue 5752)
+                driver.edit(response, req.simpleFooRequest());
+                finishTestAndReset();
+              }
+            });
+            // The fire() will freeze the proxies and lock the context
+            driver.flush().fire();
+          }
+        });
+  }
 }


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

Reply via email to