Use cursor to query from google app in android

I tried a thousand things. At the moment, the only way for me to ask for something is to get the whole list and view it this way! which takes a lot of time. How can I request something in the Google engine, for example, to pull out only objects that have> 100 votes, for example.

Tried a custom cursor but not sure how it works. I know that he can use the cursor, but how to configure it using the Google App Engine, since my database is not in my application for the message?

Ive tried ... but this dose does not work at all.

Cursor cursor = ("select * from Votes WHERE Votes >" + 250 , null); quotes endpoint.listquotes().setCursor(cursor).execute(); 

and

  String query = ("select * from Votes WHERE Votes >= 40"); quotes endpoint.listquotes().setCursor(query).execute(); 

Im following the tic-tac-toe example https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java and https://developers.google.com/eclipse/docs/endpoints-addentities In this example, I just switched quotation marks.

Here is my current code, for example, on how im gets objects.

  protected CollectionResponseQuotes doInBackground(Context... contexts) { Quotesendpoint.Builder endpointBuilder = new Quotesendpoint.Builder( AndroidHttp.newCompatibleTransport(), new JacksonFactory(), new HttpRequestInitializer() { public void initialize(HttpRequest httpRequest) { } }); Quotesendpoint endpoint = CloudEndpointUtils.updateBuilder( endpointBuilder).build(); try { quotes = endpoint.listquotes().execute(); for (Quotes quote : quotes.getItems()) { if (quote.getVotes() > 3) { quoteList.add(quote); } } 

Here is the code that Google created in the app for me when I created the endpoint. He seems to be asking, but I can't figure it out. These are two different projects.

 @Api(name = "quotesendpoint", namespace = @ApiNamespace(ownerDomain = "projectquotes.com" ownerName = "projectquotes.com", packagePath = "")) public class quotesEndpoint { /** * This method lists all the entities inserted in datastore. * It uses HTTP GET method and paging support. * * @return A CollectionResponse class containing the list of all entities * persisted and a cursor to the next page. */ @SuppressWarnings({ "unchecked", "unused" }) @ApiMethod(name = "listquotes") public CollectionResponse<quotes> listquotes( @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) { EntityManager mgr = null; Cursor cursor = null; List<quotes> execute = null; try { mgr = getEntityManager(); Query query = mgr.createQuery("select from quotes as quotes"); 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<quotes>) 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 (quotes obj : execute) ; } finally { mgr.close(); } return CollectionResponse.<quotes> builder().setItems(execute) .setNextPageToken(cursorString).build(); 
+4
source share
2 answers

In the Google App Engine, you need to configure the servlet to query the database for you and then return the results to JSON, see here for more information: https://developers.google.com/appengine/docs/java/datastore/queries https://github.com/octo-online/robospice https://developers.google.com/appengine/docs/java/#Requests_and_Servlets https://code.google.com/p/google-gson/

In the end, will you query using http: // your-url / query? + query string

EDIT: Preview!

This is a preview release of Google Cloud Endpoints. As a result, the API can be changed, and the service itself is not currently covered by any SLA or obsolescence policy. These characteristics are evaluated as an API, and the service moves to General Availability, but developers should consider this when using the pre-release endpoints of Google Cloud.

Most likely, the cursor function is still under development. But I'm also not sure why you would like to use cursors, since collections are much easier to work with ... Wouldn't you like to do what is below, and then the awful code above? :)

 ScoreCollection scores = service.scores().list().execute(); 
+3
source

Update your list method to accept the filter attribute.

 @SuppressWarnings({ "unchecked", "unused" }) @ApiMethod(name = "listZeppaUserInfo") public CollectionResponse<ZeppaUserInfo> listZeppaUserInfo( @Nullable @Named("filter") String filterString, @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) { PersistenceManager mgr = null; Cursor cursor = null; List<ZeppaUserInfo> execute = null; try { mgr = getPersistenceManager(); Query query = mgr.newQuery(ZeppaUserInfo.class); if (isWebSafe(cursorString)) { cursor = Cursor.fromWebSafeString(cursorString); HashMap<String, Object> extensionMap = new HashMap<String, Object>(); extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor); query.setExtensions(extensionMap); } else if (isWebSafe(filterString)){ // query has a filter query.setFilter(filterString); } if (limit != null) { query.setRange(0, limit); } execute = (List<ZeppaUserInfo>) query.execute(); cursor = JDOCursorHelper.getCursor(execute); if (cursor != null) cursorString = cursor.toWebSafeString(); // Tight loop for fetching all entities from datastore and // accomodate // for lazy fetch. for (ZeppaUserInfo obj : execute) ; } finally { mgr.close(); } return CollectionResponse.<ZeppaUserInfo> builder().setItems(execute) .setNextPageToken(cursorString).build(); } 
+1
source

Source: https://habr.com/ru/post/1492426/


All Articles