Introduces RequestFactory interface and "tool generated"
interface ExpenseRequestFactory. Moves old
ExpenseRequestFactory class to become "code generated"
ExpenseRequestFactoryImpl, in new package gen.
Introduces @LongString and @ServerType annotations
Various other renames: Entity > EntityRef, and Ref
suffix added to clients side entities to avoid
confusion with server side.
Lots of checkstyle
Review at http://gwt-code-reviews.appspot.com/200801
Review by: amitmanjhi@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7726 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java b/bikeshed/src/com/google/gwt/requestfactory/shared/EntityRef.java
similarity index 78%
rename from bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java
rename to bikeshed/src/com/google/gwt/requestfactory/shared/EntityRef.java
index 629132f..f4af87f 100644
--- a/bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/EntityRef.java
@@ -22,14 +22,12 @@
*
* @param <E>
*/
-public interface Entity<E extends Entity<E>> {
+public interface EntityRef<E extends EntityRef<E>> {
+ /**
+ * @return a reference to a property of this entity
+ */
+ <V> FieldRef<E, V> getFieldRef(Property<E, V> property);
Object getId();
+
Comparable<?> getVersion();
-
- <V> Slot<E, V> slot(Property<E, V> property);
-
- // TODO(rjrjr) Possible?
-// <V> Path<E, V> through(Property<E, V> property);
-//
-// <V> Path<E, V> through(Path<E, V> property);
}
diff --git a/bikeshed/src/com/google/gwt/requestfactory/shared/Slot.java b/bikeshed/src/com/google/gwt/requestfactory/shared/FieldRef.java
similarity index 91%
rename from bikeshed/src/com/google/gwt/requestfactory/shared/Slot.java
rename to bikeshed/src/com/google/gwt/requestfactory/shared/FieldRef.java
index 6ee491d..085bc82 100644
--- a/bikeshed/src/com/google/gwt/requestfactory/shared/Slot.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/FieldRef.java
@@ -23,11 +23,11 @@
* @param <E> Entity
* @param <V> Value
*/
-public class Slot<E extends Entity<E>, V> {
+public class FieldRef<E extends EntityRef<E>, V> {
private final E entity;
private final Property<E, V> property;
- public Slot(E entity, Property<E, V> property) {
+ public FieldRef(E entity, Property<E, V> property) {
assert null != entity;
assert null != property;
this.entity = entity;
@@ -47,7 +47,7 @@
if (getClass() != obj.getClass()) {
return false;
}
- Slot<E, V> other = (Slot<E, V>) obj;
+ FieldRef<E, V> other = (FieldRef<E, V>) obj;
if (!entity.getId().equals(other.entity.getId())) {
return false;
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java b/bikeshed/src/com/google/gwt/requestfactory/shared/LongString.java
similarity index 77%
copy from bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
copy to bikeshed/src/com/google/gwt/requestfactory/shared/LongString.java
index 1e2979f7..ad427a8 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/LongString.java
@@ -13,11 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.requestfactory.shared;
/**
- * Represents the MethodName.
+ * Marks a String {@link Property} that represents a long server side.
*/
-public enum MethodName {
- FIND_ALL_EMPLOYEES, FIND_EMPLOYEE, FIND_REPORTS_BY_EMPLOYEE, SYNC,
+public @interface LongString {
+
}
diff --git a/bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java b/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
similarity index 61%
copy from bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java
copy to bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
index 629132f..f8657dd 100644
--- a/bikeshed/src/com/google/gwt/requestfactory/shared/Entity.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
@@ -1,12 +1,12 @@
/*
* 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
@@ -15,21 +15,19 @@
*/
package com.google.gwt.requestfactory.shared;
-import com.google.gwt.valuestore.shared.Property;
+import com.google.gwt.valuestore.shared.ValueStore;
+import com.google.gwt.valuestore.shared.Values;
+
+import java.util.List;
/**
- * Client side proxy object for server side entity.
- *
- * @param <E>
+ * Marker interface for the RequestFactory code generator.
*/
-public interface Entity<E extends Entity<E>> {
- Object getId();
- Comparable<?> getVersion();
-
- <V> Slot<E, V> slot(Property<E, V> property);
-
- // TODO(rjrjr) Possible?
-// <V> Path<E, V> through(Property<E, V> property);
-//
-// <V> Path<E, V> through(Path<E, V> property);
+public interface RequestFactory {
+
+ public ValueStore getValueStore();
+
+ // TODO actually a DeltaValueStore, interim hack
+ public SyncRequest syncRequest(final List<Values<?>> deltaValueStore);
+
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java b/bikeshed/src/com/google/gwt/requestfactory/shared/ServerType.java
similarity index 77%
copy from bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
copy to bikeshed/src/com/google/gwt/requestfactory/shared/ServerType.java
index 81faffa..122ebaf 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/ServerType.java
@@ -13,11 +13,14 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.requestfactory.shared;
+
/**
- * Request to commit CRUD operations accumulated in a DeltaValueStore.
+ * Identifies the server domain class represented by an {@link EntityRef}.
*/
-public interface SyncRequest {
- void fire();
+public @interface ServerType {
+
+ Class<?> value();
+
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java b/bikeshed/src/com/google/gwt/requestfactory/shared/SyncRequest.java
similarity index 93%
rename from bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
rename to bikeshed/src/com/google/gwt/requestfactory/shared/SyncRequest.java
index 81faffa..cd79676 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/SyncRequest.java
+++ b/bikeshed/src/com/google/gwt/requestfactory/shared/SyncRequest.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.requestfactory.shared;
/**
* Request to commit CRUD operations accumulated in a DeltaValueStore.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/Expenses.gwt.xml b/bikeshed/src/com/google/gwt/sample/expenses/Expenses.gwt.xml
index 25840a8..0d663ad 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/Expenses.gwt.xml
+++ b/bikeshed/src/com/google/gwt/sample/expenses/Expenses.gwt.xml
@@ -16,5 +16,6 @@
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
+ <source path='gen'/>
</module>
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/client/EmployeeList.java b/bikeshed/src/com/google/gwt/sample/expenses/client/EmployeeList.java
index e0d1021..a5370da 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/client/EmployeeList.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/client/EmployeeList.java
@@ -17,7 +17,7 @@
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
-import com.google.gwt.sample.expenses.shared.Employee;
+import com.google.gwt.sample.expenses.shared.EmployeeRef;
import com.google.gwt.user.client.ui.HasValueList;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.valuestore.shared.Values;
@@ -28,22 +28,22 @@
* Manages the Employee ListBox. This shoudl grow into a proper View, with a
* corresponding Presenter factored out of {@link Expenses}
*/
-public final class EmployeeList implements HasValueList<Values<Employee>> {
+public final class EmployeeList implements HasValueList<Values<EmployeeRef>> {
interface Listener {
- void onEmployeeSelected(Employee e);
+ void onEmployeeSelected(EmployeeRef e);
}
private final class MyChangeHandler implements ChangeHandler {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
- Values<Employee> values = employeeValues.get(selectedIndex);
- Employee e = values.getPropertyHolder();
+ Values<EmployeeRef> values = employeeValues.get(selectedIndex);
+ EmployeeRef e = values.getPropertyHolder();
listener.onEmployeeSelected(e);
}
}
private final ListBox listBox;
- private List<Values<Employee>> employeeValues;
+ private List<Values<EmployeeRef>> employeeValues;
private Listener listener;
/**
@@ -56,7 +56,7 @@
}
public void editValueList(boolean replace, int index,
- List<Values<Employee>> newValues) {
+ List<Values<EmployeeRef>> newValues) {
throw new UnsupportedOperationException();
}
@@ -64,12 +64,12 @@
this.listener = listener;
}
- public void setValueList(List<Values<Employee>> newValues) {
+ public void setValueList(List<Values<EmployeeRef>> newValues) {
this.employeeValues = newValues;
listBox.clear();
for (int i = 0; i < employeeValues.size(); i++) {
- Values<Employee> values = employeeValues.get(i);
- listBox.addItem(values.get(Employee.DISPLAY_NAME));
+ Values<EmployeeRef> values = employeeValues.get(i);
+ listBox.addItem(values.get(EmployeeRef.DISPLAY_NAME));
}
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java b/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
index a5b8a87..0614d31 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/client/Expenses.java
@@ -17,10 +17,11 @@
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.sample.expenses.shared.Employee;
-import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
-import com.google.gwt.sample.expenses.shared.Report;
+import com.google.gwt.sample.expenses.gen.ExpenseRequestFactoryImpl;
+import com.google.gwt.sample.expenses.shared.EmployeeRef;
+import com.google.gwt.sample.expenses.shared.ReportRef;
import com.google.gwt.user.client.ui.RootLayoutPanel;
+import com.google.gwt.valuestore.client.ValuesImpl;
import com.google.gwt.valuestore.shared.Values;
import java.util.ArrayList;
@@ -38,7 +39,7 @@
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
- private final ExpenseRequestFactory requestFactory = GWT.create(ExpenseRequestFactory.class);
+ private final ExpenseRequestFactoryImpl requestFactory = GWT.create(ExpenseRequestFactoryImpl.class);
/**
* This is the entry point method.
@@ -53,9 +54,9 @@
shell.setListener(new Shell.Listener() {
public void setFirstPurpose(String purpose) {
- ValuesImpl<Report> reportValues = (ValuesImpl<Report> )shell.getValues().get(0);
- reportValues.setString(Report.PURPOSE, purpose);
- List<Values<Report>> deltaValueStore = new ArrayList<Values<Report>>();
+ ValuesImpl<ReportRef> reportValues = (ValuesImpl<ReportRef>) shell.getValues().get(0);
+ reportValues.setString(ReportRef.PURPOSE, purpose);
+ List<Values<?>> deltaValueStore = new ArrayList<Values<?>>();
deltaValueStore.add(reportValues);
requestFactory.syncRequest(deltaValueStore).fire();
@@ -63,17 +64,17 @@
});
employees.setListener(new EmployeeList.Listener() {
- public void onEmployeeSelected(Employee e) {
+ public void onEmployeeSelected(EmployeeRef e) {
requestFactory.reportRequest().//
- findReportsByEmployee(e.slot(Employee.ID)).//
- forProperty(Report.CREATED).//
- forProperty(Report.PURPOSE).//
+ findReportsByEmployee(e.getFieldRef(EmployeeRef.ID)).//
+ forProperty(ReportRef.CREATED).//
+ forProperty(ReportRef.PURPOSE).//
to(shell).//
fire();
}
});
requestFactory.employeeRequest().findAllEmployees().forProperty(
- Employee.DISPLAY_NAME).forProperty(Employee.USER_NAME).to(employees).fire();
+ EmployeeRef.DISPLAY_NAME).forProperty(EmployeeRef.USER_NAME).to(employees).fire();
}
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java b/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
index bab2c30..466b1c1 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/client/Shell.java
@@ -25,7 +25,7 @@
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.i18n.client.DateTimeFormat;
-import com.google.gwt.sample.expenses.shared.Report;
+import com.google.gwt.sample.expenses.shared.ReportRef;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
@@ -45,7 +45,7 @@
* UI shell for expenses sample app. A horrible clump of stuff that should be
* refactored into proper MVP pieces.
*/
-public class Shell extends Composite implements HasValueList<Values<Report>> {
+public class Shell extends Composite implements HasValueList<Values<ReportRef>> {
interface Listener {
void setFirstPurpose(String purpose);
}
@@ -53,9 +53,10 @@
interface ShellUiBinder extends UiBinder<Widget, Shell> {
}
+ private static ShellUiBinder uiBinder = GWT.create(ShellUiBinder.class);
+
private Listener listener;
- private static ShellUiBinder uiBinder = GWT.create(ShellUiBinder.class);
@UiField
Element error;
@UiField
@@ -68,18 +69,18 @@
TextBox purpose;
@UiField
Button save;
- private List<Values<Report>> values;
+ private List<Values<ReportRef>> values;
public Shell() {
initWidget(uiBinder.createAndBindUi(this));
}
public void editValueList(boolean replace, int index,
- List<Values<Report>> newValues) {
+ List<Values<ReportRef>> newValues) {
throw new UnsupportedOperationException();
}
- public List<Values<Report>> getValues() {
+ public List<Values<ReportRef>> getValues() {
return values;
}
@@ -97,7 +98,7 @@
this.listener = listener;
}
- public void setValueList(List<Values<Report>> newValues) {
+ public void setValueList(List<Values<ReportRef>> newValues) {
this.values = newValues;
int r = 1; // skip header
NodeList<TableRowElement> tableRows = table.getRows();
@@ -106,10 +107,10 @@
purpose.setEnabled(enabled);
save.setEnabled(enabled);
for (int i = 0; i < newValues.size(); i++) {
- Values<Report> valueRow = newValues.get(i);
+ Values<ReportRef> valueRow = newValues.get(i);
if (i == 0) {
- purpose.setText(valueRow.get(Report.PURPOSE));
+ purpose.setText(valueRow.get(ReportRef.PURPOSE));
}
if (r < tableRows.getLength()) {
reuseRow(r, tableRows, valueRow);
@@ -117,7 +118,7 @@
TableRowElement tableRow = Document.get().createTRElement();
TableCellElement tableCell = Document.get().createTDElement();
- tableCell.setInnerText(renderDate(valueRow, Report.CREATED));
+ tableCell.setInnerText(renderDate(valueRow, ReportRef.CREATED));
tableRow.appendChild(tableCell);
tableCell = Document.get().createTDElement();
@@ -125,7 +126,7 @@
tableRow.appendChild(tableCell);
tableCell = Document.get().createTDElement();
- tableCell.setInnerText(valueRow.get(Report.PURPOSE));
+ tableCell.setInnerText(valueRow.get(ReportRef.PURPOSE));
tableRow.appendChild(tableCell);
table.appendChild(tableRow);
@@ -151,11 +152,11 @@
* @param valueRow
*/
private void reuseRow(int r, NodeList<TableRowElement> tableRows,
- Values<Report> valueRow) {
+ Values<ReportRef> valueRow) {
TableRowElement tableRow = tableRows.getItem(r);
NodeList<TableCellElement> tableCells = tableRow.getCells();
// tableCells.getItem(0).setInnerText(valueRow.get(Report.CREATED).toString());
- tableCells.getItem(2).setInnerText(valueRow.get(Report.PURPOSE));
+ tableCells.getItem(2).setInnerText(valueRow.get(ReportRef.PURPOSE));
}
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
similarity index 70%
rename from bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java
rename to bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
index c3d066a..bad2912 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRequests.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.sample.expenses.gen;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.http.client.Request;
@@ -22,8 +22,10 @@
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.requestfactory.shared.EntityListRequest;
-import com.google.gwt.sample.expenses.client.ValuesImpl;
+import com.google.gwt.sample.expenses.shared.EmployeeRef;
+import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.valuestore.client.ValuesImpl;
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.ValueStore;
import com.google.gwt.valuestore.shared.Values;
@@ -32,16 +34,16 @@
import java.util.List;
/**
- * "Generated" from static methods of {@link com.google.gwt.sample.expenses.domain.Employee}.
+ * "Generated" from static methods of {@link com.google.gwt.sample.expenses.server.domain.Employee}.
*/
-public class EmployeeRequests {
+public class EmployeeRequestImpl implements ExpenseRequestFactory.EmployeeRequest {
- public EmployeeRequests(ValueStore values) {
+ public EmployeeRequestImpl(ValueStore values) {
}
- public EntityListRequest<Employee> findAllEmployees() {
- return new EntityListRequest<Employee>() {
- private HasValueList<Values<Employee>> watcher;
+ public EntityListRequest<EmployeeRef> findAllEmployees() {
+ return new EntityListRequest<EmployeeRef>() {
+ private HasValueList<Values<EmployeeRef>> watcher;
public void fire() {
@@ -59,15 +61,15 @@
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
String text = response.getText();
- JsArray<ValuesImpl<Employee>> valueArray = ValuesImpl.arrayFromJson(text);
+ JsArray<ValuesImpl<EmployeeRef>> valueArray = ValuesImpl.arrayFromJson(text);
// Handy for FireBug snooping
// Document.get().getBody().setPropertyJSO("foo", valueArray);
- List<Values<Employee>> valueList = new ArrayList<Values<Employee>>(
+ List<Values<EmployeeRef>> valueList = new ArrayList<Values<EmployeeRef>>(
valueArray.length());
for (int i = 0; i < valueArray.length(); i++) {
- ValuesImpl<Employee> values = valueArray.get(i);
- values.setPropertyHolder(new Employee(values.get(Employee.ID),
- values.get(Employee.VERSION)));
+ ValuesImpl<EmployeeRef> values = valueArray.get(i);
+ values.setPropertyHolder(new EmployeeRef(values.get(EmployeeRef.ID),
+ values.get(EmployeeRef.VERSION)));
valueList.add(values);
}
watcher.setValueList(valueList);
@@ -88,13 +90,13 @@
// values.subscribe(watcher, future, properties);
}
- public EntityListRequest<Employee> forProperty(
- Property<Employee, ?> property) {
+ public EntityListRequest<EmployeeRef> forProperty(
+ Property<EmployeeRef, ?> property) {
return this;
}
- public EntityListRequest<Employee> to(
- HasValueList<Values<Employee>> watcher) {
+ public EntityListRequest<EmployeeRef> to(
+ HasValueList<Values<EmployeeRef>> watcher) {
this.watcher = watcher;
return this;
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
new file mode 100644
index 0000000..624aeec
--- /dev/null
+++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
@@ -0,0 +1,145 @@
+/*
+ * 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.sample.expenses.gen;
+
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.requestfactory.shared.SyncRequest;
+import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.valuestore.client.ValuesImpl;
+import com.google.gwt.valuestore.shared.DeltaValueStore;
+import com.google.gwt.valuestore.shared.Property;
+import com.google.gwt.valuestore.shared.ValueStore;
+import com.google.gwt.valuestore.shared.Values;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * "Generated" factory for requests against
+ * com.google.gwt.sample.expenses.domain.
+ * <p>
+ * IRL would be an interface that was generated by a JPA-savvy script, and the
+ * following implementation would in turn be generated by a call to
+ * GWT.create(ExpenseRequestFactory.class)
+ */
+public class ExpenseRequestFactoryImpl implements ExpenseRequestFactory {
+ public final ValueStore values = new ValueStore() {
+
+ public void addValidation() {
+ // TODO Auto-generated method stub
+ }
+
+ public DeltaValueStore edit() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner,
+ Property<T, V> property) {
+ // TODO Auto-generated method stub
+ }
+
+ public <T, V> void subscribe(HasValueList<Values<T>> watcher,
+ T propertyOwner, Set<Property<T, ?>> properties) {
+ // TODO Auto-generated method stub
+ }
+
+ };
+
+ public EmployeeRequest employeeRequest() {
+ return new EmployeeRequestImpl(values);
+ }
+
+ public EmployeeRequest employeeRequest(DeltaValueStore deltas) {
+ return new EmployeeRequestImpl(deltas);
+ }
+
+ public ValueStore getValueStore() {
+ return values;
+ }
+
+ public ReportRequest reportRequest() {
+ return new ReportRequestImpl(values);
+ }
+
+ public ReportRequest reportRequest(DeltaValueStore deltas) {
+ return new ReportRequestImpl(deltas);
+ }
+
+ /**
+ * @param deltaValueStore
+ * @return
+ */
+ public SyncRequest syncRequest(final List<Values<?>> deltaValueStore) {
+ return new SyncRequest() {
+
+ public void fire() {
+
+ // TODO: need some way to track that this request has been issued so that
+ // we don't issue another request that arrives while we are waiting for
+ // the response.
+ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
+ "/expenses/data?methodName=" + MethodName.SYNC.name());
+
+ StringBuilder requestData = new StringBuilder("{");
+ boolean first = true;
+ for (Values<?> v : deltaValueStore) {
+ ValuesImpl<?> impl = (ValuesImpl<?>)v;
+ if (first) {
+ first = false;
+ } else {
+ requestData.append(",");
+ }
+ requestData.append(impl.toJson());
+ }
+ requestData.append("}");
+
+ builder.setRequestData(requestData.toString());
+ builder.setCallback(new RequestCallback() {
+
+ public void onError(Request request, Throwable exception) {
+ // shell.error.setInnerText(SERVER_ERROR);
+ }
+
+ public void onResponseReceived(Request request, Response response) {
+ if (200 == response.getStatusCode()) {
+ String text = response.getText();
+ } else {
+ // shell.error.setInnerText(SERVER_ERROR + " ("
+ // + response.getStatusText() + ")");
+ }
+ }
+ });
+
+ try {
+ builder.send();
+ } catch (RequestException e) {
+ // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() +
+ // ")");
+ }
+
+ // values.subscribe(watcher, future, properties);
+ }
+
+ };
+ }
+}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/MethodName.java
similarity index 93%
rename from bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
rename to bikeshed/src/com/google/gwt/sample/expenses/gen/MethodName.java
index 1e2979f7..662287e 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/MethodName.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/MethodName.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.sample.expenses.gen;
/**
* Represents the MethodName.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRequests.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
similarity index 66%
rename from bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRequests.java
rename to bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
index 72a0704..4eda33b 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRequests.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.shared;
+package com.google.gwt.sample.expenses.gen;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.http.client.Request;
@@ -22,9 +22,12 @@
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.requestfactory.shared.EntityListRequest;
-import com.google.gwt.requestfactory.shared.Slot;
-import com.google.gwt.sample.expenses.client.ValuesImpl;
+import com.google.gwt.requestfactory.shared.FieldRef;
+import com.google.gwt.sample.expenses.shared.EmployeeRef;
+import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
+import com.google.gwt.sample.expenses.shared.ReportRef;
import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.valuestore.client.ValuesImpl;
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.ValueStore;
import com.google.gwt.valuestore.shared.Values;
@@ -36,19 +39,19 @@
/**
* "Generated" from static methods of
- * {@link com.google.gwt.sample.expenses.domain.Employee}.
+ * {@link com.google.gwt.sample.expenses.server.domain.Employee}.
*/
-public class ReportRequests {
+public class ReportRequestImpl implements ExpenseRequestFactory.ReportRequest {
- public ReportRequests(ValueStore values) {
+ public ReportRequestImpl(ValueStore values) {
}
- public EntityListRequest<Report> findReportsByEmployee(
- final Slot<Employee, String> id) {
+ public EntityListRequest<ReportRef> findReportsByEmployee(
+ final FieldRef<EmployeeRef, String> id) {
- return new EntityListRequest<Report>() {
- Set<Property<Report, ?>> properties = new HashSet<Property<Report, ?>>();
- private HasValueList<Values<Report>> watcher;
+ return new EntityListRequest<ReportRef>() {
+ Set<Property<ReportRef, ?>> properties = new HashSet<Property<ReportRef, ?>>();
+ private HasValueList<Values<ReportRef>> watcher;
public void fire() {
@@ -68,14 +71,14 @@
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
String text = response.getText();
- JsArray<ValuesImpl<Report>> valueArray = ValuesImpl.arrayFromJson(text);
- List<Values<Report>> valueList = new ArrayList<Values<Report>>(
+ JsArray<ValuesImpl<ReportRef>> valueArray = ValuesImpl.arrayFromJson(text);
+ List<Values<ReportRef>> valueList = new ArrayList<Values<ReportRef>>(
valueArray.length());
for (int i = 0; i < valueArray.length(); i++) {
- ValuesImpl<Report> values = valueArray.get(i);
- String id2 = values.get(Report.ID);
- Integer version = values.get(Report.VERSION);
- values.setPropertyHolder(new Report(id2,
+ ValuesImpl<ReportRef> values = valueArray.get(i);
+ String id2 = values.get(ReportRef.ID);
+ Integer version = values.get(ReportRef.VERSION);
+ values.setPropertyHolder(new ReportRef(id2,
version));
valueList.add(values);
}
@@ -97,12 +100,12 @@
// values.subscribe(watcher, future, properties);
}
- public EntityListRequest<Report> forProperty(Property<Report, ?> property) {
+ public EntityListRequest<ReportRef> forProperty(Property<ReportRef, ?> property) {
properties.add(property);
return this;
}
- public EntityListRequest<Report> to(HasValueList<Values<Report>> watcher) {
+ public EntityListRequest<ReportRef> to(HasValueList<Values<ReportRef>> watcher) {
this.watcher = watcher;
return this;
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java b/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
index f982b98..f4ea982 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
@@ -15,9 +15,9 @@
*/
package com.google.gwt.sample.expenses.server;
-import com.google.gwt.sample.expenses.domain.Employee;
-import com.google.gwt.sample.expenses.domain.Report;
-import com.google.gwt.sample.expenses.shared.MethodName;
+import com.google.gwt.sample.expenses.gen.MethodName;
+import com.google.gwt.sample.expenses.server.domain.Employee;
+import com.google.gwt.sample.expenses.server.domain.Report;
import org.json.JSONArray;
import org.json.JSONException;
@@ -65,16 +65,16 @@
// TODO clearly there should be centralized code for these conversions
JSONObject jsonObject = new JSONObject();
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Employee.ID.getName(),
+ com.google.gwt.sample.expenses.shared.EmployeeRef.ID.getName(),
Long.toString(e.getId()));
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Employee.VERSION.getName(),
+ com.google.gwt.sample.expenses.shared.EmployeeRef.VERSION.getName(),
e.getVersion().intValue());
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Employee.USER_NAME.getName(),
+ com.google.gwt.sample.expenses.shared.EmployeeRef.USER_NAME.getName(),
e.getUserName());
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Employee.DISPLAY_NAME.getName(),
+ com.google.gwt.sample.expenses.shared.EmployeeRef.DISPLAY_NAME.getName(),
e.getDisplayName());
jsonArray.put(jsonObject);
} catch (JSONException ex) {
@@ -94,16 +94,16 @@
// TODO clearly there should be centralized code for these conversions
JSONObject jsonObject = new JSONObject();
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Employee.ID.getName(),
+ com.google.gwt.sample.expenses.shared.EmployeeRef.ID.getName(),
Long.toString(r.getId()));
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Report.VERSION.getName(),
+ com.google.gwt.sample.expenses.shared.ReportRef.VERSION.getName(),
r.getVersion().intValue());
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Report.CREATED.getName(),
+ com.google.gwt.sample.expenses.shared.ReportRef.CREATED.getName(),
Double.valueOf(r.getCreated().getTime()));
jsonObject.put(
- com.google.gwt.sample.expenses.shared.Report.PURPOSE.getName(),
+ com.google.gwt.sample.expenses.shared.ReportRef.PURPOSE.getName(),
r.getPurpose());
jsonArray.put(jsonObject);
} catch (JSONException ex) {
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/CreationVisitor.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/CreationVisitor.java
similarity index 96%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/CreationVisitor.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/CreationVisitor.java
index 20f360b..a54a51b 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/CreationVisitor.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/CreationVisitor.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Creates a new entity of the type of the receiver.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Currency.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Currency.java
similarity index 96%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Currency.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Currency.java
index 06fc66c..9f6bb31 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Currency.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Currency.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Models a type of currency.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Employee.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Employee.java
similarity index 97%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Employee.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Employee.java
index 8c211f7..6f2a79c 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Employee.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Employee.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
import java.util.List;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Entity.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Entity.java
similarity index 93%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Entity.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Entity.java
index 0883d32..5d6a107 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Entity.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Entity.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Pale imitation on the stuff JPA entities get baked into them.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/EntityVisitor.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/EntityVisitor.java
similarity index 93%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/EntityVisitor.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/EntityVisitor.java
index 38c2443..de06160 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/EntityVisitor.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/EntityVisitor.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Double dispatch mechanism to ease imitation of framework mechanisms.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/NullFieldFiller.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/NullFieldFiller.java
similarity index 97%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/NullFieldFiller.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/NullFieldFiller.java
index 3288d53..6f39fa6 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/NullFieldFiller.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/NullFieldFiller.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Does the merging that a persistence framework would have done for us. If
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipRefreshingVisitor.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipRefreshingVisitor.java
similarity index 95%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipRefreshingVisitor.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipRefreshingVisitor.java
index 146f8d5..e14b9a0 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipRefreshingVisitor.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipRefreshingVisitor.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Used by {@link Storage#get(Entity)} to refreshes fields that point to other
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipValidationVisitor.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipValidationVisitor.java
similarity index 96%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipValidationVisitor.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipValidationVisitor.java
index 4e37f5d..670a805 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/RelationshipValidationVisitor.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/RelationshipValidationVisitor.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
/**
* Used by {@link Storage#persist(Entity)} to ensure relationships are valid
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Report.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Report.java
similarity index 98%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Report.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Report.java
index 28af160..870003f 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Report.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Report.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
import java.util.Date;
import java.util.List;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/ReportItem.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/ReportItem.java
similarity index 97%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/ReportItem.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/ReportItem.java
index 09af993..f970fa7 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/ReportItem.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/ReportItem.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
import java.util.Date;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Status.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Status.java
similarity index 93%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Status.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Status.java
index 4339748..f163613 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Status.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Status.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
/**
* Expense report life cycle states.
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/domain/Storage.java b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Storage.java
similarity index 99%
rename from bikeshed/src/com/google/gwt/sample/expenses/domain/Storage.java
rename to bikeshed/src/com/google/gwt/sample/expenses/server/domain/Storage.java
index 47d3c63..6772419 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/domain/Storage.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/server/domain/Storage.java
@@ -13,7 +13,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
+
import java.util.ArrayList;
import java.util.Collections;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/Employee.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/Employee.java
deleted file mode 100644
index 063b081..0000000
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/Employee.java
+++ /dev/null
@@ -1,61 +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.sample.expenses.shared;
-
-import com.google.gwt.requestfactory.shared.Entity;
-import com.google.gwt.requestfactory.shared.Slot;
-import com.google.gwt.valuestore.shared.Property;
-
-/**
- * "Generated" proxy of {@link com.google.gwt.sample.expenses.domain.Employee
- * domain.Employee}.
- */
-public class Employee implements Entity<Employee> {
-
- public static final Property<Employee, String> ID = new Property<Employee, String>(
- Employee.class, String.class, "ID");
-
- public static final Property<Employee, String> DISPLAY_NAME = new Property<Employee, String>(
- Employee.class, String.class, "DISPLAY_NAME");
- public static final Property<Employee, Employee> SUPERVISOR = new Property<Employee, Employee>(
- Employee.class, Employee.class, "SUPERVISOR");
-
- public static final Property<Employee, String> USER_NAME = new Property<Employee, String>(
- Employee.class, String.class, "USER_NAME");
-
- public static final Property<Employee, Integer> VERSION = new Property<Employee, Integer>(
- Employee.class, Integer.class, "VERSION");
-
- private final String id;
- private final Integer version;
-
- Employee(String id, Integer version) {
- this.id = id;
- this.version = version;
- }
-
- public String getId() {
- return id;
- }
-
- public Integer getVersion() {
- return version;
- }
-
- public <V> Slot<Employee, V> slot(Property<Employee, V> property) {
- return new Slot<Employee, V>(this, property);
- }
-}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRef.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRef.java
new file mode 100644
index 0000000..d013a85
--- /dev/null
+++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeRef.java
@@ -0,0 +1,65 @@
+/*
+ * 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.sample.expenses.shared;
+
+import com.google.gwt.requestfactory.shared.EntityRef;
+import com.google.gwt.requestfactory.shared.FieldRef;
+import com.google.gwt.requestfactory.shared.LongString;
+import com.google.gwt.requestfactory.shared.ServerType;
+import com.google.gwt.valuestore.shared.Property;
+
+/**
+ * "Generated" proxy of {@link com.google.gwt.sample.expenses.server.domain.Employee
+ * domain.Employee}.
+ */
+@ServerType(com.google.gwt.sample.expenses.server.domain.Employee.class)
+public class EmployeeRef implements EntityRef<EmployeeRef> {
+
+ @LongString
+ public static final Property<EmployeeRef, String> ID = new Property<EmployeeRef, String>(
+ EmployeeRef.class, String.class, "ID");
+
+ public static final Property<EmployeeRef, String> DISPLAY_NAME = new Property<EmployeeRef, String>(
+ EmployeeRef.class, String.class, "DISPLAY_NAME");
+ public static final Property<EmployeeRef, EmployeeRef> SUPERVISOR = new Property<EmployeeRef, EmployeeRef>(
+ EmployeeRef.class, EmployeeRef.class, "SUPERVISOR");
+
+ public static final Property<EmployeeRef, String> USER_NAME = new Property<EmployeeRef, String>(
+ EmployeeRef.class, String.class, "USER_NAME");
+
+ public static final Property<EmployeeRef, Integer> VERSION = new Property<EmployeeRef, Integer>(
+ EmployeeRef.class, Integer.class, "VERSION");
+
+ private final String id;
+ private final Integer version;
+
+ public EmployeeRef(String id, Integer version) {
+ this.id = id;
+ this.version = version;
+ }
+
+ public <V> FieldRef<EmployeeRef, V> getFieldRef(Property<EmployeeRef, V> property) {
+ return new FieldRef<EmployeeRef, V>(this, property);
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
index d490d38..b9b29e7 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
+++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
@@ -15,133 +15,58 @@
*/
package com.google.gwt.sample.expenses.shared;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
-import com.google.gwt.sample.expenses.client.ValuesImpl;
-import com.google.gwt.user.client.ui.HasValue;
-import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.requestfactory.shared.EntityListRequest;
+import com.google.gwt.requestfactory.shared.FieldRef;
+import com.google.gwt.requestfactory.shared.LongString;
+import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.valuestore.shared.DeltaValueStore;
-import com.google.gwt.valuestore.shared.Property;
-import com.google.gwt.valuestore.shared.ValueStore;
-import com.google.gwt.valuestore.shared.Values;
-
-import java.util.List;
-import java.util.Set;
/**
- * "Generated" factory for requests against
- * com.google.gwt.sample.expenses.domain.
- * <p>
- * IRL would be an interface that was generated by a JPA-savvy script, and the
- * following implementation would in turn be generated by a call to
- * GWT.create(ExpenseRequestFactory.class)
+ * Generated for the service methods of
+ * com.google.gwt.sample.expenses.server.domain.
*/
-public class ExpenseRequestFactory {
- private final ValueStore values = new ValueStore() {
+public interface ExpenseRequestFactory extends RequestFactory {
- public void addValidation() {
- // TODO Auto-generated method stub
- }
+ /**
+ * Request selector.
+ */
+ interface EmployeeRequest {
- public DeltaValueStore edit() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner,
- Property<T, V> property) {
- // TODO Auto-generated method stub
- }
-
- public <T, V> void subscribe(HasValueList<Values<T>> watcher,
- T propertyOwner, Set<Property<T, ?>> properties) {
- // TODO Auto-generated method stub
- }
-
- };
-
- public EmployeeRequests employeeRequest() {
- return new EmployeeRequests(values);
- }
-
- public EmployeeRequests employeeRequest(DeltaValueStore deltas) {
- return new EmployeeRequests(deltas);
- }
-
- public ValueStore getValueStore() {
- return values;
- }
-
- public DeltaValueStore newDeltaStore() {
- return values.edit();
- }
-
- public ReportRequests reportRequest() {
- return new ReportRequests(values);
- }
-
- public ReportRequests reportRequest(DeltaValueStore deltas) {
- return new ReportRequests(deltas);
+ /**
+ * @return a request object
+ */
+ EntityListRequest<EmployeeRef> findAllEmployees();
}
/**
- * @param deltaValueStore
- * @return
+ * Request selector.
*/
- public SyncRequest syncRequest(final List<Values<Report>> deltaValueStore) {
- return new SyncRequest() {
+ interface ReportRequest {
- public void fire() {
-
- // TODO: need someway to track that this request has been issued so that
- // we don't issue another request that arrives while we are waiting for
- // the response.
- RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
- "/expenses/data?methodName=" + MethodName.SYNC.name());
-
- StringBuilder requestData = new StringBuilder("{");
- boolean first = true;
- for (Values<Report> values : deltaValueStore) {
- ValuesImpl<Report> impl = (ValuesImpl<Report>)values;
- if (first) {
- first = false;
- } else {
- requestData.append(",");
- }
- requestData.append(impl.toJson());
- }
- requestData.append("}");
-
- builder.setRequestData(requestData.toString());
- builder.setCallback(new RequestCallback() {
-
- public void onError(Request request, Throwable exception) {
- // shell.error.setInnerText(SERVER_ERROR);
- }
-
- public void onResponseReceived(Request request, Response response) {
- if (200 == response.getStatusCode()) {
- String text = response.getText();
- } else {
- // shell.error.setInnerText(SERVER_ERROR + " ("
- // + response.getStatusText() + ")");
- }
- }
- });
-
- try {
- builder.send();
- } catch (RequestException e) {
- // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() +
- // ")");
- }
-
- // values.subscribe(watcher, future, properties);
- }
-
- };
+ /**
+ * @return a request object
+ */
+ EntityListRequest<ReportRef> findReportsByEmployee(
+ @LongString FieldRef<EmployeeRef, String> id);
}
+
+ /**
+ * @return a request selector
+ */
+ EmployeeRequest employeeRequest();
+
+ /**
+ * @return a request selector based on new values
+ */
+ EmployeeRequest employeeRequest(DeltaValueStore deltas);
+
+ /**
+ * @return a request selector
+ */
+ ReportRequest reportRequest();
+
+ /**
+ * @return a request selector based on new values
+ */
+ ReportRequest reportRequest(DeltaValueStore deltas);
}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/Report.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/Report.java
deleted file mode 100644
index 67bad6e..0000000
--- a/bikeshed/src/com/google/gwt/sample/expenses/shared/Report.java
+++ /dev/null
@@ -1,61 +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.sample.expenses.shared;
-
-import com.google.gwt.requestfactory.shared.Entity;
-import com.google.gwt.requestfactory.shared.Slot;
-import com.google.gwt.valuestore.shared.Property;
-
-import java.util.Date;
-
-/**
- * "Generated" proxy of {@link com.google.gwt.sample.expenses.domain.Report
- * domain.Report}.
- */
-public class Report implements Entity<Report> {
-
- public static final Property<Report, String> ID = new Property<Report, String>(
- Report.class, String.class, "ID");
-
- public static final Property<Report, Integer> VERSION = new Property<Report, Integer>(
- Report.class, Integer.class, "VERSION");
-
- public static final Property<Report, Date> CREATED = new Property<Report, Date>(
- Report.class, Date.class, "CREATED");
-
- public static final Property<Report, String> PURPOSE = new Property<Report, String>(
- Report.class, String.class, "PURPOSE");
-
- private final String id;
- private final Integer version;
-
- Report(String id, Integer version) {
- this.id = id;
- this.version = version;
- }
-
- public String getId() {
- return id;
- }
-
- public Integer getVersion() {
- return version;
- }
-
- public <V> Slot<Report, V> slot(Property<Report, V> property) {
- return new Slot<Report, V>(this, property);
- }
-}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRef.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRef.java
new file mode 100644
index 0000000..dcf9020
--- /dev/null
+++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportRef.java
@@ -0,0 +1,65 @@
+/*
+ * 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.sample.expenses.shared;
+
+import com.google.gwt.requestfactory.shared.EntityRef;
+import com.google.gwt.requestfactory.shared.FieldRef;
+import com.google.gwt.requestfactory.shared.LongString;
+import com.google.gwt.requestfactory.shared.ServerType;
+import com.google.gwt.valuestore.shared.Property;
+
+import java.util.Date;
+
+/**
+ * "Generated" proxy of
+ * {@link com.google.gwt.sample.expenses.server.domain.Report domain.Report}.
+ */
+@ServerType(com.google.gwt.sample.expenses.server.domain.Report.class)
+public class ReportRef implements EntityRef<ReportRef> {
+
+ @LongString
+ public static final Property<ReportRef, String> ID = new Property<ReportRef, String>(
+ ReportRef.class, String.class, "ID");
+
+ public static final Property<ReportRef, Integer> VERSION = new Property<ReportRef, Integer>(
+ ReportRef.class, Integer.class, "VERSION");
+
+ public static final Property<ReportRef, Date> CREATED = new Property<ReportRef, Date>(
+ ReportRef.class, Date.class, "CREATED");
+
+ public static final Property<ReportRef, String> PURPOSE = new Property<ReportRef, String>(
+ ReportRef.class, String.class, "PURPOSE");
+
+ private final String id;
+ private final Integer version;
+
+ public ReportRef(String id, Integer version) {
+ this.id = id;
+ this.version = version;
+ }
+
+ public <V> FieldRef<ReportRef, V> getFieldRef(Property<ReportRef, V> property) {
+ return new FieldRef<ReportRef, V>(this, property);
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+}
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java b/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
similarity index 95%
rename from bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java
rename to bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
index 20cc004..5aa0ddb 100644
--- a/bikeshed/src/com/google/gwt/sample/expenses/client/ValuesImpl.java
+++ b/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.client;
+package com.google.gwt.valuestore.client;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
@@ -48,7 +48,7 @@
}
if (Date.class.equals(property.getValueType())) {
double millis = getDouble(property.getName());
- //TODO (rjrjr) bring this back when Date gets JSO friendly again
+ // TODO (rjrjr) bring this back when Date gets JSO friendly again
// if (GWT.isScript()) {
// return (V) initDate(new Date(), millis);
// } else {
@@ -60,10 +60,6 @@
return nativeGet(property);
}
- public native void setString(Property<T, String> property, String value) /*-{
- this[property.@com.google.gwt.valuestore.shared.Property::getName()()] = value;
- }-*/;
-
public native T getPropertyHolder() /*-{
return this.propertyHolder;
}-*/;
@@ -72,21 +68,8 @@
this.propertyHolder = propertyHolder;
}-*/;
- private native double getDouble(String name) /*-{
- return this[name];
- }-*/;
-
- private native int getInt(String name) /*-{
- return this[name];
- }-*/;
-
-// private native Date initDate(Date date, double millis) /*-{
-// date.@java.util.Date::init(D)(millis);
-// return date;
-// }-*/;
-
- private native <V, P extends Property<T, V>> V nativeGet(P property) /*-{
- return this[property.@com.google.gwt.valuestore.shared.Property::getName()()];
+ public native void setString(Property<T, String> property, String value) /*-{
+ this[property.@com.google.gwt.valuestore.shared.Property::getName()()] = value;
}-*/;
/**
@@ -101,4 +84,21 @@
}
return output;
}-*/;
+
+ private native double getDouble(String name) /*-{
+ return this[name];
+ }-*/;
+
+// private native Date initDate(Date date, double millis) /*-{
+// date.@java.util.Date::init(D)(millis);
+// return date;
+// }-*/;
+
+ private native int getInt(String name) /*-{
+ return this[name];
+ }-*/;
+
+ private native <V, P extends Property<T, V>> V nativeGet(P property) /*-{
+ return this[property.@com.google.gwt.valuestore.shared.Property::getName()()];
+ }-*/;
}
diff --git a/bikeshed/src/com/google/gwt/valuestore/shared/ValueStore.java b/bikeshed/src/com/google/gwt/valuestore/shared/ValueStore.java
index 45bca44..3a80740 100644
--- a/bikeshed/src/com/google/gwt/valuestore/shared/ValueStore.java
+++ b/bikeshed/src/com/google/gwt/valuestore/shared/ValueStore.java
@@ -25,7 +25,6 @@
* to particular sets of values.
*/
public interface ValueStore {
-
/**
* Most validations are per field or per id and set via annotation. Note that
* validations are only actually enforced by in {@link DeltaValueStore}
diff --git a/bikeshed/test/com/google/gwt/sample/expenses/domain/CreationVisitorTest.java b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/CreationVisitorTest.java
similarity index 96%
rename from bikeshed/test/com/google/gwt/sample/expenses/domain/CreationVisitorTest.java
rename to bikeshed/test/com/google/gwt/sample/expenses/server/domain/CreationVisitorTest.java
index 5993721..509dea5 100644
--- a/bikeshed/test/com/google/gwt/sample/expenses/domain/CreationVisitorTest.java
+++ b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/CreationVisitorTest.java
@@ -13,10 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
import junit.framework.TestCase;
+
/**
* Eponymous test class.
*/
diff --git a/bikeshed/test/com/google/gwt/sample/expenses/domain/EntityTester.java b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/EntityTester.java
similarity index 94%
rename from bikeshed/test/com/google/gwt/sample/expenses/domain/EntityTester.java
rename to bikeshed/test/com/google/gwt/sample/expenses/server/domain/EntityTester.java
index 2a12c15..b6c03cc 100644
--- a/bikeshed/test/com/google/gwt/sample/expenses/domain/EntityTester.java
+++ b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/EntityTester.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
class EntityTester {
Currency currency;
diff --git a/bikeshed/test/com/google/gwt/sample/expenses/domain/NullFieldFillerTest.java b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/NullFieldFillerTest.java
similarity index 98%
rename from bikeshed/test/com/google/gwt/sample/expenses/domain/NullFieldFillerTest.java
rename to bikeshed/test/com/google/gwt/sample/expenses/server/domain/NullFieldFillerTest.java
index f94bcfc..0b94645 100644
--- a/bikeshed/test/com/google/gwt/sample/expenses/domain/NullFieldFillerTest.java
+++ b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/NullFieldFillerTest.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
import junit.framework.TestCase;
diff --git a/bikeshed/test/com/google/gwt/sample/expenses/domain/StorageTest.java b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/StorageTest.java
similarity index 98%
rename from bikeshed/test/com/google/gwt/sample/expenses/domain/StorageTest.java
rename to bikeshed/test/com/google/gwt/sample/expenses/server/domain/StorageTest.java
index 8e14009..7d97cc4 100644
--- a/bikeshed/test/com/google/gwt/sample/expenses/domain/StorageTest.java
+++ b/bikeshed/test/com/google/gwt/sample/expenses/server/domain/StorageTest.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.sample.expenses.domain;
+package com.google.gwt.sample.expenses.server.domain;
import junit.framework.TestCase;