protected InnerTopiaQueryBuilderRunQueryStep<E> forHql(String hql) { Map<String, Object> properties = Collections.emptyMap(); InnerTopiaQueryBuilderRunQueryStep<E> result = forHql(hql, properties); return result; }
protected InnerTopiaQueryBuilderRunQueryStep<E> forHql(String hql, String parameterName, Object parameterValue, Object... otherParameterNamesAndValues) { Map<String, Object> hqlParameters = TopiaUtil.convertPropertiesArrayToMap(parameterName, parameterValue, otherParameterNamesAndValues); InnerTopiaQueryBuilderRunQueryStep<E> result = forHql(hql, hqlParameters); 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 PaginationResult<E> findPage(PaginationParameter page) { PaginationResult<E> result; if (!Strings.isNullOrEmpty(hqlForFetchStep1) && !Strings.isNullOrEmpty(hqlForFetchStep2)) { PaginationResult<String> pageResult = topiaDao.findPage(hqlForFetchStep1, hqlParameters, page); List<String> step1ResultTopiaIds = pageResult.getElements(); List<E> sortedEntities; if (CollectionUtils.isEmpty(step1ResultTopiaIds)) { sortedEntities = Lists.newArrayList(); } else { Map<String, Object> step2Args = Maps.newHashMap(); step2Args.put("topiaIdsForFetch_", step1ResultTopiaIds); List<E> entities = topiaDao.forHql(hqlForFetchStep2, step2Args).findAll(); sortedEntities = sortAccordingToIds(entities, step1ResultTopiaIds); } result = PaginationResult.of(sortedEntities, pageResult.getCount(), pageResult.getCurrentPage()); } else { result = topiaDao.findPage(hql, hqlParameters, page); } return result; }