Reviewers: Ray Ryan,
Description:
Deleting a managed entity makes all its fields null. Updated the code to
account for this behavior.
Please review this at http://gwt-code-reviews.appspot.com/520801/show
Affected files:
M
trunk/bikeshed/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
Index:
trunk/bikeshed/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
===================================================================
---
trunk/bikeshed/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
(revision 8109)
+++
trunk/bikeshed/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
(working copy)
@@ -500,27 +500,32 @@
Set<ConstraintViolation<Object>> violations) throws
SecurityException,
JSONException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
-
+ // id/futureId, the identifying field is sent back from the incoming
record.
JSONObject returnObject = new JSONObject();
- if (writeOperation == WriteOperation.CREATE && violations != null
- && !violations.isEmpty()) {
- // don't send anything back
- } else {
- // currently sending back only two properties.
- for (String propertyName : new String[] {"id", "version"}) {
- if ("version".equals(propertyName) && violations != null
- && !violations.isEmpty()) {
- continue;
- }
- returnObject.put(propertyName, getPropertyValueFromDataStore(
- entityInstance, propertyName));
- }
- }
- if (violations != null && !violations.isEmpty()) {
+ final boolean hasViolations = violations != null
&& !violations.isEmpty();
+ if (hasViolations) {
returnObject.put("violations", getViolationsAsJson(violations));
}
- if (writeOperation == WriteOperation.CREATE) {
- returnObject.put("futureId", recordObject.getString("id"));
+ switch (writeOperation) {
+ case CREATE:
+ returnObject.put("futureId", recordObject.getString("id"));
+ if (!hasViolations) {
+ returnObject.put("id",
getPropertyValueFromDataStore(entityInstance,
+ "id"));
+ returnObject.put("version", getPropertyValueFromDataStore(
+ entityInstance, "version"));
+ }
+ break;
+ case DELETE:
+ returnObject.put("id", recordObject.getString("id"));
+ break;
+ case UPDATE:
+ returnObject.put("id", recordObject.getString("id"));
+ if (!hasViolations) {
+ returnObject.put("version", getPropertyValueFromDataStore(
+ entityInstance, "version"));
+ }
+ break;
}
return returnObject;
}
@@ -562,8 +567,8 @@
return violationsAsJson;
}
- private Object invokeStaticDomainMethod(Method domainMethod,
- Object args[]) throws IllegalAccessException,
InvocationTargetException {
+ private Object invokeStaticDomainMethod(Method domainMethod, Object
args[])
+ throws IllegalAccessException, InvocationTargetException {
return domainMethod.invoke(null, args);
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors