I'm trying to work on the sample GAE / Android app. There is Place Entity.
In generated PlaceEndpoint class there is a method:
@ApiMethod(name = "listGame")
public CollectionResponse<Place> listPlace(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Game> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Place as Place");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Game>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Game obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Game> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
As I understand cursor
and limit
all optional params.
However I can't figure out how to pass them using Placeednpoint
class on the client side:
Placeendpoint.Builder builder = new Placeendpoint.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
builder = CloudEndpointUtils.updateBuilder(builder);
Placeendpoint endpoint = builder.build();
try {
CollectionResponsePlace placesResponse = endpoint.listPlace().execute();
} catch (Exception e) {
e.printStackTrace();
Normally, when params are not nullable I would pass them in endpoint.listPlace() method. But when params are nullable, client side app doesn't see alternative constructor, that would accept params.
How am I supposed to pass them then?
There is an additional way. You can simply set your nullable value 'cursor' it like this:
Where you can
Faced the same issue but backend developed using Java. The solution provided by Tony m worked like a charm. Simply had to adapt how the method is called on Android and it worked.
For passing parameters from client side while sending a query request through cloud endpoints, you need to add provision for setting parameters. To send the required parameter from android , the class where you would define the REST Path and method type, should include an option to the set cursor and limit. For example for the String cursorstring :
Finally while calling the endpoint method from your android code, you should pass a value using the setCursorstring, which will be something like: