You'll have to do another query since we don't "peek ahead" to see if you're
at the end of the query result or not. You can optimize this, however, by
doing a keys only query so you don't have to fetch the entities:

http://code.google.com/appengine/docs/java/datastore/queriesandindexes.html#Queries_on_Keys

On Wed, Apr 21, 2010 at 4:10 AM, Chau Huynh <[email protected]> wrote:

> Hello app engine team,
>
> I'd like to have a search form, which allows user to search next if more
> result available by using a Cursor.
> My issue is, in the last chunk, I am not able to detect if it's.
> Therefore, I will need to execute one additional query to test if more
> data.
> Can you please advise if other approach, without using the 2nd query.
> Thanks.
>
> By document, CursorHelper.getCursor(List<?>) will return a Cursor which
> points to the last element in the list.
> The code is below (correct according to doc)
>
> import com.google.appengine.api.datastore.Cursor;
>
>     EntityManager em = ...
>     Query query = em.createQuery(queryString);
>     query.setMaxResults(20);
>     em.getTransaction().begin();
>     List<TestEntity> testEntities = query.getResultList();
>     Cursor cursor = JPACursorHelper.getCursor(testEntities);
>     em.getTransaction().rollback();
>
> Then I will need to invoke one more call later, to check a null cursor
> returned indicates no more data available
>     query.setMaxResults(1);
>     query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
>     em.getTransaction().begin();
>     List<TestEntity> testEntities = query.getResultList();
>     Cursor cursor = JPACursorHelper.getCursor(testEntities);
>     em.getTransaction().rollback();
>
> By curiosity (please correct me if I'm wrong), I looked into
> org.datanucleus.store.appengine.query
> and found that StreamingQueryResult returned by DatastoreQuery,
> which was in fact constructed from
> com.google.appengine.api.datastore.QueryResultList.
> The document say return a cursor that points to the result immediately
> after the last one in this list.
>
> http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/QueryResultList.html#getCursor()
>
> So I wonder if CursorHelper.getCursor(List<?>) can have something similar?
>
> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>



-- 
Ikai Lan
Developer Relations, Google App Engine
Twitter: http://twitter.com/ikai
Delicious: http://delicious.com/ikailan

----------------
Google App Engine links:
Blog: http://googleappengine.blogspot.com
Twitter: http://twitter.com/app_engine
Reddit: http://www.reddit.com/r/appengine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to