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);
}
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;
}
Aggregations