/** * Synonym for {@link #hasNext()}. * * @return true if a next page is available. */ public boolean getNext() { return hasNext(); }
private LazyList<T> find(String query, Object... params) { if (query.equals("*")) { if (params.length == 0) { return findAll(); } else { throw new IllegalArgumentException("cannot provide parameters with query: '*'"); } } return fullQuery ? new LazyList<T>(true, metaModel, this.query, params) : new LazyList<T>(query, metaModel, params); }
/** * Returns index of the last item in a current page. Use in UI where you need a message: * <code>Displaying 101 to 140 items</code> ir something similar. * * @return index of the last item in a current page. */ public long getTo(){ long count = getCount(); if((currentPageIndex * pageSize) > count){ return count; }else{ return currentPageIndex * pageSize; } } }
/** * Terminal method to create an instance of Paginator. * @return new Paginator properly configured. */ public Paginator<T> create(){ Paginator<T> paginator = new Paginator<T>(modelClass, pageSize, suppressCounts, query, countQuery, params); paginator.setCurrentPageIndex(currentPageIndex, skipCheck); paginator.orderBy(orderBys); return paginator; } }
/** * Returns index of the first item in a current page. Use in UI where you need a message: * <code>Displaying 101 to 140 items</code> ir something similar. * * @return index of the first item in a current page. */ public long getFrom(){ return (getCurrentPage() - 1) * getPageSize() + 1; }
public boolean hasNext() { return currentPageIndex < pageCount(); }
if (pageable != null) { CouchbaseClient client = operations.getCouchbaseClient(); View view = client.getView(designDocName(), viewName()); // Paginator p = new Paginator(client, view, query, // pageable.getPageSize()); Paginator paginator = client.paginatedQuery(view, query, pageable.getPageSize()); // now we need to goto the start point ViewResponse viewResponse = null; // views are 0 base int i = 0; while (paginator.hasNext()) { viewResponse = paginator.next(); if (pageable.getPageNumber() == i++) { LOGGER.debug("Found the response for this page: {} ", i); break; } } if (viewResponse == null) { LOGGER.debug("no view response so leaving now"); return null; } Class<?> type = method.getEntityInformation().getJavaType(); final List result = new ArrayList(viewResponse.size()); for (final ViewRow row : viewResponse) { result.add(operations.findById(row.getId(), type)); } return result; }
/** * Synonym for {@link #hasPrevious()}. * * @return true if a previous page is available. */ public boolean getPrevious() { return hasPrevious(); }
/** * This method will return a list of records for a specific page. * * @param pageNumber page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will * be rejected. * @return list of records that match a query make up a "page". */ public LazyList<T> getPage(int pageNumber) { if (pageNumber < 1) throw new IllegalArgumentException("minimum page index == 1"); try { LazyList<T> list = find(query, params).offset((pageNumber - 1) * pageSize).limit(pageSize); if (orderBys != null) { list.orderBy(orderBys); } currentPageIndex = pageNumber; return list; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }
/** * Returns total count of records based on provided criteria. * * @return total count of records based on provided criteria */ public Long getCount() { if (count == 0L || !suppressCounts) { if (metaModel.cached()) { count = (Long) QueryCache.instance().getItem(metaModel.getTableName(), countQueryFull, params); if (count == null || count == 0) { count = doCount(); QueryCache.instance().addItem(metaModel.getTableName(), countQueryFull, params, count); }else { LogFilter.logQuery(LOGGER, countQueryFull, params, System.currentTimeMillis(), true); } } else { count = doCount(); } return count; } else { return count; } }
public boolean hasPrevious() { return currentPageIndex > 1 && currentPageIndex <= pageCount(); }
/** * Terminal method to create an instance of Paginator. * @return new Paginator properly configured. */ public Paginator<T> create(){ Paginator<T> paginator = new Paginator<T>(modelClass, pageSize, suppressCounts, query, countQuery, params); paginator.setCurrentPageIndex(currentPageIndex, skipCheck); paginator.orderBy(orderBys); return paginator; } }
/** * Synonym for {@link #hasPrevious()}. * * @return true if a previous page is available. */ public boolean getPrevious() { return hasPrevious(); }
/** * This method will return a list of records for a specific page. * * @param pageNumber page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will * be rejected. * @return list of records that match a query make up a "page". */ public LazyList<T> getPage(int pageNumber) { if (pageNumber < 1) throw new IllegalArgumentException("minimum page index == 1"); try { LazyList<T> list = find(query, params).offset((pageNumber - 1) * pageSize).limit(pageSize); if (orderBys != null) { list.orderBy(orderBys); } currentPageIndex = pageNumber; return list; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }
/** * Returns total count of records based on provided criteria. * * @return total count of records based on provided criteria */ public Long getCount() { Long result = null; if (metaModel.cached()) { result = (Long) QueryCache.instance().getItem(metaModel.getTableName(), countQuery, params); if (result == null) { result = doCount(); QueryCache.instance().addItem(metaModel.getTableName(), countQuery, params, result); } } else { result = doCount(); } return result; }
/** * Returns index of the first item in a current page. Use in UI where you need a message: * <code>Displaying 101 to 140 items</code> ir something similar. * * @return index of the first item in a current page. */ public long getFrom(){ return (getCurrentPage() - 1) * getPageSize() + 1; }
/** * Sets an index of a current page. This method will make a quick count query to check that * the index you are setting is within the boundaries. * * @param currentPageIndex index of a current page. * @param skipCheck <code>true</code> to skip the upper boundary check (will not make a call to DB). */ public void setCurrentPageIndex(int currentPageIndex, boolean skipCheck){ if( currentPageIndex < 1){ throw new IndexOutOfBoundsException("currentPageIndex cannot be < 1"); } if(!skipCheck){ if(currentPageIndex > pageCount()){ throw new IndexOutOfBoundsException("currentPageIndex it outside of record set boundaries. "); } } this.currentPageIndex = currentPageIndex; }
/** * Synonym for {@link #hasNext()}. * * @return true if a next page is available. */ public boolean getNext(){ return hasNext(); }
/** * @return a number of pages */ public long pageCount() { try { long results = getCount(); long fullPages = results / pageSize; return results % pageSize == 0 ? fullPages : fullPages + 1; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }