Permalink
Browse files

Add in a loadPage() method to QueryResult

  • Loading branch information...
1 parent 7278bd3 commit 3f917429717b99e85cc420cc7afd6c751cda5850 @akeefer committed Feb 10, 2012
Showing with 25 additions and 0 deletions.
  1. +10 −0 src/tosa/api/QueryResult.gs
  2. +15 −0 src/tosa/impl/query/QueryResultImpl.gs
View
10 src/tosa/api/QueryResult.gs
@@ -111,6 +111,16 @@ public interface QueryResult<T> extends Iterable<T> {
function page(startPage : int = 0, pageSize : int = 100, startOffset : int = 0) : QueryResult<T>
/**
+ * Loads the specified page into a List. If this query hasn't been paged, this will
+ * load all results regardless of the pageNumber argument specified.
+ *
+ * @param pageNumber the page number to load, which defaults to 0
+ *
+ * @return the results corresponding to the specified page
+ */
+ function loadPage(pageNumber : int = 0) : List<T>
+
+ /**
* Clears any paging information applied to this QueryResult.
*
* Calling this method will invalidate any already-loaded results, causing them to be reloaded from the
View
15 src/tosa/impl/query/QueryResultImpl.gs
@@ -107,6 +107,21 @@ public class QueryResultImpl<T> implements QueryResult<T> {
return this
}
+ override function loadPage(pageNumber : int) : List<T> {
+ if (_pagingInfo == null) {
+ maybeLoadResults()
+ return new ArrayList<T>(_results)
+ } else {
+ // Invalidate results if necessary
+ if (_pagingInfo._currentOffset != pageNumber * _pagingInfo._pageSize) {
+ _results = null
+ _pagingInfo._currentOffset = pageNumber * _pagingInfo._pageSize
+ }
+ maybeLoadResults()
+ return new ArrayList<T>(_results)
+ }
+ }
+
override function clearPaging() : QueryResult<T> {
_results = null
_pagingInfo = null

0 comments on commit 3f91742

Please sign in to comment.