title: use cursor to query from google app engine in android
body: <p>Ive tried a thousand things. As of right now the only way for me to query anything is to get the entire list and look through it that way! which takes way to much time. How can I query something in google app engine, for example pull only the entities that have > 100 votes for example.</p>
  
  <p>Tried to user cursor but not sure how it works. I know it can use a cursor but how do I set it up with google app engine since my database isnt in my app per say??</p>
  
  <p>Ive tried...   but this dose not work at all..</p>
  
  <pre><code>Cursor cursor = ("select * from Votes WHERE Votes &gt;" + 250 , null);
  quotes endpoint.listquotes().setCursor(cursor).execute();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>  String query  = ("select * from Votes WHERE Votes &gt;= 40");
      quotes endpoint.listquotes().setCursor(query).execute();
  </code></pre>
  
  <p>Im following the tic-tac-toe example <a href="https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java" rel="nofollow">https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java</a> and <a href="https://developers.google.com/eclipse/docs/endpoints-addentities" rel="nofollow">https://developers.google.com/eclipse/docs/endpoints-addentities</a> In the example I just switched notes for quotes.</p>
  
  <p>Heres my current code for example on how im getting the entities.</p>
  
  <pre><code> 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() &gt; 3) {
  
         quoteList.add(quote);
  
          }  
  
   }
  </code></pre>
  
  <p>Here is the code that Google generated in the app engine for me when I created the endpoint. It     looks like it will query somehow but I cant figure it out. They are two different projects.</p>
  
  <pre><code>@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&lt;quotes&gt; listquotes(
          @Nullable @Named("cursor") String cursorString,
          @Nullable @Named("limit") Integer limit) {
  
   EntityManager mgr = null;
  Cursor cursor = null;
  List&lt;quotes&gt; execute = null;
  
  try {
      mgr = getEntityManager();
      Query query = mgr.createQuery("select from quotes as quotes");
      if (cursorString != null &amp;&amp; cursorString != "") {
          cursor = Cursor.fromWebSafeString(cursorString);
          query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
      }
  
      if (limit != null) {
          query.setFirstResult(0);
          query.setMaxResults(limit);
      }
  
      execute = (List&lt;quotes&gt;) 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.&lt;quotes&gt; builder().setItems(execute)
          .setNextPageToken(cursorString).build();
  </code></pre>