Revision: 8983
Author: [email protected]
Date: Fri Oct  8 13:01:19 2010
Log: Fix a bug in server code that assumes that the EntityProxy must expose a getId() method.
Patch by: bobv
Review by: rjrjr

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

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

Modified:
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/AddressProxy.java /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/PersonProxy.java /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
 /trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryStringTest.java /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
 /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleBarProxy.java

=======================================
--- /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/AddressProxy.java Tue Sep 21 12:24:16 2010 +++ /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/AddressProxy.java Fri Oct 8 13:01:19 2010
@@ -27,8 +27,6 @@
 public interface AddressProxy extends EntityProxy {
   String getCity();

-  String getId();
-
   String getState();

   String getStreet();
=======================================
--- /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/PersonProxy.java Sun Oct 3 11:35:25 2010 +++ /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/shared/PersonProxy.java Fri Oct 8 13:01:19 2010
@@ -30,8 +30,6 @@

   String getDescription();

-  String getId();
-
   PersonProxy getMentor();

   String getName();
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java Tue Oct 5 14:47:46 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java Fri Oct 8 13:01:19 2010
@@ -440,19 +440,6 @@
       return encodePropertyValue(returnValue);
     }
   }
-
-  /**
- * Generate an ID for a new record. The default behavior is to return null and
-   * let the data store generate the ID automatically.
-   *
-   * @param key the key of the record field
-   * @return the ID of the new record, or null to auto generate
-   */
-  public String generateIdForCreate(String key) {
-    // TODO(rjrjr) is there any point to this method if a service layer
-    // is coming?
-    return null;
-  }

   /**
* Find the entity in the server data store, apply its setters, capture any
@@ -476,28 +463,19 @@
     validateKeys(recordObject, propertiesInDomain.keySet());

     // get entityInstance
-    Object entityInstance = getEntityInstance(
-        writeOperation,
-        entityType,
- entityKey.decodedId(propertiesInProxy.get(Constants.ENTITY_ID_PROPERTY).getType()),
-        propertiesInProxy.get(Constants.ENTITY_ID_PROPERTY).getType());
-
+    Class<?> idType = getIdMethodForEntity(entityType).getReturnType();
+    Object entityInstance = getEntityInstance(writeOperation, entityType,
+        entityKey.decodedId(idType), idType);
     cachedEntityLookup.put(entityKey, entityInstance);

     Iterator<?> keys = recordObject.keys();
     while (keys.hasNext()) {
       String key = (String) keys.next();
-      Class<?> propertyType = propertiesInDomain.get(key);
       Property<?> dtoProperty = propertiesInProxy.get(key);
       if (writeOperation == WriteOperation.PERSIST
           && (Constants.ENTITY_ID_PROPERTY.equals(key))) {
-        String id = generateIdForCreate(key);
-        if (id != null) {
-          // TODO(rjrjr) generateIdForCreate returns null. Has this ever
-          // execute
-          entityType.getMethod(getMethodNameFromPropertyName(key, "set"),
-              propertyType).invoke(entityInstance, id);
-        }
+        // Don't allow the client to attempt to set the id
+        continue;
       } else {
         Object propertyValue = null;
         if (recordObject.isNull(key)) {
@@ -641,8 +619,10 @@
     for (Property<?> p : allProperties(entityKeyClass)) {
       if (requestedProperty(p, propertyContext)) {
         String propertyName = p.getName();
-        jsonObject.put(propertyName, encodePropertyValueFromDataStore(
-            entityElement, p, propertyName, propertyContext));
+        jsonObject.put(
+            propertyName,
+ encodePropertyValueFromDataStore(entityElement, p, propertyName,
+                propertyContext));
       }
     }
     return jsonObject;
@@ -1087,7 +1067,7 @@
      * will protected against ConcurrentModificationExceptions.
      */
     afterDvsDataMap = new HashMap<EntityKey, EntityData>();
-    Set<EntityKey> done = new HashSet<EntityKey>();
+    Set<EntityKey> done = new HashSet<EntityKey>();
     Set<EntityKey> queue = new HashSet<EntityKey>(involvedKeys);
     while (!queue.isEmpty()) {
       for (EntityKey entityKey : queue) {
@@ -1109,11 +1089,10 @@
            * unedited, existing object.
            */
           SerializedEntity serializedEntity = beforeDataMap.get(entityKey);
-          Object entityInstance = (serializedEntity == null) ?
- getEntityInstance(entityKey) : serializedEntity.entityInstance;
+          Object entityInstance = (serializedEntity == null)
+ ? getEntityInstance(entityKey) : serializedEntity.entityInstance;
           if (entityInstance != null) {
-            afterDvsDataMap.put(entityKey, new EntityData(entityInstance,
-                null));
+ afterDvsDataMap.put(entityKey, new EntityData(entityInstance, null));
           }
         }
       }
