@Override public List<String> findIds(int startIndex, int endIndex) { String hqlWithSelectClause = "select topiaId " + hql; return topiaDao.find(hqlWithSelectClause, hqlParameters, startIndex, endIndex); }
@Override public List<String> findIds(PaginationParameter page) { String hqlWithSelectClause = "select topiaId " + hql; return topiaDao.find(hqlWithSelectClause, hqlParameters, page); }
@Override public List<E> find(PaginationParameter page) { return topiaDao.find(hql, hqlParameters, page); }
protected <O> List<O> find(String hql, int startIndex, int endIndex) { Preconditions.checkNotNull(hql); Map<String, Object> hqlParameters = Collections.emptyMap(); List<O> result = find(hql, hqlParameters, startIndex, endIndex); return result; }
@Override public List<E> find(int startIndex, int endIndex) { List<E> result; if (!Strings.isNullOrEmpty(hqlForFetchStep1) && !Strings.isNullOrEmpty(hqlForFetchStep2)) { List<String> step1ResultTopiaIds = topiaDao.find(hqlForFetchStep1, hqlParameters, startIndex, endIndex); if (CollectionUtils.isEmpty(step1ResultTopiaIds)) { result = Lists.newArrayList(); } else { Map<String, Object> step2Args = Maps.newHashMap(); step2Args.put("topiaIdsForFetch_", step1ResultTopiaIds); List<E> entities = topiaDao.forHql(hqlForFetchStep2, step2Args).findAll(); result = sortAccordingToIds(entities, step1ResultTopiaIds); } } else { result = topiaDao.find(hql, hqlParameters, startIndex, endIndex); } return result; }
protected <O> PaginationResult<O> findPage(String hql, Map<String, Object> hqlParameters, PaginationParameter page) { List<O> elements = find(hql, hqlParameters, page); String countHql = "select count(topiaId) "; if (hqlStartsWithSelect(hql)) { // must remove the from clause, otherwise some sql queries won't work. countHql += hql.substring(hql.toLowerCase().indexOf(" from ")); } else { countHql += hql; } if (hqlContainsOrderBy(countHql)) { // must remove the order by clause, otherwise some sql queries won't work. countHql = countHql.substring(0, countHql.toLowerCase().indexOf("order by")); } long count = count(countHql, hqlParameters); PaginationResult<O> result = PaginationResult.of(elements, count, page); return result; }
public O next() { if (!hasNext()) { throw new NoSuchElementException(); } if (!data.hasNext()) { // must load iterator PaginationParameter pageToLoad; if (firstPageLoaded) { pageToLoad = pager.getNextPage(); } else { pageToLoad = pager.getCurrentPage(); firstPageLoaded = true; } // load new window of data List<O> values = dao.find(hql, params, pageToLoad); data = values.iterator(); // Create a new pager on the next page pager = PaginationResult.of(pager.getElements(), pager.getCount(), pageToLoad); } O next = data.next(); return next; }