There's 1 typo in my message, please read org.datanucleus.store.appengine.query.CursorHelper.getCursor(Iterator<?> iter)
Thanks On Fri, May 7, 2010 at 10:48 AM, Chau Huynh <cmhu...@gmail.com> wrote: > Hi Jeff, > > With JPA I will need to excute getResultList() to get a collection > > http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html#getResultList()<http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html#getResultList%28%29> > Somehow org.datanucleus.store.appengine.query.getCursor(Iterator<?> iter) > can not get the cursor in the middle of my iterator, a null value is > returned in sample code below. > I guess getCursor() has something to do with the List returned. > > EntityManager em = > Query query = em.createQuery(queryString); > query.setMaxResults(pageSize + 1); > em.getTransaction().begin(); > Iterator<TestEntity> iterator = query.getResultList().iterator(); > List<TestEntity> list = new ArrayList<TestEntity>(); > for (int i = 0; (i < pageSize) && iterator.hasNext(); i++) { > list.add(iterator.next()); > } > Cursor cursor = JPACursorHelper.getCursor(iterator); > // assert iterator.hasNext() == true and cursor == null > em.getTransaction().rollback(); > > Just my curious: > if I'm able to iterate through the result (using > com.google.appengine.api.datastore.QueryResultIterator<T>) > is it true that each iterator.hasNext() will lazily load entity from the > data store? > My concern is it might cost me more time that way than using > Query.getResultList(). Please advise. > > Thank you. > > > On Fri, May 7, 2010 at 2:24 AM, Jeff Schnitzer <j...@infohazard.org>wrote: > >> I'm a little confused by this. Why doesn't the OP's approach work? >> >> 1) Create query, fetch with limit of 21 items >> 2) Iterate through 20 items >> 3) Get cursor to be used for next page (if necessary) >> 4) Iterate to 21st item just to check for existence >> >> Why won't this work? The documentation seems to imply that this is >> how cursors work... >> >> Jeff >> >> On Thu, May 6, 2010 at 1:03 AM, Ikai L (Google) <ika...@google.com> >> wrote: >> > This is a datastore limitation and not related to JDO/JPA, so you won't >> be >> > able to do this in Objectify either (you can look at the low-level API, >> it >> > doesn't provide this functionality). I believe I saw an issue in the >> issues >> > tracker about creating cursors from arbitrary locations. >> > >> > -- >> > 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 >> google-appengine-j...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com> >> . >> > For more options, visit this group at >> > http://groups.google.com/group/google-appengine-java?hl=en. >> > >> >> -- >> 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 >> google-appengine-j...@googlegroups.com. >> To unsubscribe from this group, send email to >> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-appengine-java?hl=en. >> >> > -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.