Java Code Examples for org.springframework.data.repository.support.PageableExecutionUtils

The following examples show how to use org.springframework.data.repository.support.PageableExecutionUtils. These examples are extracted from open source projects. 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 Project: sdn-rx   Source File: AbstractNeo4jQuery.java    License: 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 Project: sdn-rx   Source File: SimpleQueryByExampleExecutor.java    License: 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 Project: SpringAll   Source File: UserService.java    License: 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 Project: sdn-rx   Source File: SimpleNeo4jRepository.java    License: 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 Project: sca-best-practice   Source File: CodelessDaoProxy.java    License: 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 Project: springBoot   Source File: PageInfo.java    License: 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 Project: springBoot   Source File: PageInfo.java    License: 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 Project: base-admin   Source File: PageInfo.java    License: 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 Project: halo   Source File: BaseRepositoryImpl.java    License: 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 Project: spring-data-ebean   Source File: EbeanQueryWrapper.java    License: 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 Project: konker-platform   Source File: DeviceSearchRepository.java    License: 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
@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;
}