@Override public Pagination pagination() { return delegate.pagination(); }
@Override public Pagination pagination() { return delegate.pagination(); }
@Override public Collection<Resource> members(RequestContext ctx) { Pagination pagination = ctx.pagination(); Stream<String> members = this.db().getCollectionNames().stream().skip(pagination.offset()); if (pagination.limit() > 0) { members = members.limit(pagination.limit()); } return members .filter(name -> !name.equals("system.indexes")) .map(name -> new MongoCollectionResource(this, db().getCollection(name))) .collect(Collectors.toList()); }
@Override public Collection<Resource> members(RequestContext ctx) throws Exception { LinkedList<Resource> members = new LinkedList<>(); // if children requested query children info DBCollection col = getUserspace().getFilesCollection(); DBCursor result = col.find().skip(ctx.pagination().offset()).limit(ctx.pagination().limit()); while (result.hasNext()) { DBObject child = result.next(); members.add(wrapDBObject(path(), new GridFSDBObject(child))); } return members; }
Pagination pagination = ctx.pagination(); if (pagination != null) { int offset = pagination.offset();
int count = ctx.pagination().offset() >= totalCount ? 0 : totalCount - ctx.pagination().offset(); count = count < ctx.pagination().limit() ? count : ctx.pagination().limit();
public Builder(ResourceRequest original) { obj = new DefaultResourceRequest(original); mediaTypeMatcher(original.mediaTypeMatcher()); pagination(original.requestContext().pagination()); resourceState(original.state()); }
public QueryResults queryTable(String table, String id, RequestContext ctx) throws SQLException, IOException { Catalog cat = parent.catalog(); Table t = cat.tableById(table); try (Connection con = parent.connection()) { String q = ctx.resourceParams().value("q"); if (id == null) { if (q != null) { return queryBuilder.querySelectFromTable(con, t, replaceIdsWithColumnNames(ctx.sorting()), ctx.pagination(), q); } else { return queryBuilder.querySelectFromTable(con, t, replaceIdsWithColumnNames(ctx.sorting()), ctx.pagination()); } } else { return queryBuilder.querySelectFromTableWhereId(con, t, id); } } }
@Override public Map<String, ?> properties(RequestContext ctx) throws Exception { // perform select and store it for readMembers if (results != null) { return null; } results = queryTable(id, null, ctx); List<Resource> links = new LinkedList<>(); MapResource link = new MapResource(); link.put("rel", "schema"); link.put(LiveOak.HREF, uri() + SCHEMA_ENDPOINT); links.add(link); PagingLinksBuilder linksBuilder = new PagingLinksBuilder(ctx) .uri(uri()) .count(results.count()); int totalCount = -1; if (parent.configuration().configuration().includeTotalCount()) { totalCount = queryTableCount(id, ctx); linksBuilder.totalCount(totalCount); } links.addAll(linksBuilder.build()); // keep predictable ordering by using LinkedHashMap Map<String, Object> result = new LinkedHashMap<>(); result.put("links", links); if (totalCount != -1 || results.count() < ctx.pagination().limit()) { result.put("count", totalCount != -1 ? totalCount : results.count()); } result.put("type", "collection"); return result; }
@Override public void encode() throws Exception { //we should only read the members if they are going to be returned in the response //otherwise it could be an expensive operation when all we are requesting is metadata (ie count) //or if the count > 0 (eg no member should be returned). if (requestContext().returnFields().included(LiveOak.MEMBERS) && requestContext().pagination().limit() > 0) { resource().readMembers(requestContext(), new MyResourceSink()); } else { encodeNext(); } }
int offset = ctx.pagination().offset(); int limit = ctx.pagination().limit();
Pagination pagination = ctx.pagination(); if (pagination != null) { dbCursor.limit(pagination.limit());