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

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

Introduction

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

Prototype

protected PageRequest(int page, int size, Sort sort) 

Source Link

Document

Creates a new PageRequest with sort parameters applied.

Usage

From source file:com.luna.common.service.UserServiceTest.java

@Test
public void testFindAllByPageableAndSortAsc() {
    int count = 15;
    User lastUser = null;/*from w  w  w . j av  a2s . co  m*/
    for (int i = 0; i < count; i++) {
        lastUser = userService.save(createUser());
    }

    Sort sortAsc = new Sort(Sort.Direction.ASC, "id");
    Pageable pageable = new PageRequest(0, 5, sortAsc);
    Page<User> userPage = userService.findAll(pageable);

    assertEquals(5, userPage.getNumberOfElements());
    assertFalse(userPage.getContent().contains(lastUser));
    assertTrue(userPage.getContent().get(0).getId() < userPage.getContent().get(1).getId());
}

From source file:app.service.CollectionService.java

public List<Collection> findByUser(String uid, int page, int size) {
    if (StringUtils.isEmpty(uid)) {
        return null;
    }//from  w ww. j av  a  2s  . c  o  m

    User user = prepareUser(uid);
    Page<Collection> colPage = mColRepo.findByUser(user, new PageRequest(page, size, mLatestSort));
    List<Collection> colList = getFromPage(colPage, false);
    colList.forEach(collection -> fillCollection(collection, uid));
    return colList;
}

From source file:org.devgateway.toolkit.forms.wicket.providers.AbstractJpaRepositoryTextChoiceProvider.java

public Page<T> findAll(final int page) {
    PageRequest pageRequest = new PageRequest(page, WebConstants.SELECT_PAGE_SIZE, sort);
    return getTextSearchableRepository().findAll(pageRequest);
}

From source file:io.springagora.core.domain.Product.java

/**
 * Lists all products that belongs to a given category.
 * /*from   www .  j  a v a2s .  c  om*/
 * @param category  Category for reference in the search.
 * @param page      Page index that are going to be fetched.
 * @param size      Size of the elements in the page.
 * 
 * @return
 *      A list of products that should be shown in the showcase. In case no
 *      products are found for the category, returns an empty list.
 */
public static Page<Product> findByCategory(Category category, int page, int size) {
    Pageable pagination = new PageRequest(page, size, new Sort("name"));
    return repository().findByCategory(category, pagination);
}