Revision: 8932
Author: [email protected]
Date: Mon Oct 4 18:41:57 2010
Log: Fixed the serialization bug that the version numbers were not being
sent back
on an update (which impacts the event firing). Fixed the test and test
harness
(SimpleBar, SimpleFoo, SimpleFooString). The tests were only passing purely
due
to luck -- the serialization bug masked the test harness bug.
Patch by: amitmanjhi
Review by: robertvawter
Review at http://gwt-code-reviews.appspot.com/930802
http://code.google.com/p/google-web-toolkit/source/detail?r=8932
Modified:
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.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/server/JsonRequestProcessorTest.java
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleBar.java
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleFooString.java
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Sat Oct 2 12:01:57 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Mon Oct 4 18:41:57 2010
@@ -618,19 +618,15 @@
Class<? extends EntityProxy> entityKeyClass,
RequestProperty propertyContext) throws JSONException,
NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
- JSONObject jsonObject = new JSONObject();
if (entityElement == null
|| !EntityProxy.class.isAssignableFrom(entityKeyClass)) {
// JSONObject.NULL isn't a JSONObject
return JSONObject.NULL;
}
-
- jsonObject.put(Constants.ENCODED_ID_PROPERTY, isEntityReference(
- entityElement, entityKeyClass));
- jsonObject.put(Constants.ENCODED_VERSION_PROPERTY,
- encodePropertyValueFromDataStore(entityElement,
- Constants.ENTITY_VERSION_PROPERTY,
- Constants.ENTITY_VERSION_PROPERTY.getName(), propertyContext));
+ JSONObject jsonObject = getJsonObjectWithIdAndVersion(
+ isEntityReference(entityElement, entityKeyClass), entityElement,
+ propertyContext);
+
for (Property<?> p : allProperties(entityKeyClass)) {
if (requestedProperty(p, propertyContext)) {
String propertyName = p.getName();
@@ -1235,10 +1231,6 @@
assert originalEntityKey.isFuture;
Object entityInstance = entityData.entityInstance;
assert entityInstance != null;
- JSONObject returnObject = new JSONObject();
- returnObject.put(Constants.ENCODED_FUTUREID_PROPERTY,
- originalEntityKey.encodedId + "");
- // violations have already been taken care of.
Object newId = getRawPropertyValueFromDatastore(entityInstance,
Constants.ENTITY_ID_PROPERTY);
if (newId == null) {
@@ -1248,12 +1240,12 @@
}
newId = encodeId(newId);
- returnObject.put(Constants.ENCODED_ID_PROPERTY, getSchemaAndId(
- originalEntityKey.proxyType, newId));
- returnObject.put(Constants.ENCODED_VERSION_PROPERTY,
- encodePropertyValueFromDataStore(entityInstance,
- Constants.ENTITY_VERSION_PROPERTY,
- Constants.ENTITY_VERSION_PROPERTY.getName(), propertyRefs));
+ JSONObject returnObject = getJsonObjectWithIdAndVersion(
+ getSchemaAndId(originalEntityKey.proxyType, newId), entityInstance,
+ propertyRefs);
+ // violations have already been taken care of.
+ returnObject.put(Constants.ENCODED_FUTUREID_PROPERTY,
+ originalEntityKey.encodedId + "");
return returnObject;
}
@@ -1277,29 +1269,17 @@
return idMethod;
}
- private Object getPropertyValueFromRequestCached(JSONObject recordObject,
- Map<String, Property<?>> propertiesInProxy, String key,
- Property<?> dtoProperty) throws JSONException,
IllegalAccessException,
- InvocationTargetException, NoSuchMethodException,
InstantiationException {
- Object propertyValue;
- if (!recordObject.isNull(key)
- && EntityProxy.class.isAssignableFrom(dtoProperty.getType())) {
- // if the property type is a Proxy, we expect an encoded Key string
- EntityKey propKey = getEntityKey(recordObject.getString(key));
- // check to see if we've already decoded this object from JSON
- Object cacheValue = cachedEntityLookup.get(propKey);
- // containsKey is used here because an entity lookup can return null
- if (cachedEntityLookup.containsKey(propKey)) {
- propertyValue = cacheValue;
- } else {
- propertyValue = getPropertyValueFromRequest(recordObject, key,
- propertiesInProxy.get(key).getType());
- }
- } else {
- propertyValue = getPropertyValueFromRequest(recordObject, key,
- propertiesInProxy.get(key).getType());
- }
- return propertyValue;
+ private JSONObject getJsonObjectWithIdAndVersion(String encodedId,
+ Object entityElement, RequestProperty propertyContext)
+ throws JSONException, SecurityException, NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put(Constants.ENCODED_ID_PROPERTY, encodedId);
+ jsonObject.put(Constants.ENCODED_VERSION_PROPERTY,
+ encodePropertyValueFromDataStore(entityElement,
+ Constants.ENTITY_VERSION_PROPERTY,
+ Constants.ENTITY_VERSION_PROPERTY.getName(), propertyContext));
+ return jsonObject;
}
private Object getPropertyValueFromRequestCached(JSONArray recordArray,
@@ -1328,6 +1308,31 @@
}
return propertyValue;
}
+
+ private Object getPropertyValueFromRequestCached(JSONObject recordObject,
+ Map<String, Property<?>> propertiesInProxy, String key,
+ Property<?> dtoProperty) throws JSONException,
IllegalAccessException,
+ InvocationTargetException, NoSuchMethodException,
InstantiationException {
+ Object propertyValue;
+ if (!recordObject.isNull(key)
+ && EntityProxy.class.isAssignableFrom(dtoProperty.getType())) {
+ // if the property type is a Proxy, we expect an encoded Key string
+ EntityKey propKey = getEntityKey(recordObject.getString(key));
+ // check to see if we've already decoded this object from JSON
+ Object cacheValue = cachedEntityLookup.get(propKey);
+ // containsKey is used here because an entity lookup can return null
+ if (cachedEntityLookup.containsKey(propKey)) {
+ propertyValue = cacheValue;
+ } else {
+ propertyValue = getPropertyValueFromRequest(recordObject, key,
+ propertiesInProxy.get(key).getType());
+ }
+ } else {
+ propertyValue = getPropertyValueFromRequest(recordObject, key,
+ propertiesInProxy.get(key).getType());
+ }
+ return propertyValue;
+ }
private Object getRawPropertyValueFromDatastore(Object entityElement,
String propertyName) throws SecurityException, NoSuchMethodException,
@@ -1384,10 +1389,11 @@
deleteArray.put(deleteRecord);
}
if (writeOperation == WriteOperation.UPDATE) {
- JSONObject updateRecord = new JSONObject();
- updateRecord.put(Constants.ENCODED_ID_PROPERTY, getSchemaAndId(
- entityKey.proxyType, entityKey.encodedId));
- updateArray.put(updateRecord);
+ Object entityInstance = entityData.entityInstance;
+ assert entityInstance != null;
+ updateArray.put(getJsonObjectWithIdAndVersion(
+ getSchemaAndId(entityKey.proxyType, entityKey.encodedId),
+ entityInstance, propertyRefs));
}
}
if (createArray.length() > 0) {
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryStringTest.java
Fri Oct 1 18:15:55 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryStringTest.java
Mon Oct 4 15:35:00 2010
@@ -163,6 +163,50 @@
}
});
}
+
+ public void testFindFindEdit() {
+ delayTestFinish(5000);
+
+ final SimpleFooEventHandler<SimpleFooStringProxy> handler = new
SimpleFooEventHandler<SimpleFooStringProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(),
+ SimpleFooStringProxy.class, handler);
+
+ req.simpleFooStringRequest().findSimpleFooStringById("999x").fire(
+ new Receiver<SimpleFooStringProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooStringProxy newFoo) {
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+
+
req.simpleFooStringRequest().findSimpleFooStringById("999x").fire(
+ new Receiver<SimpleFooStringProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooStringProxy newFoo) {
+ // no events are fired second time.
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+ SimpleFooStringRequest context =
req.simpleFooStringRequest();
+ final Request<Void> mutateRequest =
context.persist().using(
+ newFoo);
+ newFoo = context.edit(newFoo);
+ newFoo.setUserName("Ray");
+ mutateRequest.fire(new Receiver<Void>() {
+ @Override
+ public void onSuccess(Void response) {
+ // events fired on updates.
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
+
+ finishTestAndReset();
+ }
+ });
+ }
+ });
+ }
+ });
+ }
public void testFetchEntity() {
delayTestFinish(5000);
@@ -275,8 +319,8 @@
@Override
public void onSuccess(SimpleFooStringProxy finalFoo)
{
assertEquals("Ray", finalFoo.getUserName());
- assertEquals(3, handler.updateEventCount);
- assertEquals(3, handler.totalEventCount);
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
finishTestAndReset();
}
});
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Sun Oct 3 19:15:33 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Mon Oct 4 15:35:00 2010
@@ -360,6 +360,50 @@
}
});
}
+
+ public void testFindFindEdit() {
+ delayTestFinish(5000);
+
+ final SimpleFooEventHandler<SimpleFooProxy> handler = new
SimpleFooEventHandler<SimpleFooProxy>();
+ EntityProxyChange.registerForProxyType(req.getEventBus(),
+ SimpleFooProxy.class, handler);
+
+ req.simpleFooRequest().findSimpleFooById(999L).fire(
+ new Receiver<SimpleFooProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooProxy newFoo) {
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+
+ req.simpleFooRequest().findSimpleFooById(999L).fire(
+ new Receiver<SimpleFooProxy>() {
+
+ @Override
+ public void onSuccess(SimpleFooProxy newFoo) {
+ // no events are fired second time.
+ assertEquals(1, handler.updateEventCount);
+ assertEquals(1, handler.totalEventCount);
+ SimpleFooRequest context = req.simpleFooRequest();
+ final Request<Void> mutateRequest =
context.persist().using(
+ newFoo);
+ newFoo = context.edit(newFoo);
+ newFoo.setUserName("Ray");
+ mutateRequest.fire(new Receiver<Void>() {
+ @Override
+ public void onSuccess(Void response) {
+ // events fired on updates.
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
+
+ finishTestAndReset();
+ }
+ });
+ }
+ });
+ }
+ });
+ }
public void disabled_testEchoSimpleFutures() {
// tests if futureIds can be echoed back.
@@ -784,8 +828,8 @@
@Override
public void onSuccess(SimpleFooProxy finalFoo) {
assertEquals("Ray", finalFoo.getUserName());
- assertEquals(3, handler.updateEventCount);
- assertEquals(3, handler.totalEventCount);
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(2, handler.totalEventCount);
finishTestAndReset();
}
});
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Sat Oct 2 12:01:57 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Mon Oct 4 15:35:00 2010
@@ -134,8 +134,9 @@
JSONArray updateArray =
result.getJSONObject("sideEffects").getJSONArray(
"UPDATE");
assertEquals(1, updateArray.length());
- assertEquals(1, updateArray.getJSONObject(0).length());
+ assertEquals(2, updateArray.getJSONObject(0).length());
assertTrue(updateArray.getJSONObject(0).has(Constants.ENCODED_ID_PROPERTY));
+
assertTrue(updateArray.getJSONObject(0).has(Constants.ENCODED_VERSION_PROPERTY));
assertFalse(updateArray.getJSONObject(0).has("violations"));
assertEquals(45, (int) fooResult.getIntId());
assertEquals("JSC", fooResult.getUserName());
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/server/SimpleBar.java
Thu Sep 30 12:36:38 2010
+++ /trunk/user/test/com/google/gwt/requestfactory/server/SimpleBar.java
Mon Oct 4 15:35:00 2010
@@ -157,6 +157,7 @@
isNew = false;
get().put(getId(), this);
}
+ version++;
}
public SimpleBar persistAndReturnSelf() {
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
Fri Oct 1 18:15:55 2010
+++ /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
Mon Oct 4 15:35:00 2010
@@ -301,6 +301,7 @@
public Long countSimpleFooWithUserNameSideEffect() {
findSimpleFoo(1L).setUserName(userName);
+ version++;
return countSimpleFoo();
}
@@ -449,6 +450,7 @@
isNew = false;
get().put(getId(), this);
}
+ version++;
}
public SimpleFoo persistAndReturnSelf() {
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleFooString.java
Wed Sep 22 04:32:28 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleFooString.java
Mon Oct 4 15:35:00 2010
@@ -185,6 +185,7 @@
public Long countSimpleFooWithUserNameSideEffect() {
get().setUserName(userName);
+ version++;
return 1L;
}
@@ -322,6 +323,7 @@
public void persist() {
setId(nextId++ + "x");
+ version++;
}
public SimpleFooString persistAndReturnSelf() {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors