Java Code Examples for org.springframework.data.repository.support.PageableExecutionUtils#getPage()

The following examples show how to use org.springframework.data.repository.support.PageableExecutionUtils#getPage() . 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: AbstractNeo4jQuery.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
public final Object execute(Object[] parameters) {

	Neo4jParameterAccessor parameterAccessor = getParameterAccessor(parameters);
	ResultProcessor resultProcessor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);

	PreparedQuery<?> preparedQuery = prepareQuery(resultProcessor.getReturnedType().getReturnedType(),
		getInputProperties(resultProcessor), parameterAccessor, null, getMappingFunction(resultProcessor));

	Object rawResult = new DefaultQueryExecution(neo4jOperations).execute(
		preparedQuery, queryMethod.isCollectionLikeQuery() || queryMethod.isPageQuery());

	Object processedResult = resultProcessor.processResult(rawResult, OptionalUnwrappingConverter.INSTANCE);

	if (!queryMethod.isPageQuery()) {
		return processedResult;
	} else {
		return PageableExecutionUtils.getPage((List<?>) processedResult, parameterAccessor.getPageable(), () -> {

			PreparedQuery<Long> countQuery = prepareQuery(Long.class, Collections.emptyList(), parameterAccessor,
				Neo4jQueryType.COUNT, null);
			return neo4jOperations.toExecutableQuery(countQuery).getRequiredSingleResult();
		});
	}
}
 
Example 2
Source File: SimpleQueryByExampleExecutor.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {

	Predicate predicate = Predicate.create(mappingContext, example);
	StatementBuilder.OngoingReadingAndReturn returning = predicate
		.useWithReadingFragment(cypherGenerator::prepareMatchOf)
		.returning(asterisk());

	BuildableStatement returningWithPaging = addPagingParameter(predicate.getNeo4jPersistentEntity(), pageable,
		returning);

	Statement statement = returningWithPaging.build();

	List<S> page = this.neo4jOperations.findAll(statement, predicate.getParameters(), example.getProbeType());
	LongSupplier totalCountSupplier = () -> this.count(example);
	return PageableExecutionUtils.getPage(page, pageable, totalCountSupplier);
}
 
Example 3
Source File: UserService.java    From SpringAll with MIT License 6 votes vote down vote up
public Page<User> getUserByCondition(int size, int page, User user) {
    Query query = new Query();
    Criteria criteria = new Criteria();

    if (!StringUtils.isEmpty(user.getName())) {
        criteria.and("name").is(user.getName());
    }
    if (!StringUtils.isEmpty(user.getDescription())) {
        criteria.and("description").regex(user.getDescription());
    }

    query.addCriteria(criteria);

    Sort sort = new Sort(Sort.Direction.DESC, "age");
    Pageable pageable = PageRequest.of(page, size, sort);

    List<User> users = template.find(query.with(pageable), User.class);
    return PageableExecutionUtils.getPage(users, pageable, () -> template.count(query, User.class));
}
 
Example 4
Source File: SimpleNeo4jRepository.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Page<T> findAll(Pageable pageable) {

	OngoingReadingAndReturn returning = cypherGenerator.prepareMatchOf(entityMetaData)
		.returning(cypherGenerator.createReturnStatementForMatch(entityMetaData));

	StatementBuilder.BuildableStatement returningWithPaging =
		addPagingParameter(entityMetaData, pageable, returning);

	Statement statement = returningWithPaging.build();

	List<T> allResult = this.neo4jOperations.findAll(statement, entityInformation.getJavaType());
	LongSupplier totalCountSupplier = this::count;
	return PageableExecutionUtils.getPage(allResult, pageable, totalCountSupplier);
}
 
Example 5
Source File: CodelessDaoProxy.java    From sca-best-practice with Apache License 2.0 5 votes vote down vote up
protected <T> Page<T> readPage(final Class<T> clazz, TypedQuery<T> query, Pageable pageable,
                               @Nullable Specification<T> spec) {

    if (pageable.isPaged()) {
        query.setFirstResult((int)pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }

    return PageableExecutionUtils.getPage(query.getResultList(), pageable,
        () -> executeCountQuery(getCountQuery(clazz, spec)));
}
 
Example 6
Source File: PageInfo.java    From springBoot with MIT License 5 votes vote down vote up
/**
 * 获取JPA的分页对象
 */
public static Page readPage(Query query, Pageable pageable, Query countQuery) {
    if (pageable.isPaged()) {
        query.setFirstResult((int) pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }
    return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery));
}
 
Example 7
Source File: PageInfo.java    From springBoot with MIT License 5 votes vote down vote up
/**
 * 获取JPA的分页对象
 */
public static Page readPage(Query query, Pageable pageable, Query countQuery) {
    if (pageable.isPaged()) {
        query.setFirstResult((int) pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }
    return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery));
}
 
Example 8
Source File: PageInfo.java    From base-admin with MIT License 5 votes vote down vote up
/**
 * 获取JPA的分页对象
 */
public static Page readPage(Query query, Pageable pageable, Query countQuery) {
    if (pageable.isPaged()) {
        query.setFirstResult((int) pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }
    return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery));
}
 
Example 9
Source File: BaseRepositoryImpl.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
protected <S extends DOMAIN> Page<S> readPage(TypedQuery<S> query, Class<S> domainClass, Pageable pageable, TypedQuery<Long> countQuery) {

        if (pageable.isPaged()) {
            query.setFirstResult((int) pageable.getOffset());
            query.setMaxResults(pageable.getPageSize());
        }

        return PageableExecutionUtils.getPage(query.getResultList(), pageable,
            () -> executeCountQuery(countQuery));
    }
 
Example 10
Source File: EbeanQueryWrapper.java    From spring-data-ebean with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
<E> Page<E> findPage(Pageable pageable) {
    if (queryType == QUERY) {
        PagedList<E> pagedList = ((Query<E>) queryInstance)
                .setFirstRow((int) pageable.getOffset())
                .setMaxRows(pageable.getPageSize())
                .findPagedList();
        return PageableExecutionUtils.getPage(pagedList.getList(), pageable, pagedList::getTotalCount);

    }
    throw new IllegalArgumentException("query not supported!");
}
 
Example 11
Source File: DeviceSearchRepository.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public Page<Device> search(String tenantId, String applicationName, String locationId, String tag, int page, int size) {
    PageRequest pageable = new PageRequest(page, size);

    Query query = new Query();
    query.with(pageable);

    List<Criteria> criterias = new ArrayList<>();
    criterias.add(Criteria.where("application.name").is(applicationName));

    if (StringUtils.isNotBlank(tag)) {
        criterias.add(Criteria.where("tags").in(tag));
    }

    if (StringUtils.isNotBlank(locationId)) {
        criterias.add(Criteria.where("location.id").is(locationId));
    }

    query.addCriteria(Criteria
            .where("tenant.id").is(tenantId)
            .andOperator(criterias.toArray(new Criteria[criterias.size()]))
    );

    List<Device> devices = mongoTemplate.find(query, Device.class);
    Page<Device> devicePage = PageableExecutionUtils.getPage(devices,
            pageable,
            () -> mongoTemplate.count(query, Device.class));
    return devicePage;

}
 
Example 12
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;
}