zillo32 / vosao

Automatically exported from code.google.com/p/vosao
GNU Lesser General Public License v2.1
0 stars 0 forks source link

This is the page? #463

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
vosao code:
VelocityServiceImpl.java       
        public List<PageEntity> findPageChildren(String path, int start, int count) {
    return ListUtil.slice(findPageChildren(path), start, count);
        }

ListUtil.java
        public static <T> List<T> slice(List<T> list, int index, int count) {
        List<T> result = new ArrayList<T>();
        if (index >= 0 && index < list.size()) {
            int end = index + count < list.size() ? index + count : list.size();
            for (int i = index; i < end; i++) {
                result.add(list.get(i));
            }
        }
        return result;
    }
use (com.google.appengine.api.datastore.Query)
a batch get() cannot return more than 1 megabyte of data.

JDO QUERY API (javax.jdo.Query)
PersistenceManager pm=....
Query query=pm.newQuery(GQL);
query.setRange(startIndex, endIndex);

Original issue reported on code.google.com by liaowu...@gmail.com on 20 Apr 2011 at 3:40

GoogleCodeExporter commented 8 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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago
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

GoogleCodeExporter commented 8 years ago

Original comment by kinyelo@gmail.com on 25 Jun 2011 at 9:58