Revision: 9381
Author: [email protected]
Date: Wed Dec  8 12:37:05 2010
Log: Disallow persisted entities with null version properties because it breaks RequestFactory update semantics.
Patch by: bobv
Review by: rjrjr

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

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

Modified:
/trunk/user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java /trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestFactory.java /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
 /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
 /trunk/user/test/com/google/gwt/requestfactory/shared/ComplexKeysTest.java
 /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java

=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java Tue Dec 7 22:33:06 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java Wed Dec 8 12:37:05 2010
@@ -186,7 +186,7 @@
     processOperationMessages(state, message);
     List<Object> decoded = decodeInvocationArguments(state,
         message.getInvocations().get(0).getParameters(),
-        new Class<?>[] {proxyType}, new Type[] {domainClass});
+        new Class<?>[]{proxyType}, new Type[]{domainClass});

     @SuppressWarnings("unchecked")
     List<T> toReturn = (List<T>) decoded;
@@ -273,10 +273,16 @@
       Splittable version = null;
       if (writeOperation == WriteOperation.PERSIST
           || writeOperation == WriteOperation.UPDATE) {
+        /*
+ * If we're sending an operation, the domain object must be persistent.
+         * This means that it must also have a non-null version.
+         */
         Object domainVersion = service.getVersion(domainObject);
-        if (domainVersion != null) {
-          version = returnState.flatten(domainVersion);
-        }
+        if (domainVersion == null) {
+          throw new UnexpectedException("The persisted entity with id "
+              + service.getId(domainObject) + " has a null version", null);
+        }
+        version = returnState.flatten(domainVersion);
       }

       boolean inResponse = bean.getTag(Constants.IN_RESPONSE) != null;
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestFactory.java Wed Nov 24 12:33:58 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequestFactory.java Wed Dec 8 12:37:05 2010
@@ -82,7 +82,7 @@
       protected RequestData makeRequestData() {
         return new RequestData(
             "com.google.gwt.requestfactory.shared.impl.FindRequest::find",
- new Object[] {proxyId}, propertyRefs, proxyId.getProxyClass(), null); + new Object[]{proxyId}, propertyRefs, proxyId.getProxyClass(), null);
       }
     };
   }
@@ -142,6 +142,8 @@
    */
   protected boolean hasVersionChanged(SimpleProxyId<?> id,
       String observedVersion) {
+    assert id != null : "id";
+    assert observedVersion != null : "observedVersion";
     String key = getHistoryToken(id);
     String existingVersion = version.get(key);
     // Return true if we haven't seen this before or the versions differ
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Wed Dec 8 08:24:06 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Wed Dec 8 12:37:05 2010
@@ -1068,6 +1068,27 @@
       }
     });
   }
+
+  /**
+ * Test that the server code will not allow a persisted entity to be returned
+   * if it has a null version property.
+   */
+  public void testPersistedEntityWithNullVersion() {
+    delayTestFinish(DELAY_TEST_FINISH);
+    simpleFooRequest().getSimpleFooWithNullVersion().fire(
+        new Receiver<SimpleFooProxy>() {
+
+          @Override
+          public void onFailure(ServerFailure error) {
+            finishTestAndReset();
+          }
+
+          @Override
+          public void onSuccess(SimpleFooProxy response) {
+            fail();
+          }
+        });
+  }

   public void testPersistExistingEntityExistingRelation() {
     delayTestFinish(DELAY_TEST_FINISH);
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java Wed Dec 8 08:24:06 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java Wed Dec 8 12:37:05 2010
@@ -123,6 +123,16 @@
     list.add(3);
     return list;
   }
+
+  /**
+   * This tests that the server detects and disallows the use of persisted
+   * objects with a null version property.
+   */
+  public static SimpleFoo getSimpleFooWithNullVersion() {
+    SimpleFoo foo = new SimpleFoo();
+    foo.setVersion(null);
+    return foo;
+  }

   public static SimpleFoo getSimpleFooWithSubPropertyCollection() {
     SimpleFoo foo = new SimpleFoo();
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/ComplexKeysTest.java Fri Nov 19 12:33:32 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/ComplexKeysTest.java Wed Dec 8 12:37:05 2010
@@ -67,8 +67,8 @@
       return key;
     }

-    public Void getVersion() {
-      return null;
+    public Integer getVersion() {
+      return 0;
     }
   }

@@ -101,8 +101,8 @@
       return key;
     }

-    public Void getVersion() {
-      return null;
+    public Integer getVersion() {
+      return 0;
     }
   }

@@ -129,8 +129,8 @@
       return key;
     }

-    public Void getVersion() {
-      return null;
+    public Integer getVersion() {
+      return 0;
     }
   }

=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java Thu Dec 2 03:34:25 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleFooRequest.java Wed Dec 8 12:37:05 2010
@@ -49,6 +49,8 @@

   Request<Set<Integer>> getNumberSet();

+  Request<SimpleFooProxy> getSimpleFooWithNullVersion();
+
   Request<SimpleFooProxy> getSimpleFooWithSubPropertyCollection();

   Request<SimpleFooProxy> getTripletReference();

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

Reply via email to