Revision: 9024
Author: [email protected]
Date: Mon Oct 11 07:24:43 2010
Log: Ensure that EntityProxy instances returned from Collections returned from an editable EntityProxy are editable.
Patch by: bobv
Review by: rjrjr
Found by: pjulien

Review at http://gwt-code-reviews.appspot.com/976801

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

Modified:
/trunk/user/src/com/google/gwt/requestfactory/client/impl/EntityProxyCategory.java /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java

=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/EntityProxyCategory.java Fri Oct 1 18:15:55 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/EntityProxyCategory.java Mon Oct 11 07:24:43 2010
@@ -49,8 +49,7 @@
     return stableId(bean).hashCode();
   }

-  public static AbstractRequestContext requestContext(
-      AutoBean<? extends EntityProxy> bean) {
+  public static AbstractRequestContext requestContext(AutoBean<?> bean) {
     return (AbstractRequestContext) bean.getTag(REQUEST_CONTEXT);
   }

@@ -70,13 +69,11 @@
    * EntityProxy, that its return values are mutable.
    */
   // CHECKSTYLE_OFF
-  public static <T> T __intercept(AutoBean<? extends EntityProxy> bean,
-      T returnValue) {
+  public static <T> T __intercept(AutoBean<?> bean, T returnValue) {
     // CHECKSTYLE_ON
-    if (!(returnValue instanceof EntityProxy)) {
-      return returnValue;
-    }
+
     AbstractRequestContext context = requestContext(bean);
+
     /*
      * The context will be null if the bean is immutable. If the context is
      * locked, don't try to edit.
@@ -85,8 +82,26 @@
       return returnValue;
     }

-    @SuppressWarnings("unchecked")
-    T toReturn = (T) context.edit((EntityProxy) returnValue);
-    return toReturn;
+    /*
+ * EntityProxies need to be recorded specially by the RequestContext, so
+     * delegate to the edit() method for wiring up the context.
+     */
+    if (returnValue instanceof EntityProxy) {
+      @SuppressWarnings("unchecked")
+      T toReturn = (T) context.edit((EntityProxy) returnValue);
+      return toReturn;
+    }
+
+    /*
+     * We're returning some object that's not an EntityProxy, most likely a
+ * Collection type. At the very least, propagate the current RequestContext
+     * so that editable chains can be constructed.
+     */
+    AutoBean<T> otherBean = AutoBeanUtils.getAutoBean(returnValue);
+    if (otherBean != null) {
+      otherBean.setTag(EntityProxyCategory.REQUEST_CONTEXT,
+          bean.getTag(EntityProxyCategory.REQUEST_CONTEXT));
+    }
+    return returnValue;
   }
 }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Fri Oct 8 13:01:19 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Mon Oct 11 07:24:43 2010
@@ -1762,6 +1762,10 @@
       @Override
       public void onSuccess(SimpleFooProxy response) {
         assertEquals(2, response.getOneToManyField().size());
+
+ // Check lists of proxies returned from a mutable object are mutable
+        response = simpleFooRequest().edit(response);
+        response.getOneToManyField().get(0).setUserName("canMutate");
         finishTestAndReset();
       }
     });

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

Reply via email to