Revision: 8487
Author: [email protected]
Date: Thu Aug  5 10:04:19 2010
Log: Moved the create method from DeltaValueStore, used Long futureIds. Deleted ValueStore interface and made ValueStoreJsonImpl non-public.

Patch by: amitmanjhi
Review by: rjrjr (desk review)

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

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

Deleted:
 /trunk/user/src/com/google/gwt/valuestore/shared/ValueStore.java
Modified:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java
 /trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java /trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java
 /trunk/user/src/com/google/gwt/requestfactory/client/impl/RecordKey.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java /trunk/user/src/com/google/gwt/requestfactory/client/impl/ValueStoreJsonImpl.java /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
 /trunk/user/src/com/google/gwt/requestfactory/shared/DeltaValueStore.java
 /trunk/user/src/com/google/gwt/requestfactory/shared/RequestFactory.java
 /trunk/user/src/com/google/gwt/valuestore/client/SyncResultImpl.java
 /trunk/user/src/com/google/gwt/valuestore/shared/SyncResult.java
/trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java

=======================================
--- /trunk/user/src/com/google/gwt/valuestore/shared/ValueStore.java Wed Jul 28 16:39:40 2010
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.valuestore.shared;
-
-/**
- * <p>
- * <span style="color:red">Experimental API: This class is still under rapid
- * development, and is very likely to be deleted. Use it at your own risk.
- * </span>
- * </p>
- * A store of records with properties.
- */
-public interface ValueStore {
-  /**
-   * Most validations are per field or per id and set via annotation.
-   */
- void addValidation(/* what's a validation. JSR 303? Learn from Pectin? */);
-
-}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java Fri Jul 30 17:29:09 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileExpenseEntry.java Thu Aug 5 10:04:19 2010
@@ -74,9 +74,9 @@
   }

   public void create(Long reportId) {
+    expense = (ExpenseRecord) requestFactory.create(ExpenseRecord.class);
     requestObject = requestFactory.expenseRequest().persist();
     DeltaValueStore deltas = requestObject.getDeltaValueStore();
-    expense = (ExpenseRecord) deltas.create(ExpenseRecord.class);
     deltas.set(ExpenseRecord.reportId, expense, reportId);
     displayExpense();
   }
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java Fri Jul 30 11:32:15 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java Thu Aug 5 10:04:19 2010
@@ -84,9 +84,9 @@
   }

   public void create(Long reporterId) {
+    report = (ReportRecord) requestFactory.create(ReportRecord.class);
     requestObject = requestFactory.reportRequest().persist();
     DeltaValueStore deltas = requestObject.getDeltaValueStore();
-    report = (ReportRecord) deltas.create(ReportRecord.class);
     deltas.set(ReportRecord.reporterKey, report, reporterId.toString());
     displayReport();
   }
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java Fri Jul 30 17:29:09 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java Thu Aug 5 10:04:19 2010
@@ -58,7 +58,7 @@
   public EmployeeEditActivity(Long id, RecordEditView<EmployeeRecord> view,
       ExpensesRequestFactory requests,
       PlaceController<ScaffoldPlace> placeController) {
-    super(view, id, requests.employeeRequest().persist());
+    super(view, id, requests, requests.employeeRequest().persist());
     this.requests = requests;
     this.placeController = placeController;
   }
=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java Fri Jul 30 17:29:09 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java Thu Aug 5 10:04:19 2010
@@ -58,7 +58,7 @@
   public ReportEditActivity(Long id, RecordEditView<ReportRecord> view,
       ExpensesRequestFactory requests,
       PlaceController<ScaffoldPlace> placeController) {
-    super(view, id, requests.reportRequest().persist());
+    super(view, id, requests, requests.reportRequest().persist());
     this.requests = requests;
     this.placeController = placeController;
   }
=======================================
--- /trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java Fri Jul 30 17:29:09 2010 +++ /trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java Thu Aug 5 10:04:19 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.requestfactory.shared.DeltaValueStore;
 import com.google.gwt.requestfactory.shared.Receiver;
