Search in sources :

Example 1 with SortDirection

use of com.google.appengine.api.datastore.Query.SortDirection in project Cached-Datastore by Emperorlou.

the class QueryHelper method getFilteredList_Sorted.

public List<CachedEntity> getFilteredList_Sorted(String kind, int limit, Cursor cursor, String fieldName, boolean ascending) {
    SortDirection direction = SortDirection.DESCENDING;
    if (ascending)
        direction = SortDirection.ASCENDING;
    Query q = new Query(kind).addSort(fieldName, direction);
    return ds.fetchAsList(q, limit, cursor);
}
Also used : SortDirection(com.google.appengine.api.datastore.Query.SortDirection) Query(com.google.appengine.api.datastore.Query)

Example 2 with SortDirection

use of com.google.appengine.api.datastore.Query.SortDirection in project appengine-java-standard by GoogleCloudPlatform.

the class DatastoreViewerServlet method getEntityViews.

/**
 * Retrieve all EntityViews of the given kind for display, sorted by the
 * (possibly null) given order.
 */
List<EntityView> getEntityViews(String kind, String order, int start, int numPerPage) {
    List<EntityView> entityViews = new ArrayList<EntityView>();
    Query q = new Query(kind);
    SortDirection dir = SortDirection.ASCENDING;
    if (order != null) {
        // If the order string begins with a dash, sort in descending order.
        if (order.charAt(0) == '-') {
            dir = SortDirection.DESCENDING;
            order = order.substring(1);
        }
        q.addSort(order, dir);
    }
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    FetchOptions opts = FetchOptions.Builder.withOffset(start).limit(numPerPage);
    for (Entity e : ds.prepare(q).asIterable(opts)) {
        entityViews.add(new EntityView(e));
    }
    return entityViews;
}
Also used : FetchOptions(com.google.appengine.api.datastore.FetchOptions) Entity(com.google.appengine.api.datastore.Entity) SortDirection(com.google.appengine.api.datastore.Query.SortDirection) Query(com.google.appengine.api.datastore.Query) DatastoreService(com.google.appengine.api.datastore.DatastoreService) LocalDatastoreService(com.google.appengine.api.datastore.dev.LocalDatastoreService) ArrayList(java.util.ArrayList)

Aggregations

Query (com.google.appengine.api.datastore.Query)2 SortDirection (com.google.appengine.api.datastore.Query.SortDirection)2 DatastoreService (com.google.appengine.api.datastore.DatastoreService)1 Entity (com.google.appengine.api.datastore.Entity)1 FetchOptions (com.google.appengine.api.datastore.FetchOptions)1 LocalDatastoreService (com.google.appengine.api.datastore.dev.LocalDatastoreService)1 ArrayList (java.util.ArrayList)1