@Override public long count() { String hqlWithSelectClause = "select count(topiaId) " + hql; return topiaDao.count(hqlWithSelectClause, hqlParameters); }
@Override public E create() { E result = newInstance(); create(result); return result; }
@Override public void deleteAll(Iterable<E> entities) { for (E entity : entities) { delete(entity); } }
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; }
PaginationParameter firstPage = PaginationParameter.of(0, pageSize); if (hqlContainsOrderBy(hql)) { if (hqlStartsWithSelect(hql)) { long count = count(countHql, params);
protected <O> O findFirstOrNull(String hql, Map<String, Object> hqlParameters) throws QueryMissingOrderException { if (!hqlContainsOrderBy(hql)) { throw new QueryMissingOrderException(hql, hqlParameters); } O result = findAnyOrNull(hql, hqlParameters); return result; }
@Override public Iterable<E> findAllLazy() { String hql = " FROM " + getTopiaEntityEnum().getImplementationFQN() + " ORDER BY id "; Map<String, Object> hqlParameters = Collections.emptyMap(); Iterable<E> result = findAllLazy(hql, hqlParameters); return result; }
protected <O> Iterable<O> findAllLazy(String hql, Map<String, Object> hqlParameters) { Iterable<O> result = findAllLazy(hql, hqlParameters, batchSize); 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; }
@Override public List<String> findIds(PaginationParameter page) { String hqlWithSelectClause = "select topiaId " + hql; return topiaDao.find(hqlWithSelectClause, hqlParameters, page); }
@Override public E findAnyOrNull() { return topiaDao.findAnyOrNull(hql, hqlParameters); }
@Override public List<String> findAllIds() { String hqlWithSelectClause = "select topiaId " + hql; return topiaDao.findAll(hqlWithSelectClause, hqlParameters); }
@Override public Iterable<E> createAll(Iterable<E> entities) { for (E entity : entities) { create(entity); } return entities; }
@Override public E findFirst() throws QueryMissingOrderException, TopiaNoResultException { return topiaDao.findFirst(hql, hqlParameters); }
@Override public boolean exists() { return topiaDao.exists(hql, hqlParameters); }
@Override public E findAny() throws TopiaNoResultException { return topiaDao.findAny(hql, hqlParameters); }
@Override public Iterable<E> findAllLazy(int batchSize) { return topiaDao.findAllLazy(hql + (fromHql || withOrderByClause ? "" : " ORDER BY id "), hqlParameters, batchSize); }
@Override public List<String> findIds(int startIndex, int endIndex) { String hqlWithSelectClause = "select topiaId " + hql; return topiaDao.find(hqlWithSelectClause, hqlParameters, startIndex, endIndex); }
protected <O> Optional<O> tryFindAny(String hql, Map<String, Object> hqlParameters) { O anyOrNull = findAnyOrNull(hql, hqlParameters); Optional<O> result = Optional.fromNullable(anyOrNull); return result; }
@Override public List<E> findAll() { return topiaDao.findAll(hql, hqlParameters); }