@@ -1267,7 +1246,8 @@
       IllegalAccessException, InvocationTargetException {
     JSONObject jsonObject = new JSONObject();
     jsonObject.put(Constants.ENCODED_ID_PROPERTY, encodedId);
-    jsonObject.put(Constants.ENCODED_VERSION_PROPERTY,
+    jsonObject.put(
+        Constants.ENCODED_VERSION_PROPERTY,
         encodePropertyValueFromDataStore(entityElement,
             Constants.ENTITY_VERSION_PROPERTY,
             Constants.ENTITY_VERSION_PROPERTY.getName(), propertyContext));
@@ -1431,11 +1411,11 @@
         if (entityKey.isFuture) {
           returnObject.put(Constants.ENCODED_FUTUREID_PROPERTY,
               entityKey.encodedId);
-          returnObject.put(Constants.ENCODED_ID_PROPERTY, getSchemaAndId(
-              entityKey.proxyType, null));
+          returnObject.put(Constants.ENCODED_ID_PROPERTY,
+              getSchemaAndId(entityKey.proxyType, null));
         } else {
-          returnObject.put(Constants.ENCODED_ID_PROPERTY, getSchemaAndId(
-              entityKey.proxyType, entityKey.encodedId));
+          returnObject.put(Constants.ENCODED_ID_PROPERTY,
+              getSchemaAndId(entityKey.proxyType, entityKey.encodedId));
         }
         violations.put(returnObject);
       }
@@ -1448,8 +1428,9 @@
       SecurityException, IllegalAccessException, InvocationTargetException,
       NoSuchMethodException, JSONException, InstantiationException {
     SerializedEntity beforeEntity = beforeDataMap.get(entityKey);
-    if (beforeEntity != null && hasChanged(beforeEntity.serializedEntity,
-        serializeEntity(entityInstanceAfterOperation, entityKey))) {
+    if (beforeEntity != null
+        && hasChanged(beforeEntity.serializedEntity,
+            serializeEntity(entityInstanceAfterOperation, entityKey))) {
       return true;
     }
     return false;
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java Fri Oct 1 18:15:55 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/FindServiceTest.java Fri Oct 8 13:01:19 2010
@@ -133,7 +133,6 @@
               @Override
               public void onSuccess(SimpleBarProxy returnedProxy) {
                 assertEquals(stableId, returnedProxy.stableId());
-                assertEquals("999L", returnedProxy.getId());
                 finishTestAndReset();
               }
             });
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryStringTest.java Mon Oct 4 15:35:00 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryStringTest.java Fri Oct 8 13:01:19 2010
@@ -148,16 +148,11 @@

     SimpleBarRequest context = req.simpleBarRequest();
     final SimpleBarProxy foo = context.create(SimpleBarProxy.class);
-    Object futureId = foo.getId();
-    assertEquals(futureId, foo.getId());
Request<SimpleBarProxy> fooReq = context.persistAndReturnSelf().using(foo);
     fooReq.fire(new Receiver<SimpleBarProxy>() {

       @Override
       public void onSuccess(final SimpleBarProxy returned) {
-        Object futureId = foo.getId();
-        assertEquals(futureId, foo.getId());
-
         checkStableIdEquals(foo, returned);
         finishTestAndReset();
       }
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Tue Oct 5 09:11:00 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Fri Oct 8 13:01:19 2010
@@ -456,16 +456,12 @@

     SimpleBarRequest context = simpleBarRequest();
     final SimpleBarProxy foo = context.create(SimpleBarProxy.class);
-    Object futureId = foo.getId();
-    assertEquals(futureId, foo.getId());
     assertTrue(((SimpleEntityProxyId<?>) foo.stableId()).isEphemeral());
Request<SimpleBarProxy> fooReq = context.persistAndReturnSelf().using(foo);
     fooReq.fire(new Receiver<SimpleBarProxy>() {

       @Override
       public void onSuccess(final SimpleBarProxy returned) {
-        Object futureId = foo.getId();
-        assertEquals(futureId, foo.getId());
assertFalse(((SimpleEntityProxyId<?>) foo.stableId()).isEphemeral());

         checkStableIdEquals(foo, returned);
@@ -479,16 +475,12 @@

     SimpleBarRequest context = simpleBarRequest();
     final SimpleBarProxy bar = context.create(SimpleBarProxy.class);
-    Object futureId = bar.getId();
-    assertEquals(futureId, bar.getId());
     assertTrue(((SimpleEntityProxyId<?>) bar.stableId()).isEphemeral());
Request<SimpleBarProxy> fooReq = context.returnFirst(Collections.singletonList(bar));
     fooReq.fire(new Receiver<SimpleBarProxy>() {

       @Override
       public void onSuccess(final SimpleBarProxy returned) {
-        Object futureId = bar.getId();
-        assertEquals(futureId, bar.getId());
assertFalse(((SimpleEntityProxyId<?>) bar.stableId()).isEphemeral()); assertFalse(((SimpleEntityProxyId<?>) returned.stableId()).isEphemeral());

=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleBarProxy.java Fri Sep 24 12:10:50 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleBarProxy.java Fri Oct 8 13:01:19 2010
@@ -25,7 +25,10 @@
 public interface SimpleBarProxy extends EntityProxy {
   Boolean getFindFails();

-  String getId();
+  /*
+ * NB: The lack of a getId() here is intentional, to ensure that the system
+   * does not assume that the id property is available to the client.
+   */

   String getUserName();

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

Reply via email to