List of usage examples for org.springframework.data.domain SliceImpl SliceImpl
public SliceImpl(List<T> content, Pageable pageable, boolean hasNext)
From source file:at.plechinger.minigeocode.repository.GeocodeRepository.java
public Slice<GeocodeResult> findSlice(String query, Pageable pageable) { String sql = GEOCODE_SQL + pageableString(pageable); List<GeocodeResult> result = getJdbcTemplate().query(sql, new Object[] { query }, geocodeRowMapper); boolean last = result.size() < pageable.getPageSize(); return new SliceImpl<GeocodeResult>(result, pageable, !last); }
From source file:at.plechinger.minigeocode.repository.GeocodeRepository.java
public Slice<ReverseGeocodeResult> findReverseSlice(Double longitude, Double latitude, Pageable pageable) { String sql = REVERSE_GEOCODE_SQL + pageableString(pageable); List<ReverseGeocodeResult> result = getJdbcTemplate().query(sql, new Object[] { longitude, latitude }, reverseGeocodeRowMapper);/*from w w w.ja v a2 s. c o m*/ boolean last = result.size() < pageable.getPageSize(); return new SliceImpl<ReverseGeocodeResult>(result, pageable, !last); }
From source file:org.eclipse.hawkbit.repository.jpa.JpaTargetManagement.java
@Override public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable, final Long orderByDistributionId, final FilterParams filterParams) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class); final Root<JpaTarget> targetRoot = query.from(JpaTarget.class); // select case expression to retrieve the case value as a column to be // able to order based on // this column, installed first,... final Expression<Object> selectCase = cb.selectCase() .when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id), orderByDistributionId), 1) .when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), orderByDistributionId), 2) .otherwise(100);//from w ww.j a v a 2 s . c o m // multiselect statement order by the select case and controllerId query.distinct(true); // build the specifications and then to predicates necessary by the // given filters final Predicate[] specificationsForMultiSelect = specificationsToPredicate( buildSpecificationList(filterParams), targetRoot, query, cb); // if we have some predicates then add it to the where clause of the // multiselect if (specificationsForMultiSelect.length > 0) { query.where(specificationsForMultiSelect); } // add the order to the multi select first based on the selectCase query.orderBy(cb.asc(selectCase), cb.desc(targetRoot.get(JpaTarget_.id))); // the result is a Object[] due the fact that the selectCase is an extra // column, so it cannot // be mapped directly to a Target entity because the selectCase is not a // attribute of the // Target entity, the the Object array contains the Target on the first // index (case of the // multiselect order) of the array and // the 2nd contains the selectCase int value. final int pageSize = pageable.getPageSize(); final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset()) .setMaxResults(pageSize + 1).getResultList(); final boolean hasNext = resultList.size() > pageSize; return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext); }