+import com.google.gwt.requestfactory.shared.RequestFactory;
 import com.google.gwt.requestfactory.shared.RequestObject;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.valuestore.shared.Record;
@@ -43,17 +44,18 @@

   private Long id;
   private Long futureId;
-  private DeltaValueStore deltas;
+  private final RequestFactory requests;

   private Display display;
   private RequestObject<Void> requestObject;

   public AbstractRecordEditActivity(RecordEditView<R> view, Long id,
-      RequestObject<Void> requestObject) {
+      RequestFactory requests, RequestObject<Void> requestObject) {

     this.view = view;
     this.creating = 0L == id;
     this.id = id;
+    this.requests = requests;
     this.requestObject = requestObject;
   }

@@ -142,8 +144,7 @@
     view.setCreating(creating);

     if (creating) {
-      R tempRecord = (R) requestObject.getDeltaValueStore().create(
-          getRecordClass());
+      R tempRecord = (R) requests.create(getRecordClass());
       futureId = tempRecord.getId();
       doStart(display, tempRecord);
     } else {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java Fri Jul 30 11:32:15 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractRequest.java Thu Aug 5 10:04:19 2010
@@ -50,7 +50,7 @@
   public AbstractRequest(RequestFactoryJsonImpl requestFactory) {
     this.requestFactory = requestFactory;
     ValueStoreJsonImpl valueStore = requestFactory.getValueStore();
- this.deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map); + this.deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, requestFactory);
   }

   public void fire(Receiver<T> receiver) {
@@ -83,7 +83,7 @@

   public void reset() {
     ValueStoreJsonImpl valueStore = requestFactory.getValueStore();
- deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map); + deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, requestFactory);
   }

   public <V> void set(Property<V> property, Record record, V value) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java Fri Jul 30 17:29:09 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImpl.java Thu Aug 5 10:04:19 2010
@@ -25,8 +25,6 @@
 import com.google.gwt.valuestore.shared.WriteOperation;
 import com.google.gwt.valuestore.shared.impl.RecordImpl;
 import com.google.gwt.valuestore.shared.impl.RecordJsoImpl;
-import com.google.gwt.valuestore.shared.impl.RecordSchema;
-import com.google.gwt.valuestore.shared.impl.RecordToTypeMap;

 import java.util.HashMap;
 import java.util.HashSet;
@@ -38,8 +36,7 @@
* <span style="color:red">Experimental API: This class is still under rapid
  * development, and is very likely to be deleted. Use it at your own risk.
  * </span>
- * </p>
- * {...@link DeltaValueStore} implementation.
+ * </p> {...@link DeltaValueStore} implementation.
  */
 public class DeltaValueStoreJsonImpl implements DeltaValueStore {

@@ -99,34 +96,13 @@
       return 'violations' in this;
     }-*/;
   }
-
-  private static class FutureIdGenerator {
-    Set<String> idsInTransit = new HashSet<String>();
-    int maxId = 1;
-
-    void delete(String id) {
-      idsInTransit.remove(id);
-    }
-
-    String getFutureId() {
-      int futureId = maxId++;
-      if (maxId == Integer.MAX_VALUE) {
-        maxId = 1;
-      }
-      assert !idsInTransit.contains(futureId);
-      return new String(futureId + "");
-    }
-  }

private static final HashMap<String, String> NULL_VIOLATIONS = new HashMap<String, String>();

-  private static final Integer INITIAL_VERSION = 1;
-
   private boolean used = false;
- private final FutureIdGenerator futureIdGenerator = new FutureIdGenerator();

   private final ValueStoreJsonImpl master;
-  private final RecordToTypeMap recordToTypeMap;
+  private final RequestFactoryJsonImpl requestFactory;

   // track C-U-D of CRUD operations
