No more massive copy paste between our request objects. Introduces the abstract classes for RequestFactory and its request object. Also some clean up to make it more clear what classes will come from GWT code generators and what will come from pre-compilation tools. Part of this moves HandleManager to a more appropriate package, since it won't be generated. Review at http://gwt-code-reviews.appspot.com/250801 Review by: amitmanjhi@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7759 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/src/com/google/gwt/requestfactory/client/impl/AbstractListJsonRequestObject.java b/bikeshed/src/com/google/gwt/requestfactory/client/impl/AbstractListJsonRequestObject.java new file mode 100644 index 0000000..5e9dc66 --- /dev/null +++ b/bikeshed/src/com/google/gwt/requestfactory/client/impl/AbstractListJsonRequestObject.java
@@ -0,0 +1,110 @@ +/* + * 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.requestfactory.client.impl; + +import com.google.gwt.core.client.JsArray; +import com.google.gwt.requestfactory.shared.EntityKey; +import com.google.gwt.requestfactory.shared.RequestFactory; +import com.google.gwt.requestfactory.shared.RequestFactory.Service; +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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Abstract implementation of {@link RequestFactory.RequestObject} for methods + * returning lists of entities. + * + * @param <T> the type of entities returned + * @param <R> this request type + */ +public abstract class AbstractListJsonRequestObject<T extends EntityKey<T>, R extends AbstractListJsonRequestObject<T, R>> + implements RequestFactory.RequestObject { + + private final T key; + private final Service requestService; + @SuppressWarnings("unused") + // That's next + private final ValueStore valueStore; + + private final Set<Property<T, ?>> properties = new HashSet<Property<T, ?>>(); + + private HasValueList<Values<T>> watcher; + + public AbstractListJsonRequestObject(T key, ValueStore valueStore, + RequestFactory.Service requestService) { + this.requestService = requestService; + this.valueStore = valueStore; + this.key = key; + } + + public void fire() { + requestService.fire(this); + } + + public R forProperties(Collection<Property<T, ?>> properties) { + for (Property<T, ?> property : properties) { + forProperty(property); + } + return getThis(); + } + + public R forProperty(Property<T, ?> property) { + properties.add(property); + return getThis(); + } + + /** + * @return the properties + */ + public Set<Property<T, ?>> getProperties() { + return properties; + } + + public void handleResponseText(String text) { + // DeltaValueStore deltaStore = valueStore.edit(); + JsArray<ValuesImpl<T>> valueArray = ValuesImpl.arrayFromJson(text); + List<Values<T>> valueList = new ArrayList<Values<T>>(valueArray.length()); + for (int i = 0; i < valueArray.length(); i++) { + ValuesImpl<T> values = valueArray.get(i); + values.setPropertyHolder(key); + // deltaStore.setValue(propertyHolder, properties, values); + valueList.add(values); + } + + // valueStore.subscribe(watcher, valueList, properties); + // deltaStore.commit(); + watcher.setValueList(valueList); + } + + public R to(HasValueList<Values<T>> watcher) { + this.watcher = watcher; + return getThis(); + } + + /** + * Subclasses must override to return {@code this}, to allow builder-style + * methods to do the same. + */ + protected abstract R getThis(); +}
diff --git a/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java b/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java new file mode 100644 index 0000000..3cc12b4 --- /dev/null +++ b/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
@@ -0,0 +1,155 @@ +/* + * 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.requestfactory.client.impl; + +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.RequestFactory; +import com.google.gwt.requestfactory.shared.SyncRequest; +import com.google.gwt.sample.expenses.gen.MethodName; +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; + +/** + * Base implementation of RequestFactory. + */ +public class RequestFactoryJsonImpl implements RequestFactory, + RequestFactory.Service { + + private final ValueStore valueStore = new ValueStore() { + + public void addValidation() { + throw new UnsupportedOperationException(); + } + + public DeltaValueStore edit() { + throw new UnsupportedOperationException(); + } + + public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner, + Property<T, V> property) { + throw new UnsupportedOperationException(); + } + + public <T, V> void subscribe(HasValueList<Values<T>> watcher, + T propertyOwner, Set<Property<T, ?>> properties) { + throw new UnsupportedOperationException(); + } + + }; + + @SuppressWarnings("deprecation") + public void fire(final RequestObject requestObject) { + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, + requestObject.getRequestUrl()); + 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(); + requestObject.handleResponseText(text); + } else { + // shell.error.setInnerText(SERVER_ERROR + " (" + // + response.getStatusText() + ")"); + } + } + + }); + + try { + builder.send(); + } catch (RequestException e) { + // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() + + // ")"); + } + } + + public ValueStore getValueStore() { + return valueStore; + } + + /** + * @param deltaValueStore + * @return + */ + public SyncRequest syncRequest(final List<Values<?>> deltaValueStore) { + return new SyncRequest() { + + public void fire() { + + 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(); + // parse the return value. + + // publish this value to all subscribers that are interested. + } 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/requestfactory/shared/EntityListRequest.java b/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java index 6ce47da..c4deea1 100644 --- a/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java +++ b/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java
@@ -27,9 +27,7 @@ * * @param <E> The type held by the returned list */ -public interface EntityListRequest<E> { - void fire(); - +public interface EntityListRequest<E> extends RequestFactory.RequestObject { EntityListRequest<E> forProperties(Collection<Property<E, ?>> properties); EntityListRequest<E> forProperty(Property<E, ?> property);
diff --git a/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java b/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java index 155e02f..ac379ef 100644 --- a/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.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 @@ -25,9 +25,32 @@ */ public interface RequestFactory { + /** + * Implemented by the request objects created by this factory. + */ + interface RequestObject { + void fire(); + + String getRequestData(String data); + + /** + * @deprecated Here only until we can move everything into the post data + */ + String getRequestUrl(); + + void handleResponseText(String responseText); + } + + /** + * Implemented by the RPC service backing this factory. + */ + interface Service { + void fire(RequestObject request); + } + ValueStore getValueStore(); - // TODO actually a DeltaValueStore, interim hack + // TODO actually a DeltaValueStore, List is an interim hack SyncRequest syncRequest(final List<Values<?>> deltaValueStore); }
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/gen/UrlParameterManager.java b/bikeshed/src/com/google/gwt/requestfactory/shared/impl/UrlParameterManager.java similarity index 97% rename from bikeshed/src/com/google/gwt/sample/expenses/gen/UrlParameterManager.java rename to bikeshed/src/com/google/gwt/requestfactory/shared/impl/UrlParameterManager.java index 19a7726..fbec5c8 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/gen/UrlParameterManager.java +++ b/bikeshed/src/com/google/gwt/requestfactory/shared/impl/UrlParameterManager.java
@@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.sample.expenses.gen; +package com.google.gwt.requestfactory.shared.impl; import java.util.Map;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java index 7234314..247e48a 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
@@ -15,107 +15,55 @@ */ package com.google.gwt.sample.expenses.gen; -import com.google.gwt.core.client.JsArray; -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.client.impl.AbstractListJsonRequestObject; import com.google.gwt.requestfactory.shared.EntityListRequest; +import com.google.gwt.requestfactory.shared.RequestFactory.Service; import com.google.gwt.sample.expenses.shared.EmployeeKey; 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; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; /** - * "Generated" from static methods of {@link com.google.gwt.sample.expenses.server.domain.Employee}. + * "Code generated" implementation of {ExpenseRequestFactory.EmployeeRequest} + * <p> + * IRL this will be generated as a side effect of a call to + * GWT.create(ExpenseRequestFactory.class) */ -public class EmployeeRequestImpl implements ExpenseRequestFactory.EmployeeRequest { +public class EmployeeRequestImpl implements + ExpenseRequestFactory.EmployeeRequest { - @SuppressWarnings("unused") // TODO next step is to use it - private ValueStore valueStore; + private abstract class Request extends + AbstractListJsonRequestObject<EmployeeKey, Request> implements + EntityListRequest<EmployeeKey> { - public EmployeeRequestImpl(ValueStore valueStore) { + Request() { + super(EmployeeKey.get(), valueStore, requestService); + } + + @Override + protected Request getThis() { + return this; + } + } + + private final ValueStore valueStore; + public final Service requestService; + + public EmployeeRequestImpl(ValueStore valueStore, Service requestService) { this.valueStore = valueStore; + this.requestService = requestService; } public EntityListRequest<EmployeeKey> findAllEmployees() { - - - return new EntityListRequest<EmployeeKey>() { - private HasValueList<Values<EmployeeKey>> watcher; - private Set<Property<EmployeeKey, ?>> properties = new HashSet<Property<EmployeeKey, ?>>(); - - public void fire() { - // TODO: accumulate and batch fire requests, e.g. once batch per event loop - // TODO: cache and short circuit find requests - RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, - "/expenses/data?methodName=" + MethodName.FIND_ALL_EMPLOYEES.name()); - 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(); -// DeltaValueStore deltaStore = valueStore.edit(); - JsArray<ValuesImpl<EmployeeKey>> valueArray = ValuesImpl.arrayFromJson(text); - List<Values<EmployeeKey>> valueList = new ArrayList<Values<EmployeeKey>>( - valueArray.length()); - for (int i = 0; i < valueArray.length(); i++) { - ValuesImpl<EmployeeKey> values = valueArray.get(i); - values.setPropertyHolder(EmployeeKey.get()); -// deltaStore.setValue(propertyHolder, properties, values); - valueList.add(values); - } - -// valueStore.subscribe(watcher, valueList, properties); -// deltaStore.commit(); - watcher.setValueList(valueList); - } else { - // shell.error.setInnerText(SERVER_ERROR + " (" - // + response.getStatusText() + ")"); - } - } - }); - - try { - builder.send(); - } catch (RequestException e) { - // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() + - // ")"); - } + return new Request() { + public String getRequestData(String data) { + // TODO Dear Amit: your code here + throw new UnsupportedOperationException(); } - public EntityListRequest<EmployeeKey> forProperties( - Collection<Property<EmployeeKey, ?>> properties) { - for (Property<EmployeeKey, ?> property : properties) { - forProperty(property); - } - return this; - } - - public EntityListRequest<EmployeeKey> forProperty( - Property<EmployeeKey, ?> property) { - properties.add(property); - return this; - } - - public EntityListRequest<EmployeeKey> to( - HasValueList<Values<EmployeeKey>> watcher) { - this.watcher = watcher; - return this; + @SuppressWarnings("deprecation") + public String getRequestUrl() { + return "/expenses/data?methodName=" + + MethodName.FIND_ALL_EMPLOYEES.name(); } }; }
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java index 0862aa1..f10c596 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
@@ -15,131 +15,32 @@ */ 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.requestfactory.client.impl.RequestFactoryJsonImpl; 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 + * "Code 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 + * IRL this will 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 class ExpenseRequestFactoryImpl extends RequestFactoryJsonImpl implements + ExpenseRequestFactory { public EmployeeRequest employeeRequest() { - return new EmployeeRequestImpl(values); + return new EmployeeRequestImpl(getValueStore(), this); } public EmployeeRequest employeeRequest(DeltaValueStore deltas) { - return new EmployeeRequestImpl(deltas); - } - - public ValueStore getValueStore() { - return values; + return new EmployeeRequestImpl(deltas, this); } public ReportRequest reportRequest() { - return new ReportRequestImpl(values); + return new ReportRequestImpl(getValueStore(), this); } 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(); - // parse the return value. - - // publish this value to all subscribers that are interested. - } 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 new ReportRequestImpl(deltas, this); } }
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java b/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java index acb1ddf..cbb43c0 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
@@ -15,176 +15,74 @@ */ package com.google.gwt.sample.expenses.gen; -import com.google.gwt.core.client.JsArray; -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.client.impl.AbstractListJsonRequestObject; import com.google.gwt.requestfactory.shared.EntityListRequest; +import com.google.gwt.requestfactory.shared.RequestFactory.Service; +import com.google.gwt.requestfactory.shared.impl.UrlParameterManager; import com.google.gwt.sample.expenses.shared.EmployeeKey; import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory; import com.google.gwt.sample.expenses.shared.ReportKey; -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.ValueRef; import com.google.gwt.valuestore.shared.ValueStore; -import com.google.gwt.valuestore.shared.Values; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; /** - * "Generated" from static methods of - * {@link com.google.gwt.sample.expenses.server.domain.Employee}. + * "Code generated" implementation of {ExpenseRequestFactory.ReportRequest} + * <p> + * IRL this will be generated as a side effect of a call to + * GWT.create(ExpenseRequestFactory.class) */ public class ReportRequestImpl implements ExpenseRequestFactory.ReportRequest { - @SuppressWarnings("unused") - public ReportRequestImpl(ValueStore values) { + private abstract class Request extends + AbstractListJsonRequestObject<ReportKey, Request> implements + EntityListRequest<ReportKey> { + + Request() { + super(ReportKey.get(), valueStore, requestService); + } + + @Override + protected Request getThis() { + return this; + } } - public EntityListRequest<ReportKey> findReportsByEmployee( - final ValueRef<EmployeeKey, String> id) { + private final ValueStore valueStore; + private final Service requestService; - return new EntityListRequest<ReportKey>() { - Set<Property<ReportKey, ?>> properties = new HashSet<Property<ReportKey, ?>>(); - private HasValueList<Values<ReportKey>> watcher; - - 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.GET, - "/expenses/data?methodName=" - + MethodName.FIND_REPORTS_BY_EMPLOYEE.name() - + UrlParameterManager.getUrlFragment(new Object[] {id.get()})); - 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(); - JsArray<ValuesImpl<ReportKey>> valueArray = ValuesImpl.arrayFromJson(text); - List<Values<ReportKey>> valueList = new ArrayList<Values<ReportKey>>( - valueArray.length()); - for (int i = 0; i < valueArray.length(); i++) { - ValuesImpl<ReportKey> values = valueArray.get(i); - values.setPropertyHolder(ReportKey.get()); - valueList.add(values); - } - watcher.setValueList(valueList); - } 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); - } - - public EntityListRequest<ReportKey> forProperties( - Collection<Property<ReportKey, ?>> properties) { - for (Property<ReportKey, ?> property : properties) { - forProperty(property); - } - return this; - } - - public EntityListRequest<ReportKey> forProperty(Property<ReportKey, ?> property) { - properties.add(property); - return this; - } - - public EntityListRequest<ReportKey> to(HasValueList<Values<ReportKey>> watcher) { - this.watcher = watcher; - return this; - } - }; + public ReportRequestImpl(ValueStore valueStore, Service requestService) { + this.valueStore = valueStore; + this.requestService = requestService; } public EntityListRequest<ReportKey> findAllReports() { - return new EntityListRequest<ReportKey>() { - private HasValueList<Values<ReportKey>> watcher; - - 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.GET, - "/expenses/data?methodName=" + MethodName.FIND_ALL_REPORTS.name()); - 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(); - JsArray<ValuesImpl<ReportKey>> valueArray = ValuesImpl.arrayFromJson(text); - // Handy for FireBug snooping -// Document.get().getBody().setPropertyJSO("foo", valueArray); - List<Values<ReportKey>> valueList = new ArrayList<Values<ReportKey>>( - valueArray.length()); - for (int i = 0; i < valueArray.length(); i++) { - ValuesImpl<ReportKey> values = valueArray.get(i); - values.setPropertyHolder(ReportKey.get()); - valueList.add(values); - } - watcher.setValueList(valueList); - } 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); - } - - public EntityListRequest<ReportKey> forProperties( - Collection<Property<ReportKey, ?>> properties) { - for (Property<ReportKey, ?> property : properties) { - forProperty(property); - } - return this; + return new Request() { + public String getRequestData(String data) { + // TODO Dear Amit: your code here + throw new UnsupportedOperationException(); } - public EntityListRequest<ReportKey> forProperty( - Property<ReportKey, ?> property) { - return this; + @SuppressWarnings("deprecation") + public String getRequestUrl() { + return "/expenses/data?methodName=" + + MethodName.FIND_ALL_REPORTS.name(); + } + }; + }; + + public EntityListRequest<ReportKey> findReportsByEmployee( + final ValueRef<EmployeeKey, String> id) { + return new Request() { + public String getRequestData(String data) { + // TODO Dear Amit: your code here + throw new UnsupportedOperationException(); } - public EntityListRequest<ReportKey> to( - HasValueList<Values<ReportKey>> watcher) { - this.watcher = watcher; - return this; + @SuppressWarnings("deprecation") + public String getRequestUrl() { + return "/expenses/data?methodName=" + + MethodName.FIND_REPORTS_BY_EMPLOYEE.name() + + UrlParameterManager.getUrlFragment(new Object[] {id.get()}); } }; }
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 f0d6e06..fcc185b 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
@@ -16,8 +16,8 @@ package com.google.gwt.sample.expenses.server; import com.google.gwt.requestfactory.shared.EntityKey; +import com.google.gwt.requestfactory.shared.impl.UrlParameterManager; import com.google.gwt.sample.expenses.gen.MethodName; -import com.google.gwt.sample.expenses.gen.UrlParameterManager; import com.google.gwt.sample.expenses.server.domain.Report; import com.google.gwt.sample.expenses.server.domain.Storage; import com.google.gwt.sample.expenses.shared.ReportKey;
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java index 59b11cd..de1264d 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java
@@ -15,10 +15,10 @@ */ package com.google.gwt.sample.expenses.shared; +import com.google.gwt.requestfactory.shared.EntityKey; import com.google.gwt.requestfactory.shared.Id; import com.google.gwt.requestfactory.shared.LongString; import com.google.gwt.requestfactory.shared.ServerType; -import com.google.gwt.requestfactory.shared.EntityKey; import com.google.gwt.requestfactory.shared.Version; import com.google.gwt.valuestore.shared.Property; @@ -26,9 +26,12 @@ import java.util.Set; /** - * "Generated" proxy of - * {@link com.google.gwt.sample.expenses.server.domain.Employee domain.Employee} - * . + * "API Generated" key for proxy {@link com.google.gwt.valuestore.shared.Values + * Values} of {@link com.google.gwt.sample.expenses.server.domain.Employee + * domain.Employee}. + * <p> + * IRL this class will be generated by a JPA-savvy tool run before + * compilation. */ @ServerType(com.google.gwt.sample.expenses.server.domain.Employee.class) public class EmployeeKey implements EntityKey<EmployeeKey> { @@ -87,7 +90,7 @@ public Property<EmployeeKey, String> getUserName() { return userName; } - + @Version public Property<EmployeeKey, 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 6d874e1..ac66d3f 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
@@ -22,8 +22,11 @@ import com.google.gwt.valuestore.shared.ValueRef; /** - * Generated for the service methods of + * "API generated" for the service methods of * com.google.gwt.sample.expenses.server.domain. + * <p> + * IRL this interface will be generated by a JPA-savvy tool run before + * compilation. */ public interface ExpenseRequestFactory extends RequestFactory {
diff --git a/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java b/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java index b2b3193..d78e991 100644 --- a/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java +++ b/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java
@@ -15,10 +15,10 @@ */ package com.google.gwt.sample.expenses.shared; +import com.google.gwt.requestfactory.shared.EntityKey; import com.google.gwt.requestfactory.shared.Id; import com.google.gwt.requestfactory.shared.LongString; import com.google.gwt.requestfactory.shared.ServerType; -import com.google.gwt.requestfactory.shared.EntityKey; import com.google.gwt.requestfactory.shared.Version; import com.google.gwt.valuestore.shared.Property; @@ -27,8 +27,12 @@ import java.util.Set; /** - * "Generated" proxy of - * {@link com.google.gwt.sample.expenses.server.domain.Report domain.Report}. + * "API Generated" key for proxy {@link com.google.gwt.valuestore.shared.Values + * Values} of {@link com.google.gwt.sample.expenses.server.domain.Report + * domain.Employee}. + * <p> + * IRL this class will be generated by a JPA-savvy tool run before + * compilation. */ @ServerType(com.google.gwt.sample.expenses.server.domain.Report.class) public class ReportKey implements EntityKey<ReportKey> {