Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content, Pageable pageable, long total) 

Source Link

Document

Constructor of PageImpl .

Usage

From source file:org.springframework.cloud.dataflow.server.service.impl.AbstractStreamService.java

@Override
public Page<StreamDefinition> findDefinitionByNameLike(Pageable pageable, String search) {
    Page<StreamDefinition> streamDefinitions;
    if (search != null) {
        final SearchPageable searchPageable = new SearchPageable(pageable, search);
        searchPageable.addColumns("DEFINITION_NAME", "DEFINITION");
        streamDefinitions = streamDefinitionRepository.findByNameLike(searchPageable);
        long count = streamDefinitions.getContent().size();
        long to = Math.min(count, pageable.getOffset() + pageable.getPageSize());
        streamDefinitions = new PageImpl<>(streamDefinitions.getContent(), pageable,
                streamDefinitions.getTotalElements());
    } else {/*from  w  ww.j a  va2  s  . co m*/
        streamDefinitions = streamDefinitionRepository.findAll(pageable);
    }
    return streamDefinitions;
}

From source file:org.springframework.cloud.dataflow.server.stream.AppDeployerStreamDeployer.java

@Override
public Page<AppStatus> getAppStatuses(Pageable pageable) throws ExecutionException, InterruptedException {

    Iterable<StreamDefinition> streamDefinitions = this.streamDefinitionRepository.findAll();
    Iterable<StreamDeployment> streamDeployments = this.streamDeploymentRepository.findAll();

    List<String> appDeployerStreams = new ArrayList<>();
    for (StreamDeployment streamDeployment : streamDeployments) {
        appDeployerStreams.add(streamDeployment.getStreamName());

    }//  w w w. j  ava2s .co  m

    List<StreamDefinition> appDeployerStreamDefinitions = new ArrayList<>();
    for (StreamDefinition streamDefinition : streamDefinitions) {
        if (appDeployerStreams.contains(streamDefinition.getName())) {
            appDeployerStreamDefinitions.add(streamDefinition);
        }
    }

    // First build a sorted list of deployment id's so that we have a predictable paging order.
    List<String> deploymentIds = appDeployerStreamDefinitions.stream()
            .flatMap(sd -> sd.getAppDefinitions().stream()).flatMap(sad -> {
                String key = DeploymentKey.forStreamAppDefinition(sad);
                String id = this.deploymentIdRepository.findOne(key);
                return id != null ? Stream.of(id) : Stream.empty();
            }).sorted(String::compareTo).collect(Collectors.toList());

    // Running this this inside the FJP will make sure it is used by the parallel stream
    // Skip first items depending on page size, then take page and discard rest.
    List<AppStatus> content = this.forkJoinPool.submit(() -> deploymentIds.stream()
            .skip(pageable.getPageNumber() * pageable.getPageSize()).limit(pageable.getPageSize()).parallel()
            .map(appDeployer::status).collect(Collectors.toList())).get();
    return new PageImpl<>(content, pageable, deploymentIds.size());
}

From source file:org.springframework.cloud.dataflow.server.stream.SkipperStreamDeployer.java

@Override
public Page<AppStatus> getAppStatuses(Pageable pageable) {
    List<String> skipperStreams = new ArrayList<>();
    Iterable<StreamDefinition> streamDefinitions = this.streamDefinitionRepository.findAll();
    for (StreamDefinition streamDefinition : streamDefinitions) {
        skipperStreams.add(streamDefinition.getName());
    }/*from ww  w  .  jav a  2s.c  om*/

    List<AppStatus> allStatuses = getStreamsStatuses(skipperStreams);

    List<AppStatus> pagedStatuses = allStatuses.stream().skip(pageable.getPageNumber() * pageable.getPageSize())
            .limit(pageable.getPageSize()).parallel().collect(Collectors.toList());

    return new PageImpl<>(pagedStatuses, pageable, allStatuses.size());
}

From source file:org.springframework.data.document.mongodb.repository.QueryDslMongoRepository.java

public Page<T> findAll(Predicate predicate, Pageable pageable) {

    MongodbQuery<T> countQuery = createQueryFor(predicate);
    MongodbQuery<T> query = createQueryFor(predicate);

    return new PageImpl<T>(applyPagination(query, pageable).list(), pageable, countQuery.count());
}

From source file:org.springframework.data.jpa.repository.support.SimpleJpaRepository.java

/**
 * Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and
 * {@link Specification}./*  w w  w.  jav a  2 s  .  c om*/
 * 
 * @param query must not be {@literal null}.
 * @param spec can be {@literal null}.
 * @param pageable can be {@literal null}.
 * @return
 */
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, Specification<T> spec) {

    query.setFirstResult(pageable.getOffset());
    query.setMaxResults(pageable.getPageSize());

    Long total = QueryUtils.executeCountQuery(getCountQuery(spec));
    List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T>emptyList();

    return new PageImpl<T>(content, pageable, total);
}

From source file:org.springframework.data.solr.core.ResultHelper.java