private final Map<RecordKey, RecordJsoImpl> creates = new HashMap<RecordKey, RecordJsoImpl>();
@@ -136,9 +112,9 @@
private final Map<RecordKey, WriteOperation> operations = new HashMap<RecordKey, WriteOperation>();

   public DeltaValueStoreJsonImpl(ValueStoreJsonImpl master,
-      RecordToTypeMap recordToTypeMap) {
+      RequestFactoryJsonImpl requestFactory) {
     this.master = master;
-    this.recordToTypeMap = recordToTypeMap;
+    this.requestFactory = requestFactory;
   }

   public void addValidation() {
@@ -163,8 +139,8 @@
* construct 2 maps: (i) futureId to the datastore Id, (ii) futureId to
        * violationsMap
        */
- Map<Object, Object> futureToDatastoreId = new HashMap<Object, Object>(); - Map<String, Map<String, String>> violationsMap = new HashMap<String, Map<String, String>>();
+      Map<Long, Long> futureToDatastoreId = new HashMap<Long, Long>();
+ Map<Long, Map<String, String>> violationsMap = new HashMap<Long, Map<String, String>>();
       int length = newRecords.length();
       for (int i = 0; i < length; i++) {
         ReturnRecord sync = newRecords.get(i);
@@ -173,25 +149,26 @@
           assert !sync.hasId();
HashMap<String, String> violations = new HashMap<String, String>();
           sync.fillViolations(violations);
-          violationsMap.put(sync.getFutureId(), violations);
+          violationsMap.put(Long.valueOf(sync.getFutureId()), violations);
         } else {
-          violationsMap.put(sync.getFutureId(), NULL_VIOLATIONS);
-          futureToDatastoreId.put(sync.getFutureId(), sync.getId());
+ violationsMap.put(Long.valueOf(sync.getFutureId()), NULL_VIOLATIONS);
+          futureToDatastoreId.put(Long.valueOf(sync.getFutureId()),
+              Long.valueOf(sync.getId()));
         }
       }

for (Map.Entry<RecordKey, RecordJsoImpl> entry : creates.entrySet()) {
         final RecordKey futureKey = entry.getKey();
         // TODO change violationsMap to <Long, String>
- Map<String, String> violations = violationsMap.get(futureKey.id.toString());
+        Map<String, String> violations = violationsMap.get(futureKey.id);
         assert violations != null;
         if (violations == NULL_VIOLATIONS) {
- Object datastoreId = futureToDatastoreId.get(futureKey.id.toString());
+          Long datastoreId = futureToDatastoreId.get(futureKey.id);
           assert datastoreId != null;
-          futureIdGenerator.delete(futureKey.id.toString());
+          requestFactory.futureIdGenerator.delete(futureKey.id);
final RecordKey key = new RecordKey(datastoreId, futureKey.schema);
           RecordJsoImpl value = entry.getValue();
-          value.set(Record.id, Long.parseLong(datastoreId.toString()));
+          value.set(Record.id, datastoreId);
           RecordJsoImpl masterRecord = master.records.get(key);
           assert masterRecord == null;
           master.records.put(key, value);
@@ -199,12 +176,11 @@
           toRemove.add(key);
master.eventBus.fireEvent(masterRecord.getSchema().createChangeEvent(
               masterRecord, WriteOperation.CREATE));
-          syncResults.add(new SyncResultImpl(masterRecord, null,
-              futureKey.id.toString()));
+ syncResults.add(new SyncResultImpl(masterRecord, null, futureKey.id));
         } else {
           // do not change the masterRecord or fire event
           syncResults.add(new SyncResultImpl(entry.getValue(), violations,
-              futureKey.id.toString()));
+              futureKey.id));
         }
       }
     }
