Revision: 8582
Author: [email protected]
Date: Thu Aug 19 13:59:07 2010
Log: Fixes the issue that the DVS does not send an object to the server if
no
setters have been called on it. Added tests for the issue. Finally, removed
the
unnecessary operations.size() restriction in DeltaValueStoreJsonImpl.
Patch by: amitmanjhi
Review by: rjrjr, cromwellian
http://code.google.com/p/google-web-toolkit/source/detail?r=8582
Modified:
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Thu Aug 19 13:24:10 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
Thu Aug 19 13:59:07 2010
@@ -194,7 +194,7 @@
returnedJso, WriteOperation.DELETE.name());
Map<Long, Map<String, String>> violationsMap =
getViolationsMap(deletedRecords);
int length = deletedRecords.length();
- // for (Map.Entry<RecordKey, RecordJsoImpl> entry :
deletes.entrySet()) {
+
for (int i = 0; i < length; i++) {
final RecordKey key = new RecordKey(deletedRecords.get(i).getId(),
requestFactory.getSchema(deletedRecords.get(i).getSchema()),
@@ -300,27 +300,18 @@
}
String toJson() {
- if (operations.size() > 1) {
- throw new UnsupportedOperationException(
- "Currently, only one entity can be saved/persisted at a time");
- /*
- * TODO: Short-term todo is to allow multiple entities belonging to
the
- * same class to be persisted at the same time. The client side
support
- * for this operation is already in place. On the server side, this
will
- * entail persisting all entities as part of a single transaction. In
- * particular, the transaction should fail if the validation check
on any
- * of the entities fail.
- *
- * Multiple entities belonging to different records can not be
persisted
- * at present due to the appEngine limitation of a transaction not
being
- * allowed to span multiple entity groups.
- */
- }
- return toJsonWithoutChecks();
- }
-
- String toJsonWithoutChecks() {
- used = true;
+ used = true;
+
+ /*
+ * pull the creates that only the requestFactory knows about.
+ */
+ for (RecordKey recordKey : requestFactory.creates.keySet()) {
+ RecordJsoImpl oldRecord = requestFactory.creates.remove(recordKey);
+ assert oldRecord != null;
+ operations.put(recordKey, WriteOperation.CREATE);
+ creates.put(recordKey, oldRecord);
+ }
+
StringBuffer jsonData = new StringBuffer("{");
for (WriteOperation writeOperation : new WriteOperation[] {
WriteOperation.CREATE, WriteOperation.UPDATE}) {
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
Wed Aug 18 15:12:56 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java
Thu Aug 19 13:59:07 2010
@@ -79,6 +79,7 @@
return create(token, typeMap);
}
+ @Override
public RecordSchema getSchema(String token) {
return typeMap.getType(token);
}
@@ -122,6 +123,17 @@
assertNotNull(created.getId());
assertNotNull(created.getVersion());
+ DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+ valueStore, requestFactory);
+ String json = deltaValueStore.toJson();
+ testAndGetChangeRecord(json, WriteOperation.CREATE);
+ }
+
+ public void testCreateWithSet() {
+ Record created = requestFactory.create(SimpleFooRecord.class);
+ assertNotNull(created.getId());
+ assertNotNull(created.getVersion());
+
DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
valueStore, requestFactory);
// DVS does not know about the created entity.
@@ -182,7 +194,7 @@
deltaValueStore.set(SimpleFooRecord.userName, createRecord, "harry");
deltaValueStore.set(SimpleFooRecord.userName, mockRecord, "bovik");
assertTrue(deltaValueStore.isChanged());
- String jsonString = deltaValueStore.toJsonWithoutChecks();
+ String jsonString = deltaValueStore.toJson();
JSONObject jsonObject = (JSONObject) JSONParser.parse(jsonString);
assertFalse(jsonObject.containsKey(WriteOperation.DELETE.name()));
assertTrue(jsonObject.containsKey(WriteOperation.CREATE.name()));
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors