private boolean retrieveAllResults(Page requestedPage) { return requestedPage.getPageSize() == Page.ALL_RESULTS; }
/** * Counted against total number of results available in a data source. * Counting starts from 1 not 0. * * @return A page number of current loaded paged results. */ public static int getCurrentPageNumber(Page page) { return page.getStartIndex() / page.getPageSize() + 1; }
public int getLastPageNumber() { return PagedList.getLastPageNumber(totalCount, page.getPageSize()); } }
/** * Go to last page. */ public void last() { int pageSize = page.getPageSize(); int lastIndex = totalCount - 1; lastIndex = PagedList.getNearestIndexToPageSize(lastIndex, pageSize); fetch(new Page(lastIndex, page.getPageSize())); }
/** * Go to previous page. */ public void previous() { int currentIndex = page.getStartIndex(); currentIndex -= page.getPageSize(); currentIndex = (currentIndex < 0 ? 0 : currentIndex); fetch(new Page(currentIndex, page.getPageSize())); }
private RootFindCommand<? extends T> applyPageSize(RootFindCommand<? extends T> findCommand, Page page) { if (page.getPageSize() != Page.ALL_RESULTS) { findCommand.startFrom(page.getStartIndex()); findCommand.maximumResults(page.getPageSize()); } return findCommand; }
/** * @return True if results are from the last available page. */ public boolean isOnLastPage() { int pageSize = page.getPageSize(); int lastIndex = totalCount - 1; return PagedList.getNearestIndexToPageSize(lastIndex, pageSize) == page.getStartIndex(); }
/** * Go to first page. */ public void first() { fetch(new Page(0, page.getPageSize())); }
private E getFromLoadedPageResult(int index) { int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }
/** * Go to next page. */ public void next() { int currentIndex = page.getStartIndex(); fetch(new Page(currentIndex + resultSize, page.getPageSize())); }
public int getLastPageNumber() { return getLastPageNumber(pagedResult.getTotalResultCount(), pagedResult.getPage().getPageSize()); }
/** * Returns element directly if it is within fetched (cached) page, else throw exception. * * @see java.util.List#get(int) */ public E get(int index) throws IndexOutOfBoundsException { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be less than 0"); if (isOutOfCachedPagedResult(index)) { throw new IndexOutOfBoundsException( "Index should be within range <" + getPagedResult().getPage().getStartIndex() + " ; " + getEndIndex() + ">"); } int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }
/** * Returns element directly if it is within fetched page, else fetch a new * page if available. * * @see java.util.List#get(int) */ public E get(int index) throws IndexOutOfBoundsException { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be less than 0"); if (isOutOfCachedPagedResult(index)) { int nearestStartIndex = getNearestIndexToPageSize(index, defaultPageSize); fetchPage(new Page(nearestStartIndex, defaultPageSize)); // System.out.println("fetch " + index); } if (index >= getPagedResult().getTotalResultCount()) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be greater than total number of elements."); int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }
@SuppressWarnings("unchecked") private List<T> doFindByCriteria(DetachedCriteria criteria, Page page, Set<String> existingAliases, boolean addFilterables, boolean cacheable) { Criteria executable = criteria.getExecutableCriteria((Session) entityManager.getDelegate()); if (existingAliases != null) { if (addFilterables) { enrichCriteriaWithFilterables(page, executable, existingAliases); } // projectables are needed only forexecutable final select, not for // count enrichCriteriaWithProjectables(page, executable, existingAliases); } enrichCriteriaWithSortables(page, executable, existingAliases); executable.setFirstResult(page.getStartIndex()); if (!retrieveAllResults(page)) { // Restrict the selection only when page size has meaningful value. executable.setMaxResults(page.getPageSize()); } executable.setCacheable(cacheable); if (cacheable) { executable.setCacheMode(CacheMode.NORMAL); } List<T> list = setSpecialSortCriteria(executable); if (list != null){ return list; } return executable.list(); }