@@ -214,10 +190,10 @@
     if (keys.contains(WriteOperation.DELETE.name())) {
       JsArray<ReturnRecord> deletedRecords = ReturnRecord.getRecords(
           returnedJso, WriteOperation.DELETE.name());
- Map<String, Map<String, String>> violationsMap = getViolationsMap(deletedRecords); + Map<Long, Map<String, String>> violationsMap = getViolationsMap(deletedRecords); for (Map.Entry<RecordKey, RecordJsoImpl> entry : deletes.entrySet()) {
         final RecordKey key = entry.getKey();
- Map<String, String> violations = violationsMap.get(key.id.toString());
+        Map<String, String> violations = violationsMap.get(key.id);
         assert violations != null;
         if (violations == NULL_VIOLATIONS) {
           RecordJsoImpl masterRecord = master.records.get(key);
@@ -239,10 +215,10 @@
     if (keys.contains(WriteOperation.UPDATE.name())) {
       JsArray<ReturnRecord> updatedRecords = ReturnRecord.getRecords(
           returnedJso, WriteOperation.UPDATE.name());
- Map<String, Map<String, String>> violationsMap = getViolationsMap(updatedRecords); + Map<Long, Map<String, String>> violationsMap = getViolationsMap(updatedRecords); for (Map.Entry<RecordKey, RecordJsoImpl> entry : updates.entrySet()) {
         final RecordKey key = entry.getKey();
- Map<String, String> violations = violationsMap.get(key.id.toString());
+        Map<String, String> violations = violationsMap.get(key.id);
         assert violations != null;
         if (violations == NULL_VIOLATIONS) {
           RecordJsoImpl masterRecord = master.records.get(key);
@@ -261,28 +237,18 @@
     processToRemove(toRemove, WriteOperation.UPDATE);
     return syncResults;
   }
-
-  public Record create(Class token) {
-    if (used) {
-      throw new IllegalStateException(
-          "create can only be called on an un-used DeltaValueStore");
-    }
-    String futureId = futureIdGenerator.getFutureId();
-
-    RecordSchema<? extends Record> schema = recordToTypeMap.getType(token);
- RecordJsoImpl newRecord = RecordJsoImpl.create(Long.parseLong(futureId), INITIAL_VERSION,
-        schema);
-    RecordKey recordKey = new RecordKey(newRecord);
-    assert operations.get(recordKey) == null;
-    operations.put(recordKey, WriteOperation.CREATE);
-    creates.put(recordKey, newRecord);
-    return schema.create(newRecord);
-  }

   public void delete(Record record) {
     checkArgumentsAndState(record, "delete");
     RecordImpl recordImpl = (RecordImpl) record;
     RecordKey recordKey = new RecordKey(recordImpl);
+    RecordJsoImpl rawMasterRecord = master.records.get(recordKey);
+    if (rawMasterRecord == null) {
+      // it was a create on RF
+      RecordJsoImpl oldRecord = requestFactory.creates.remove(recordKey);
+      assert oldRecord != null;
+      return;
+    }
     WriteOperation priorOperation = operations.get(recordKey);
     if (priorOperation == null) {
       operations.put(recordKey, WriteOperation.DELETE);
@@ -327,6 +293,14 @@

     RecordJsoImpl rawMasterRecord = master.records.get(recordKey);
     WriteOperation priorOperation = operations.get(recordKey);
+    if (rawMasterRecord == null && priorOperation == null) {
+      // it was a create on RF that has not been pulled in to the DVS.
+      RecordJsoImpl oldRecord = requestFactory.creates.remove(recordKey);
+      assert oldRecord != null;
+      operations.put(recordKey, WriteOperation.CREATE);
+      creates.put(recordKey, oldRecord);
+      priorOperation = WriteOperation.CREATE;
+    }
     if (priorOperation == null) {
       addNewChangeRecord(recordKey, recordImpl, property, value);
       return;
@@ -411,10 +385,6 @@
     jsonData.append("}");
     return jsonData.toString();
   }
-
-  public boolean validate() {
-    throw new UnsupportedOperationException("Auto-generated method stub");
-  }

   /**
    * returns true if a new change record has been added.
@@ -486,9 +456,9 @@
     }
   }

-  private Map<String, Map<String, String>> getViolationsMap(
+  private Map<Long, Map<String, String>> getViolationsMap(
       JsArray<ReturnRecord> records) {
- Map<String, Map<String, String>> violationsMap = new HashMap<String, Map<String, String>>(); + Map<Long, Map<String, String>> violationsMap = new HashMap<Long, Map<String, String>>();
     int length = records.length();
     for (int i = 0; i < length; i++) {
       ReturnRecord record = records.get(i);
@@ -499,7 +469,7 @@
       } else {
         violations = NULL_VIOLATIONS;
       }
-      violationsMap.put(record.getId(), violations);
+      violationsMap.put(Long.valueOf(record.getId()), violations);
     }
     return violationsMap;
   }
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/RecordKey.java Wed Jul 28 16:39:40 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/RecordKey.java Thu Aug 5 10:04:19 2010
@@ -30,7 +30,7 @@
  */
 class RecordKey {
   final RecordSchema<?> schema;
-  final Object id;
+  final Long id;

   RecordKey(RecordImpl record) {
     this(record.getId(), record.getSchema());
@@ -40,7 +40,7 @@
     this(record.getId(), record.getSchema());
   }

-  protected RecordKey(Object id, RecordSchema<?> schema) {
+  protected RecordKey(Long id, RecordSchema<?> schema) {
     assert id != null;
     assert schema != null;

=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java Wed Aug 4 16:16:12 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java Thu Aug 5 10:04:19 2010
@@ -34,7 +34,9 @@
 import com.google.gwt.valuestore.shared.impl.RecordSchema;
 import com.google.gwt.valuestore.shared.impl.RecordToTypeMap;

+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -49,21 +51,21 @@
  */
 public abstract class RequestFactoryJsonImpl implements RequestFactory {

-  private static class FutureIdGenerator {
-    Set<String> idsInTransit = new HashSet<String>();
-    int maxId = 1;
-
-    void delete(String id) {
+  static class FutureIdGenerator {
+    Set<Long> idsInTransit = new HashSet<Long>();
+    Long maxId = 1L;
+
+    void delete(Long id) {
       idsInTransit.remove(id);
     }

-    String getFutureId() {
-      int futureId = maxId++;
-      if (maxId == Integer.MAX_VALUE) {
-        maxId = 1;
+    Long getFutureId() {
+      Long futureId = maxId++;
+      if (maxId == Long.MAX_VALUE) {
+        maxId = 1L;
       }
       assert !idsInTransit.contains(futureId);
-      return new String(futureId + "");
+      return futureId;
     }
   }

@@ -80,19 +82,23 @@

   private static final Integer INITIAL_VERSION = 1;

+  final FutureIdGenerator futureIdGenerator = new FutureIdGenerator();
+
+ final Map<RecordKey, RecordJsoImpl> creates = new HashMap<RecordKey, RecordJsoImpl>();
+
   private ValueStoreJsonImpl valueStore;

   private HandlerManager handlerManager;

- private final FutureIdGenerator futureIdGenerator = new FutureIdGenerator();
-
   public com.google.gwt.valuestore.shared.Record create(
       Class<? extends Record> token, RecordToTypeMap recordToTypeMap) {
-    String futureId = futureIdGenerator.getFutureId();
+    Long futureId = futureIdGenerator.getFutureId();

     RecordSchema<? extends Record> schema = recordToTypeMap.getType(token);
-    RecordJsoImpl newRecord = RecordJsoImpl.create(Long.valueOf(futureId),
-        INITIAL_VERSION, schema);
+ RecordJsoImpl newRecord = RecordJsoImpl.create(futureId, INITIAL_VERSION,
+        schema);
+    RecordKey recordKey = new RecordKey(newRecord);
+    creates.put(recordKey, newRecord);
     return schema.create(newRecord);
   }

@@ -123,7 +129,7 @@
         if (200 == response.getStatusCode()) {
           String text = response.getText();
           requestObject.handleResponseText(text);
-        } else if (response.SC_UNAUTHORIZED == response.getStatusCode()) {
+        } else if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
           wireLogger.finest("Need to log in");
         } else if (response.getStatusCode() > 0) {
// During the redirection for logging in, we get a response with no
@@ -145,21 +151,21 @@
wireLogger.log(Level.SEVERE, SERVER_ERROR + " (" + e.getMessage() + ")", e);
     }
   }
-
-  public ValueStoreJsonImpl getValueStore() {
-    return valueStore;
-  }

   /**
    * @param handlerManager
    */
-  protected void init(HandlerManager handlerManager, RecordToTypeMap map) {
-    this.valueStore = new ValueStoreJsonImpl(handlerManager, map);
+  public void init(HandlerManager handlerManager) {
+    this.valueStore = new ValueStoreJsonImpl(handlerManager);
     this.handlerManager = handlerManager;
     Logger.getLogger("").addHandler(new RequestFactoryLogHandler(
         this, Level.WARNING, wireLogger.getName()));
     logger.fine("Successfully initialized RequestFactory");
   }
+
+  ValueStoreJsonImpl getValueStore() {
+    return valueStore;
+  }

   private void postRequestEvent(State received, Response response) {
     handlerManager.fireEvent(new RequestEvent(received, response));
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/ValueStoreJsonImpl.java Wed Jul 28 16:39:40 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/ValueStoreJsonImpl.java Thu Aug 5 10:04:19 2010
@@ -17,10 +17,8 @@

 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.valuestore.shared.ValueStore;
 import com.google.gwt.valuestore.shared.WriteOperation;
 import com.google.gwt.valuestore.shared.impl.RecordJsoImpl;
-import com.google.gwt.valuestore.shared.impl.RecordToTypeMap;

 import java.util.HashMap;
 import java.util.Map;
@@ -31,23 +29,16 @@
  * development, and is very likely to be deleted. Use it at your own risk.
  * </span>
  * </p>
- * {...@link ValueStore} implementation.
  */
-public class ValueStoreJsonImpl implements ValueStore {
+class ValueStoreJsonImpl {
   // package protected fields for use by DeltaValueStoreJsonImpl

   final HandlerManager eventBus;
-  final RecordToTypeMap map;

final Map<RecordKey, RecordJsoImpl> records = new HashMap<RecordKey, RecordJsoImpl>();

-  public ValueStoreJsonImpl(HandlerManager eventBus, RecordToTypeMap map) {
+  ValueStoreJsonImpl(HandlerManager eventBus) {
     this.eventBus = eventBus;
-    this.map = map;
-  }
-
-  public void addValidation() {
-    throw new UnsupportedOperationException("Auto-generated method stub");
   }

   public void setRecord(RecordJsoImpl newRecord) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java Wed Aug 4 22:08:44 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java Thu Aug 5 10:04:19 2010
@@ -28,9 +28,9 @@
 import com.google.gwt.core.ext.typeinfo.NotFoundException;
 import com.google.gwt.core.ext.typeinfo.TypeOracle;
 import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.requestfactory.client.impl.AbstractBooleanRequest;
 import com.google.gwt.requestfactory.client.impl.AbstractBigDecimalRequest;
 import com.google.gwt.requestfactory.client.impl.AbstractBigIntegerRequest;
+import com.google.gwt.requestfactory.client.impl.AbstractBooleanRequest;
 import com.google.gwt.requestfactory.client.impl.AbstractByteRequest;
 import com.google.gwt.requestfactory.client.impl.AbstractCharacterRequest;
 import com.google.gwt.requestfactory.client.impl.AbstractDateRequest;
@@ -293,16 +293,10 @@
       e.printStackTrace();
     }

-    // write init()
+    // write create(Class..)
JClassType recordToTypeInterface = generatorContext.getTypeOracle().findType(
         RecordToTypeMap.class.getName());
-    String recordToTypeMapName = recordToTypeInterface.getName() + "Impl";
-    sw.println("public void init(HandlerManager handlerManager) {");
-    sw.indent();
- sw.println("super.init(handlerManager, new " + recordToTypeMapName + "());");
-    sw.outdent();
-    sw.println("}");
-    sw.println();
+    String recordToTypeMapName = recordToTypeInterface.getName() + "Impl";
sw.println("public " + Record.class.getName() + " create(Class token) {");
     sw.indent();
     sw.println("return create(token, new " + recordToTypeMapName + "());");
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/DeltaValueStore.java Wed Jul 28 16:39:40 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/DeltaValueStore.java Thu Aug 5 10:04:19 2010
@@ -17,7 +17,6 @@

 import com.google.gwt.valuestore.shared.Property;
 import com.google.gwt.valuestore.shared.Record;
-import com.google.gwt.valuestore.shared.ValueStore;

 /**
  * <p>
@@ -27,7 +26,7 @@
  * </p>
  * Set of changes to a ValueStore.
  */
-public interface DeltaValueStore extends ValueStore {
+public interface DeltaValueStore {

   /**
* Enable a DeltaValueStore to be reused again. For example, when the edit
@@ -35,8 +34,6 @@
    */
   void clearUsed();

-  Record create(Class token);
-
   void delete(Record record);

   /**
@@ -47,9 +44,4 @@
   boolean isChanged();

   <V> void set(Property<V> property, Record record, V value);
-
-  /**
-   * Returns true if all validations have passed.
-   */
-  boolean validate();
-}
+}
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/RequestFactory.java Mon Aug 2 20:55:43 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/RequestFactory.java Thu Aug 5 10:04:19 2010
@@ -17,7 +17,6 @@

 import com.google.gwt.event.shared.HandlerManager;
 import com.google.gwt.valuestore.shared.Record;
-import com.google.gwt.valuestore.shared.ValueStore;

 /**
  * <p>
@@ -28,7 +27,7 @@
  * Marker interface for the RequestFactory code generator.
  */
 public interface RequestFactory {
-  public static final String JSON_CONTENT_TYPE_UTF8 =
+  String JSON_CONTENT_TYPE_UTF8 =
     "application/json; charset=utf-8";

   String SYNC = "SYNC";
@@ -38,8 +37,6 @@

   Record create(Class token);

-  ValueStore getValueStore();
-
   void init(HandlerManager eventBus);

// The following methods match the format for the generated sub-interfaces
=======================================
--- /trunk/user/src/com/google/gwt/valuestore/client/SyncResultImpl.java Thu Jun 24 14:48:00 2010 +++ /trunk/user/src/com/google/gwt/valuestore/client/SyncResultImpl.java Thu Aug 5 10:04:19 2010
@@ -32,15 +32,15 @@

   private final Record record;
   private final Map<String, String> violations;
-  private final String futureId;
-
- public SyncResultImpl(Record record, Map<String, String> violations, String futureId) {
+  private final Long futureId;
+
+ public SyncResultImpl(Record record, Map<String, String> violations, Long futureId) {
     this.record = record;
     this.violations = violations;
     this.futureId = futureId;
   }

-  public String getFutureId() {
+  public Long getFutureId() {
     return futureId;
   }

=======================================
--- /trunk/user/src/com/google/gwt/valuestore/shared/SyncResult.java Wed Jul 28 16:39:40 2010 +++ /trunk/user/src/com/google/gwt/valuestore/shared/SyncResult.java Thu Aug 5 10:04:19 2010
@@ -29,7 +29,7 @@
   // TODO: move violations out of the SyncResult...
   boolean hasViolations();

-  String getFutureId();
+  Long getFutureId();

   Record getRecord();

=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java Fri Jul 30 17:29:09 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/impl/DeltaValueStoreJsonImplTest.java Thu Aug 5 10:04:19 2010
@@ -15,11 +15,12 @@
  */
 package com.google.gwt.requestfactory.client.impl;

+import com.google.gwt.event.shared.HandlerManager;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.requestfactory.shared.DeltaValueStore;
+import com.google.gwt.requestfactory.shared.LoggingRequest;
 import com.google.gwt.valuestore.shared.Record;
 import com.google.gwt.valuestore.shared.SimpleFooRecord;
 import com.google.gwt.valuestore.shared.WriteOperation;
@@ -47,7 +48,18 @@
     }
   }

+  final RecordToTypeMap typeMap = new RecordToTypeMap() {
+    public RecordSchema<? extends Record> getType(
+        Class<? extends Record> recordClass) {
+      if (recordClass.equals(SimpleFooRecord.class)) {
+        return SimpleFooRecordImpl.SCHEMA;
+      }
+      throw new IllegalArgumentException("Unknown token " + recordClass);
+    }
+  };
   ValueStoreJsonImpl valueStore = null;
+  RequestFactoryJsonImpl requestFactory = null;
+
   RecordJsoImpl jso = null;

   public String getModuleName() {
@@ -56,16 +68,22 @@

   @Override
   public void gwtSetUp() {
-    valueStore = new ValueStoreJsonImpl(null, new RecordToTypeMap() {
-      public RecordSchema<? extends Record> getType(Class<? extends Record>
-          recordClass) {
-        if (recordClass.equals(SimpleFooRecord.class)) {
-          return SimpleFooRecordImpl.SCHEMA;
-        }
-        throw new IllegalArgumentException("Unknown token " + recordClass);
+    valueStore = new ValueStoreJsonImpl(null);
+    requestFactory = new RequestFactoryJsonImpl() {
+
+      public Record create(Class token) {
+        return create(token, typeMap);
       }

-    });
+      public void init(HandlerManager eventBus) {
+        // ignore.
+      }
+
+      public LoggingRequest loggingRequest() {
+        return null; //ignore
+      }
+
+    };

     // add a record
     jso = RecordJsoImpl.fromJson("{}");
@@ -80,19 +98,24 @@
   }

   public void testCreate() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
-    Record created = deltaValueStore.create(SimpleFooRecord.class);
+    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.
+    assertFalse(deltaValueStore.isChanged());
+    deltaValueStore.set(SimpleFooRecord.userName, created, "harry");
     assertTrue(deltaValueStore.isChanged());
testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.CREATE);
   }

   public void testCreateDelete() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
-    Record created = deltaValueStore.create(SimpleFooRecord.class);
-    assertTrue(deltaValueStore.isChanged());
+    Record created = requestFactory.create(SimpleFooRecord.class);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
+    assertFalse(deltaValueStore.isChanged());
     deltaValueStore.delete(created);
     assertFalse(deltaValueStore.isChanged());

@@ -101,9 +124,11 @@
   }

   public void testCreateUpdate() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
-    Record created = deltaValueStore.create(SimpleFooRecord.class);
-    assertTrue(deltaValueStore.isChanged());
+    Record created = requestFactory.create(SimpleFooRecord.class);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
+    // DVS does not know about the created entity.
+    assertFalse(deltaValueStore.isChanged());
     deltaValueStore.set(SimpleFooRecord.userName, created, "harry");
     assertTrue(deltaValueStore.isChanged());
JSONObject changeRecord = testAndGetChangeRecord(deltaValueStore.toJson(),
@@ -112,14 +137,16 @@
   }

   public void testDelete() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
     deltaValueStore.delete(new MyRecordImpl(jso));
     assertTrue(deltaValueStore.isChanged());
testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.DELETE);
   }

   public void testDeleteUpdate() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
     deltaValueStore.delete(new MyRecordImpl(jso));
     assertTrue(deltaValueStore.isChanged());

@@ -133,7 +160,8 @@
   }

   public void testOperationAfterJson() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
     deltaValueStore.delete(new MyRecordImpl(jso));
     assertTrue(deltaValueStore.isChanged());

@@ -153,7 +181,8 @@
   }

   public void testUpdate() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
     deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
         "harry");
     assertTrue(deltaValueStore.isChanged());
@@ -163,7 +192,8 @@
   }

   public void testUpdateDelete() {
- DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(valueStore, valueStore.map);
+    DeltaValueStoreJsonImpl deltaValueStore = new DeltaValueStoreJsonImpl(
+        valueStore, requestFactory);
     deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
         "harry");
     assertTrue(deltaValueStore.isChanged());
@@ -173,18 +203,6 @@
     assertTrue(deltaValueStore.isChanged());
testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.DELETE);
   }
-
-  public void testValidation() {
- ValueStoreJsonImpl dummyValueStore = new ValueStoreJsonImpl(null, null); - DeltaValueStore deltaValueStore = new DeltaValueStoreJsonImpl(dummyValueStore, null);
-
-    try {
-      deltaValueStore.addValidation();
-      fail("Should throw an UnsupportedOperationException");
-    } catch (UnsupportedOperationException ex) {
-      // expected
-    }
-  }

   private JSONObject testAndGetChangeRecord(String jsonString,
       WriteOperation currentWriteOperation) {

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

Reply via email to