static <T> Map<Object, GroupResult<T>> convertGroupQueryResponseToGroupResultMap(Query query,
        Map<String, Object> objectNames, QueryResponse response, SolrTemplate solrTemplate, Class<T> clazz) {

    GroupResponse groupResponse = response.getGroupResponse();

    if (groupResponse == null) {
        return Collections.emptyMap();
    }//from   ww  w  .  j  a  v a2 s .  co m

    Map<Object, GroupResult<T>> result = new LinkedHashMap<Object, GroupResult<T>>();

    List<GroupCommand> values = groupResponse.getValues();
    for (GroupCommand groupCommand : values) {

        List<GroupEntry<T>> groupEntries = new ArrayList<GroupEntry<T>>();

        for (Group group : groupCommand.getValues()) {

            SolrDocumentList documentList = group.getResult();
            List<T> beans = solrTemplate.convertSolrDocumentListToBeans(documentList, clazz);
            Page<T> page = new PageImpl<T>(beans, query.getGroupOptions().getPageRequest(),
                    documentList.getNumFound());
            groupEntries.add(new SimpleGroupEntry<T>(group.getGroupValue(), page));
        }

        int matches = groupCommand.getMatches();
        Integer ngroups = groupCommand.getNGroups();
        String name = groupCommand.getName();

        PageImpl<GroupEntry<T>> page;
        if (ngroups != null) {
            page = new PageImpl<GroupEntry<T>>(groupEntries, query.getPageRequest(), ngroups.intValue());
        } else {
            page = new PageImpl<GroupEntry<T>>(groupEntries);
        }

        SimpleGroupResult<T> groupResult = new SimpleGroupResult<T>(matches, ngroups, name, page);
        result.put(name, groupResult);
        if (objectNames.containsKey(name)) {
            result.put(objectNames.get(name), groupResult);
        }
    }

    return result;
}

From source file:piecework.repository.concrete.ProcessInstanceRepositoryCustomImpl.java

@Override
public Page<ProcessInstance> findByQuery(Query query, Pageable request, boolean includeTotal) {
    long start = 0;
    if (LOG.isDebugEnabled())
        start = System.currentTimeMillis();

    List<ProcessInstance> processInstances = mongoOperations.find(query.with(request), ProcessInstance.class);

    long total = 0;

    // We only need to look up a total if we're not on the first page or the page is full
    if (includeTotal) {
        if (query.getSkip() > 0 || processInstances.size() == query.getLimit())
            total = mongoOperations.count(query, ProcessInstance.class);
        else/*from ww  w .  j a v a2 s  .c o  m*/
            total = processInstances.size();
    }

    Page<ProcessInstance> page = new PageImpl<ProcessInstance>(processInstances, request, total);
    if (LOG.isDebugEnabled())
        LOG.debug("Retrieved instances by criteria in " + (System.currentTimeMillis() - start) + " ms");

    return page;
}

From source file:siddur.solidtrust.autoscout.AutoscoutService.java

public Page<ScoutCar> timeOnSale(Pageable pageable, String brand, String model, String build) {
    String baseJpql = "from AutoscoutNl m where m.dateRegisted is not null and m.repetition is null";
    if (!StringUtils.isEmpty(brand)) {
        baseJpql += " and m.brand = '" + brand + "'";
    }/*from w  w  w . ja  v  a2s .  com*/
    if (!StringUtils.isEmpty(model)) {
        baseJpql += " and m.model = '" + model + "'";
    }
    if (!StringUtils.isEmpty(build)) {
        baseJpql += " and m.build = '" + build + "'";
    }

    long count = em.createQuery("select count(m) " + baseJpql, Long.class).getSingleResult();

    String jpql = selectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<ScoutCar> results = ScoutCar.toScoutCarList(list, true);
    Page<ScoutCar> page = new PageImpl<ScoutCar>(results, pageable, (int) count);
    return page;
}

From source file:siddur.solidtrust.autoscout.AutoscoutService.java

public Page<ScoutCar> top100Detail(Pageable pageable, Fast100 f, String type, int index, String name) {
    String baseJpql = "from AutoscoutNl m where m.dateRegisted is not null" + " and m.repetition is null"
            + " and m.brand = '" + f.getBrand() + "' and m.model = '" + f.getModel() + "' and m.build = '"
            + f.getBuild() + "' and m.enginesize = " + f.getEngineSize() + " and m.fuel = '" + f.getFuelType()
            + "' and m.arrangement = '" + f.getArrangement() + "'";

    if (type.equals("color")) {
        baseJpql += " and m.color='" + name + "'";
    } else {/*w  w w .  j  a  v a  2  s .  co  m*/
        Integer[] range = type.equals("price") ? Sorter.PRICE_RANGE : Sorter.MILEAGE_RANGE;
        if (index == 0) {
            baseJpql += " and m." + type + " < " + range[index];
        } else if (index == range.length) {
            baseJpql += " and m." + type + " >= " + range[index - 1];
        } else {
            baseJpql += " and m." + type + " < " + range[index];
            baseJpql += " and m." + type + " >= " + range[index - 1];
        }
    }

    String jpql = selectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<ScoutCar> results = ScoutCar.toScoutCarList(list, true);

    long count = em.createQuery("select count(m) " + baseJpql, Long.class).getSingleResult();
    Page<ScoutCar> page = new PageImpl<ScoutCar>(results, pageable, (int) count);
    return page;
}

From source file:siddur.solidtrust.autoscoutde.AutoscoutDeService.java

public Page<ScoutCar> timeOnSale(Pageable pageable, String brand, String model, String build) {
    String baseJpql = "from AutoscoutDe m where m.dateRemoved != '0000-00-00'";
    if (!StringUtils.isEmpty(brand)) {
        baseJpql += " and m.brand = '" + brand + "'";
    }/* ww  w . j ava  2  s . c om*/
    if (!StringUtils.isEmpty(model)) {
        baseJpql += " and m.model = '" + model + "'";
    }
    if (!StringUtils.isEmpty(build)) {
        baseJpql += " and m.build = '" + build + "'";
    }

    long count = em.createQuery("select count(m) " + baseJpql, Long.class).getSingleResult();

    String jpql = selectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<ScoutCar> results = ScoutCar.toScoutCarList(list, true);
    Page<ScoutCar> page = new PageImpl<ScoutCar>(results, pageable, (int) count);
    return page;
}