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:com.epam.ta.reportportal.database.dao.UserRepositoryCustomImpl.java

@Override
public Page<User> findByTypeAndLastSynchronizedBefore(UserType type, Date lastSynchronized, Pageable pageable) {
    Query q = query(where("type").is(type).and(MetaInfo.SYNCHRONIZATION_DATE).lt(lastSynchronized))
            .with(pageable);//from  w w w.  j  av  a  2 s  .c o  m
    long count = mongoOperations.count(q, User.class);
    return new PageImpl<>(mongoOperations.find(q, User.class), pageable, count);

}

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

public Page<GeocodeResult> findPage(String query, Pageable pageable) {
    String countSql = String.format(COUNT_SQL, GEOCODE_SQL);
    Long total = getJdbcTemplate().queryForObject(countSql, new Object[] { query }, Long.class);
    List<GeocodeResult> content = findSlice(query, pageable).getContent();
    return new PageImpl<GeocodeResult>(content, pageable, total);
}

From source file:org.wallride.repository.CustomFieldRepositoryImpl.java

@Override
public Page<CustomField> search(CustomFieldSearchRequest request, Pageable pageable) {
    Session session = (Session) entityManager.getDelegate();
    Criteria criteria = session.createCriteria(CustomField.class).setFetchMode("options", FetchMode.JOIN);

    FullTextQuery persistenceQuery = buildFullTextQuery(request, pageable, criteria);
    int resultSize = persistenceQuery.getResultSize();
    List<CustomField> results = persistenceQuery.getResultList();
    return new PageImpl<>(results, pageable, resultSize);
}

From source file:com.jiwhiz.rest.site.PublicBlogRestControllerTest.java

@Test
public void getPublicBlogPosts_ShouldReturnAllPublicBlogPosts() throws Exception {
    Pageable pageable = new PageRequest(0, 10);
    when(blogPostRepositoryMock.findByPublishedIsTrueOrderByPublishedTimeDesc(any(Pageable.class)))
            .thenReturn(new PageImpl<BlogPost>(getTestPublishedBlogPostList(), pageable, 2));

    mockMvc.perform(get(API_ROOT + URL_SITE_BLOGS)).andExpect(status().isOk())
            .andExpect(content().contentType(MediaTypes.HAL_JSON))
            .andExpect(jsonPath("$._embedded.blogPostList", hasSize(2)))
            .andExpect(jsonPath("$._embedded.blogPostList[0].id", is(BLOGS_1_ID)))
            .andExpect(jsonPath("$._embedded.blogPostList[0].title", is(BLOGS_1_TITLE)))
            .andExpect(jsonPath("$._embedded.blogPostList[1].id", is(BLOGS_2_ID)))
            .andExpect(jsonPath("$._embedded.blogPostList[1].title", is(BLOGS_2_TITLE)))
            //check links
            .andExpect(jsonPath("$._links.self.templated", is(true)))
            .andExpect(jsonPath("$._links.self.href", endsWith("public/blogs{?page,size,sort}")))
            //check page
            .andExpect(jsonPath("$.page.size", is(10))).andExpect(jsonPath("$.page.totalElements", is(2)))
            .andExpect(jsonPath("$.page.totalPages", is(1))).andExpect(jsonPath("$.page.number", is(0)));

    verify(blogPostRepositoryMock, times(1)).findByPublishedIsTrueOrderByPublishedTimeDesc(pageable);
    verifyNoMoreInteractions(blogPostRepositoryMock);
}

From source file:org.openlmis.fulfillment.util.Pagination.java

/**
 * Returns the Page for the entirety of the specified list. Intended for use when the
 * supplied list already contains exactly the set of elements requested and there's
 * no need to return a subset of it./*  w  w w .  j a v  a 2s .co m*/
 */
public static <T> Page<T> getPage(List<T> subList, Pageable pageable, long fullListSize) {
    return new PageImpl<>(subList, pageable, fullListSize);
}

From source file:com.github.markserrano.jsonquery.jpa.service.FilterService.java

@Override
public Page<T> readAndCount(BooleanBuilder builder, Pageable page, Class<T> clazz, OrderSpecifier order,
        BooleanBuilder joinChildBuilder, String joinChildField, Class<?> joinChildClass) {
    Page<T> pageImpl = new PageImpl<T>(
            read(builder, page, clazz, order, joinChildBuilder, joinChildField, joinChildClass), page,
            count(builder, clazz, order, joinChildBuilder, joinChildField, joinChildClass));
    return pageImpl;
}

From source file:com.wiiyaya.framework.provider.repository.BaseDaoImpl.java

@Override
public Page<T> findAllJF(JF joinFetch, Pageable pageable) {
    JPQLQuery countQuery = createQuery();
    joinFetch.prepareQry(countQuery, false);
    Long total = countQuery.count();

    List<T> content = null;
    if (total > pageable.getOffset()) {
        JPQLQuery query = querydsl.applyPagination(pageable, createQuery());
        joinFetch.prepareQry(query, true);
        content = query.list(path);// w  w  w.  j  a  v  a2s  .  c o m
    } else {
        content = Collections.<T>emptyList();
    }
    return new PageImpl<T>(content, pageable, total);
}

From source file:com.sinosoft.one.data.jade.dataaccess.DataAccessImpl.java

/**
 *  2012-08-16//from  w  w w.j  a  va  2s  .  c o m
 */
public <T> Page<T> selectByPage(Pageable pageable, String sql, String countSql, Object[] args,
        RowMapper<?> rowMapper) {
    Session session = em.unwrap(Session.class);
    SingleColumnRowMapper<BigDecimal> scrm = new SingleColumnRowMapper<BigDecimal>();
    List<BigDecimal> totals = select(countSql, args, scrm);
    RenderSqlWork psw = new RenderSqlWork(sql, pageable, null);
    session.doWork(psw);
    sql = psw.getSql();
    List<T> content = select(sql, args, rowMapper);
    if (content == null) {
        content = new ArrayList<T>();
    }
    Object o = totals.get(0);
    Number num = (Number) o;
    Page<T> page = new PageImpl<T>(content, pageable, num.longValue());
    return page;
}

From source file:com.yqboots.fss.web.controller.FileItemController.java

@PreAuthorize(FileItemPermissions.READ)
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public String list(@ModelAttribute(WebKeys.SEARCH_FORM) final SearchForm<String> searchForm,
        @PageableDefault final Pageable pageable, final ModelMap model) throws IOException {
    if (StringUtils.isBlank(searchForm.getCriterion())) {
        model.addAttribute(WebKeys.PAGE, new PageImpl<FileItem>(new ArrayList<>(), pageable, 0));
        return VIEW_HOME;
    }/*from  w  ww  .  jav  a 2s  .  c  om*/

    model.addAttribute(WebKeys.PAGE, fileItemManager.findByPath(searchForm.getCriterion(), pageable));
    return VIEW_HOME;
}

From source file:br.com.joaops.awc.service.SystemUserServiceImpl.java

@Transactional(readOnly = true)
@Override/*from  w  w w  . j ava2 s  .  c om*/
public Page<SystemUserDto> searchAllUsers(Pageable p) {
    List<SystemUserDto> usersDto = new ArrayList<>();
    Page<SystemUser> systemUsers = repository.findAll(p);
    for (SystemUser systemUser : systemUsers) {
        SystemUserDto userDto = new SystemUserDto();
        mapper.map(systemUser, userDto);
        usersDto.add(userDto);
    }
    Page<SystemUserDto> page = null;
    if (!usersDto.isEmpty()) {
        page = new PageImpl<>(usersDto, p, systemUsers.getTotalElements());
    }
    return page;
}