Closed GoogleCodeExporter closed 9 years ago
http://code.google.com/p/datanucleus-appengine/source/browse/trunk/tests/org/dat
anucleus/store/appengine/query/JPQLCursorTest.java?r=447
implements pagination with api
(import com.google.appengine.api.datastore.Cursor)
String encodedCursor=entityIter.getCursor().toWebSafeString();
Cursor c=Cursor.fromWebSafeString(encodedCursor);
c.next();
Original comment by liaowu...@gmail.com
on 20 Apr 2011 at 4:25
he following example demonstrates the use of cursors for pagination
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.QueryResultList;
public class ListPeopleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query q = new Query("Person");
PreparedQuery pq = datastore.prepare(q);
int pageSize = 15;
resp.setContentType("text/html");
resp.getWriter().println("<ul>");
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(pageSize);
String startCursor = req.getParameter("cursor");
// If this servlet is passed a cursor parameter, let's use it
if (startCursor != null) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursor));
}
QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);
for (Entity entity : results) {
resp.getWriter().println("<li>" + entity.getProperty("name") + "</li>");
}
resp.getWriter().println("</ul>");
String cursor = results.getCursor().toWebSafeString();
// Assuming this servlet lives at '/people'
resp.getWriter().println(
"<a href='/people?cursor=" + cursor + "'>Next page</a>");
}
}
Original comment by liaowu...@gmail.com
on 21 Apr 2011 at 4:19
Looks like there is no more 1MB query result limit.
http://stackoverflow.com/questions/4140485/query-response-size-limit-on-appengin
e
Original comment by kinyelo@gmail.com
on 25 Jun 2011 at 9:58
Original comment by kinyelo@gmail.com
on 25 Jun 2011 at 9:58
Original issue reported on code.google.com by
liaowu...@gmail.com
on 20 Apr 2011 at 3:40