Java Code Examples for org.springframework.data.domain.Pageable#isUnpaged()

The following examples show how to use org.springframework.data.domain.Pageable#isUnpaged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseRepositoryImpl.java    From halo with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SensitiveConceal
public Page<DOMAIN> findAllByIdIn(Collection<ID> ids, Pageable pageable) {
    Assert.notNull(ids, "The given Collection of Id's must not be null!");
    Assert.notNull(pageable, "Page info must nto be null");

    if (!ids.iterator().hasNext()) {
        return new PageImpl<>(Collections.emptyList());
    }

    if (entityInformation.hasCompositeId()) {
        throw new UnsupportedOperationException("Unsupported find all by composite id with page info");
    }

    ByIdsSpecification<DOMAIN> specification = new ByIdsSpecification<>(entityInformation);
    TypedQuery<DOMAIN> query = super.getQuery(specification, pageable).setParameter(specification.parameter, ids);
    TypedQuery<Long> countQuery = getCountQuery(specification, getDomainClass()).setParameter(specification.parameter, ids);

    return pageable.isUnpaged() ?
        new PageImpl<>(query.getResultList())
        : readPage(query, getDomainClass(), pageable, countQuery);
}
 
Example 2
Source File: AqlUtils.java    From spring-data with Apache License 2.0 6 votes vote down vote up
private static StringBuilder buildPageableClause(
	final Pageable pageable,
	@Nullable final String varName,
	final StringBuilder clause) {

	if (pageable.isUnpaged()) {
		return clause;
	}

	final Sort sort = pageable.getSort();
	buildSortClause(sort, varName, clause);

	if (sort.isSorted()) {
		clause.append(' ');
	}

	clause.append("LIMIT ").append(pageable.getOffset()).append(", ").append(pageable.getPageSize());
	return clause;
}
 
Example 3
Source File: SimpleKeyValueRepository.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
@Override
public Page<T> findAll(Pageable pageable) {

	Assert.notNull(pageable, "Pageable must not be null!");

	if (pageable.isUnpaged()) {
		List<T> result = findAll();
		return new PageImpl<>(result, Pageable.unpaged(), result.size());
	}

	Iterable<T> content = operations.findInRange(pageable.getOffset(), pageable.getPageSize(), pageable.getSort(),
			entityInformation.getJavaType());

	return new PageImpl<>(IterableConverter.toList(content), pageable,
			this.operations.count(entityInformation.getJavaType()));
}
 
Example 4
Source File: AqlUtils.java    From spring-data with Apache License 2.0 5 votes vote down vote up
public static String buildLimitClause(final Pageable pageable) {
	if (pageable.isUnpaged()) {
		return "";
	}

	final StringJoiner clause = new StringJoiner(", ", "LIMIT ", "");
	clause.add(String.valueOf(pageable.getOffset()));
	clause.add(String.valueOf(pageable.getPageSize()));
	return clause.toString();
}
 
Example 5
Source File: JpaSpecificationExecutorWithProjectionImpl.java    From specification-with-projection with MIT License 5 votes vote down vote up
@Override
public <R> Page<R> findAll(Specification<T> spec, Class<R> projectionType, Pageable pageable) {
    final ReturnedType returnedType = ReturnTypeWarpper.of(projectionType, getDomainClass(), projectionFactory);
    final TypedQuery<Tuple> query = getTupleQuery(spec, pageable.isPaged() ? pageable.getSort() : Sort.unsorted(), returnedType);
    final MyResultProcessor resultProcessor = new MyResultProcessor(projectionFactory,returnedType);
    if (pageable.isPaged()) {
        query.setFirstResult((int)pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }
    final List<R> resultList = resultProcessor.processResult(query.getResultList(), new TupleConverter(returnedType));
    final Page<R> page = PageableExecutionUtils.getPage(resultList, pageable, () -> executeCountQuery(this.getCountQuery(spec, getDomainClass())));
    return pageable.isUnpaged() ? new PageImpl(resultList) : page;
}
 
Example 6
Source File: SimpleMybatisRepository.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
@Override
public <X extends T> Page<T> findAll(Pageable pageable, X condition) {
	if (null == pageable || pageable.isUnpaged()) {
		// FIXME USE A DEFAULT PAGEABLE?
		return new PageImpl<>(findAll(condition));
	}
	return findByPager(pageable, "__find_by_pager", "__count", condition);
}
 
Example 7
Source File: CodelessDaoProxy.java    From sca-best-practice with Apache License 2.0 4 votes vote down vote up
private static boolean isUnpaged(Pageable pageable) {
    return pageable.isUnpaged();
}
 
Example 8
Source File: FindPageSpecificationInterceptor.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Override
public Object intercept(RepositoryMethodKey methodKey, MethodInvocationContext<Object, Object> context) {
    final Object[] parameterValues = context.getParameterValues();
    if (parameterValues.length != 2) {
        throw new IllegalStateException("Expected exactly 2 arguments to method");
    }
    final Object parameterValue = parameterValues[0];
    final Object pageableObject = parameterValues[1];
    if (parameterValue instanceof Specification) {
        Specification specification = (Specification) parameterValue;
        final EntityManager entityManager = jpaOperations.getCurrentEntityManager();
        final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        final CriteriaQuery<Object> query = criteriaBuilder.createQuery((Class<Object>) getRequiredRootEntity(context));
        final Root<Object> root = query.from((Class<Object>) getRequiredRootEntity(context));
        final Predicate predicate = specification.toPredicate(root, query, criteriaBuilder);
        query.where(predicate);
        query.select(root);

        if (pageableObject instanceof Pageable) {
            Pageable pageable = (Pageable) pageableObject;
            final Sort sort = pageable.getSort();
            if (sort.isSorted()) {
                final List<Order> orders = QueryUtils.toOrders(sort, root, criteriaBuilder);
                query.orderBy(orders);
            }
            final TypedQuery<Object> typedQuery = entityManager
                    .createQuery(query);
            if (pageable.isUnpaged()) {
                return new PageImpl<>(
                    typedQuery
                            .getResultList()
                );
            } else {
                typedQuery.setFirstResult((int) pageable.getOffset());
                typedQuery.setMaxResults(pageable.getPageSize());
                final List<Object> results = typedQuery.getResultList();
                final CriteriaQuery<Long> countQuery = criteriaBuilder.createQuery(Long.class);
                final Root<?> countRoot = countQuery.from(getRequiredRootEntity(context));
                final Predicate countPredicate = specification.toPredicate(root, query, criteriaBuilder);
                countQuery.where(countPredicate);
                countQuery.select(criteriaBuilder.count(countRoot));

                return new PageImpl<>(
                        results,
                        pageable,
                        entityManager.createQuery(countQuery).getSingleResult()
                );
            }

        } else {
            return new PageImpl<>(
                    entityManager
                            .createQuery(query)
                            .getResultList()
            );
        }
    } else {
        throw new IllegalArgumentException("Argument must be an instance of: " + Specification.class);
    }
}
 
Example 9
Source File: DatastorePageable.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
public static Pageable from(Pageable pageable, String urlSafeCursor, Long totalCount) {
	if (pageable.isUnpaged()) {
		return pageable;
	}
	return new DatastorePageable(pageable, urlSafeCursor, totalCount);
}