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.venice.piazza.common.hibernate.dao.service.ServiceDaoImpl.java

public Page<ServiceEntity> getServiceListForUserAndKeyword(String keyword, String userName,
        Pagination pagination) {/*www .  jav a  2 s. c o  m*/
    // Query
    String queryString = String.format(USERNAME_AND_KEYWORD_SERVICE_QUERY,
            Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, ServiceEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName));
    query.setParameter(4, pagination.getSortBy());
    query.setParameter(5, pagination.getPerPage());
    query.setParameter(6, pagination.getPage() * pagination.getPerPage());
    List<ServiceEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(USERNAME_AND_KEYWORD_SERVICE_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<ServiceEntity>(results, null, count);
}

From source file:it.f2informatica.core.gateway.mysql.ConsultantRepositoryGatewayMySQL.java

@Override
public Page<ConsultantModel> paginateConsultants(ConsultantSearchCriteria searchCriteria, Pageable pageable) {
    Page<Consultant> consultantPage = consultantRepository.findAll(whereCondition(searchCriteria), pageable);
    return new PageImpl<>(mysqlConsultantToModelConverter.convertList(consultantPage.getContent()), pageable,
            consultantPage.getTotalElements());
}

From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java

@SuppressWarnings("unchecked")
@Override//  w  w w  . j av a  2  s. c  o  m
public Page<T> findAllFetchEagerly(Pageable pageable, Set<Criterion> criterions, String... associations) {
    //http://stackoverflow.com/questions/2183617/criteria-api-returns-a-too-small-resultset

    //get the ids of every object that matches the pageable conditions
    //we cannot get the objects directly because we use FetchMode.JOIN which returns the scalar product of all rows in all affected tables
    //and CriteriaSpecification.DISTINCT_ROOT_ENTITY does not work on SQL Level but on in Java after the result is returned from SQL
    Criteria criteria = getPageableCriteria(pageable);
    if (criterions != null) {
        for (Criterion c : criterions) {
            criteria.add(c);
        }
    }
    criteria.setProjection(Projections.distinct(Projections.property("id")));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<Long> list = criteria.list();

    //once we have the required ids we query for the complete objects
    Criteria objectCriteria = getCriteria();
    for (String association : associations) {
        objectCriteria.setFetchMode(association, FetchMode.JOIN);
    }
    if (!list.isEmpty()) {
        objectCriteria.add(Restrictions.in("id", list));
    }
    objectCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    addOrderBy(objectCriteria, pageable);
    List<T> objects = objectCriteria.list();
    sort(objects);

    //we also need the total number of rows
    Criteria rowCountCritieria = getCriteria();
    if (criterions != null) {
        for (Criterion c : criterions) {
            rowCountCritieria.add(c);
        }
    }
    rowCountCritieria.setProjection(Projections.rowCount());
    Long resultCount = (Long) rowCountCritieria.uniqueResult();
    if (resultCount == null) {
        resultCount = objects.size() + 0L;
    }
    Collections.sort(objects);
    PageImpl<T> page = new PageImpl<>(new ArrayList<>(objects), pageable, resultCount);
    return page;
}

From source file:at.plechinger.minigeocode.repository.GeocodeRepository.java

public Page<ReverseGeocodeResult> findReversePage(Double longitude, Double latitude, Pageable pageable) {
    String countSql = String.format(COUNT_SQL, REVERSE_GEOCODE_SQL);

    Long total = getJdbcTemplate().queryForObject(countSql, new Object[] { longitude, latitude }, Long.class);
    List<ReverseGeocodeResult> content = findReverseSlice(longitude, latitude, pageable).getContent();
    return new PageImpl<ReverseGeocodeResult>(content, pageable, total);
}

From source file:com.wiiyaya.framework.provider.repository.revision.BaseRevisionDaoImpl.java

@SuppressWarnings("unchecked")
public Page<Revision<N, T>> findRevisions(ID id, Pageable pageable) {

    Class<T> type = entityInformation.getJavaType();
    AuditReader reader = AuditReaderFactory.get(entityManager);
    List<Number> revisionNumbers = reader.getRevisions(type, id);

    if (pageable.getOffset() > revisionNumbers.size()) {
        return new PageImpl<Revision<N, T>>(Collections.<Revision<N, T>>emptyList(), pageable, 0);
    }//from  ww w  .j  a  va 2  s  .  c  o  m

    int upperBound = pageable.getOffset() + pageable.getPageSize();
    upperBound = upperBound > revisionNumbers.size() ? revisionNumbers.size() : upperBound;

    List<? extends Number> subList = revisionNumbers.subList(pageable.getOffset(), upperBound);
    Revisions<N, T> revisions = getEntitiesForRevisions((List<N>) subList, id, reader);

    return new PageImpl<Revision<N, T>>(revisions.getContent(), pageable, revisionNumbers.size());
}

From source file:com.expedia.seiso.web.hateoas.link.PaginationLinkBuilderTests.java

private PaginationLinkBuilder paginationLinkBuilder(int pageNumber, int pageSize, int totalItems) {
    val pageable = new PageRequest(pageNumber, pageSize);
    val page = new PageImpl(Collections.EMPTY_LIST, pageable, totalItems);
    return new PaginationLinkBuilder(page, uriComponents, params);
}

From source file:br.com.joaops.smt.service.SystemUserPermissionServiceImpl.java

@Transactional(readOnly = true)
@Override//ww w .  j a  va  2  s. c om
public Page<SystemUserPermissionDto> searchAllUsersPermissions(Pageable p) {
    List<SystemUserPermissionDto> permissionDtos = new ArrayList<>();
    Page<SystemUserPermission> permissions = repository.findAll(p);
    for (SystemUserPermission permission : permissions) {
        SystemUserPermissionDto permissionDto = new SystemUserPermissionDto();
        mapper.map(permission, permissionDto);
        permissionDtos.add(permissionDto);
    }
    Page<SystemUserPermissionDto> page = null;
    if (!permissionDtos.isEmpty()) {
        page = new PageImpl<>(permissionDtos, p, permissionDtos.size());
    }
    return page;
}

From source file:siddur.solidtrust.image.ImageController.java

@RequestMapping(value = "/image/search")
@Transactional(readOnly = true)// w  w w . j a  v  a  2 s.c  o  m
public String search(@RequestParam(value = "key", required = false) String key,
        @RequestParam(value = "type", required = false, defaultValue = "1") int type,
        @RequestParam(value = "page", required = false, defaultValue = "1") Integer pageIndex, Model model)
        throws Exception {
    int pageSize = 8;
    if (type == 1) {
        //Search by keywords
        if (!StringUtils.isEmpty(key)) {
            FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
            QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
                    .forEntity(ImageProduct.class).get();
            Query query = qb.keyword().onFields("brand", "type", "arrangement", "buildYear")
                    .matching(key.toLowerCase()).createQuery();
            FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(query,
                    ImageProduct.class);

            persistenceQuery.setMaxResults(pageSize);
            persistenceQuery.setFirstResult((pageIndex - 1) * pageSize);
            @SuppressWarnings("unchecked")
            List<ImageProduct> ips = persistenceQuery.getResultList();
            Pageable pageable = new PageRequest(pageIndex - 1, pageSize);
            Page<ImageProduct> page = new PageImpl<ImageProduct>(ips, pageable,
                    persistenceQuery.getResultSize());
            model.addAttribute("page", page);
        }
    } else if (type == 2) {
        //Search by license plate
        if (key != null) {
            ImageProduct ip = findImagesByLicensePlate(key);
            model.addAttribute("ip", ip);
        }
    }

    model.addAttribute("key", key);
    return "image/search";
}

From source file:org.venice.piazza.common.hibernate.dao.deployment.DeploymentDaoImpl.java

public Page<DeploymentEntity> getDeploymentListByDataId(String keyword, Pagination pagination) {
    // Query/*from w  w  w. jav a 2s .  c  om*/
    String queryString = String.format(KEYWORD_DATA_ID_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(KEYWORD_DATA_ID_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

From source file:com.expedia.seiso.web.assembler.ResourceAssemblerTests.java

private void setUpTestData() {
    this.queryMethod = ReflectionUtils.findMethod(ServiceRepo.class, "findByName", String.class);
    this.queryMethods = Arrays.asList(queryMethod);

    when(repoInfo.getQueryMethods()).thenReturn(queryMethods);

    // @formatter:off
    this.person = new Person().setUsername("mkozelek").setFirstName("Mark").setLastName("Kozelek");
    this.service = new Service().setKey("benji").setName("Benji").setDescription("My Benji service")
            .setOwner(person);/*from   w  ww . j a v a 2s  .c  o  m*/
    // @formatter:on

    this.itemList = Arrays.asList(service);
    this.itemPage = new PageImpl<Service>(itemList, PAGE_REQUEST, 8675309);
}