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:io.springagora.core.domain.Product.java

/**
 * Lists all products, using pagination.
 * //from w  ww . jav  a  2  s. c om
 * @param page  Page index that are going to be fetched.
 * @param size  Size of the elements in the page.
 * 
 * @return
 *      The representation of a {@code Page} object, with meta information
 *      and the list of products retrieved.
 */
public static Page<Product> findAll(int page, int size) {
    Pageable pagination = new PageRequest(page, size, new Sort("name"));
    return repository().findAll(pagination);
}

From source file:com.epam.ta.reportportal.core.log.impl.GetLogHandlerTest.java

@Test
public void testGetLogPageNumberDesc() {
    final PageRequest pageRequest = new PageRequest(0, 2, new Sort(Sort.Direction.DESC, "logTime"));

    final List<Log> logs = generateLogs(logRepository);
    final Log logToFind = logs.get(9);

    long pageNumber = prepareHandler().getPageNumber(logToFind.getId(), PROJECT_ID, Filter.builder()
            .withCondition(FilterCondition.builder().withCondition(Condition.EQUALS).withSearchCriteria("item")
                    .withValue(ITEM_ID).build())
            .withTarget(Log.class).build(),

            pageRequest);//  ww  w .  j a v  a2s .c  o m

    Assert.assertThat(pageNumber, Matchers.equalTo(1L));
}

From source file:cn.org.once.cstack.service.impl.MessageServiceImpl.java

@Override
public List<Message> listByApp(User user, String applicationName, int nbMessages) throws ServiceException {
    try {//  w w w.  j  a  va2  s .  c  o  m
        Pageable pageable = new PageRequest(0, nbMessages, sortByLastNameAsc());
        Page<Message> requestedPage = messageDAO.listByApp(user, applicationName, cuInstanceName, pageable);
        return requestedPage.getContent();
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:org.jblogcms.core.comment.service.CommentServiceImplTest.java

@Before
public void setUp() throws Exception {
    comment1.setId(COMMENT_1_ID);/* w  ww.  j a  va  2s .com*/
    comment1.setText(COMMENT_1_TEXT);

    comment2.setId(COMMENT_2_ID);
    comment2.setText(COMMENT_2_TEXT);

    comment3.setId(COMMENT_3_ID);
    comment3.setText(COMMENT_3_TEXT);

    existingComment.setId(EXISTING_COMMENT_ID);
    existingComment.setText(EXISTING_COMMENT_TEXT);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    comments = new PageImpl(commentList, pageable, COMMENTS_SIZE);
}

From source file:org.jblogcms.core.post.service.PostServiceImplTest.java

@Before
public void setUp() throws Exception {
    post1.setId(POST_1_ID);//w w w .  jav  a  2s  . c  om
    post1.setTitle(POST_1_TITLE);

    post2.setId(POST_2_ID);
    post2.setTitle(POST_2_TITLE);

    post3.setId(POST_3_ID);
    post3.setTitle(POST_3_TITLE);

    existingPost.setId(EXISTING_POST_ID);
    existingPost.setTitle(EXISTING_POST_TITLE);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    posts = new PageImpl(postList, pageable, POSTS_SIZE);
}

From source file:net.xqx.controller.web.MarkQueryController.java

/**
 * ?//from  ww w.  j a  v  a 2 s .  com
 * 
 * @return
 * @throws SQLException
 */
@RequestMapping("/markQuery")
public String markQuery(HttpServletRequest request) throws SQLException {
    TMark mark = null;
    String userName = request.getParameter("userName");
    String admissionNo = request.getParameter("admissionNo");
    String licenseNo = request.getParameter("licenseNo");
    String year = request.getParameter("year");

    String input = request.getParameter("rand");

    String rand = (String) request.getSession().getAttribute("rand");
    if (input != null && rand != null) {
        if (!input.equals(rand)) {
            request.setAttribute("CodeError2", "???");
            return "redirect:markList.do";
        }
    }
    System.out.println(System.getProperty("java.endorsed.dirs"));
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "spring/services.xml" });
    AchievementService achievementService = (AchievementService) context.getBean("achievement");
    List<Achievement> list = null;
    try {
        list = (List<Achievement>) achievementService.getAchievements(userName, admissionNo, licenseNo, year);
    } catch (SOAPFaultException e) {
        request.setAttribute("error", "??!");
    } catch (WebServiceException ex) {
        request.setAttribute("error", ",???!");
    }
    Achievement achievement = null;
    if (list != null && list.size() > 0) {
        achievement = list.get(0);
    }
    request.setAttribute("achievement", achievement);
    // 
    Sort hotNewsSort = new Sort(Direction.DESC, "fdjTimes", "ffbTime");
    Pageable hotNewsRecPageable = new PageRequest(0, 8, hotNewsSort);
    List<TNews> hotNewsList = newsDao.getHotNews(hotNewsRecPageable).getContent();
    request.setAttribute("hotNewsList", hotNewsList);

    // ??
    Sort recNewsSort = new Sort(Direction.DESC, "fIsRecord", "ffbTime");
    Pageable recNewsRecPageable = new PageRequest(0, 8, recNewsSort);
    List<TNews> recNewsList = newsDao.getNewsRec(recNewsRecPageable).getContent();
    request.setAttribute("recNewsList", recNewsList);
    request.setAttribute("mark", mark);
    return "web/markDetail";
}

From source file:org.jblogcms.core.account.service.AccountServiceImplTest.java

@Before
public void setUp() throws Exception {
    account1.setId(ACCOUNT_1_ID);/*from w  w w.j av a2 s.c o  m*/
    account1.setEmail(ACCOUNT_1_EMAIL);

    account2.setId(ACCOUNT_2_ID);
    account2.setEmail(ACCOUNT_2_EMAIL);

    account3.setId(ACCOUNT_3_ID);
    account3.setEmail(ACCOUNT_3_EMAIL);

    existingAccount.setId(EXISTING_ACCOUNT_ID);
    existingAccount.setEmail(EXISTING_ACCOUNT_EMAIL);

    Sort sort = new Sort(PAGEABLE_SORT);
    pageable = new PageRequest(PAGEABLE_PAGE, PAGEABLE_SIZE, sort);
    accounts = new PageImpl(accountList, pageable, ACCOUNTS_SIZE);
}

From source file:org.springside.examples.quickstart.service.BuyerDataService.java

/***/
private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
    Sort sort = null;/*w  w  w .  j av  a2 s  .co m*/
    if ("auto".equals(sortType)) {
        sort = new Sort(Direction.DESC, "id");
    } else if ("title".equals(sortType)) {
        sort = new Sort(Direction.ASC, "title");
    } else {
        sort = new Sort(Direction.ASC, "customerId");

    }
    return new PageRequest(pageNumber - 1, pagzSize, sort);
}

From source file:io.omatic.event.service.EventMaintainanceService.java

/**
 * Maintenance method used to keep the number of {@link Event} records in the database
 * at a manageable level. /*  w ww  . ja  v  a2 s  .c om*/
 * 
 * Note that this method can be scheduled. To do so specify a value for the externalised 
 * property eventomatic.maintenance.cronSchedule. The value must be in crontab format. For more information see 
 * <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html">here</a>
 */
@Transactional
@Scheduled(cron = "${eventomatic.maintenance.cronSchedule}")
public void maintainPoll() {

    // Firstly delete any events that are older than they should be, this will stop historic data clogging up the system. 0 disable
    if (applicationConfiguration.getMaintenance().getMaxAge() < 0) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, applicationConfiguration.getMaintenance().getMaxAge().intValue());
        Date maxAge = cal.getTime();

        long countOldEvents = eventRepository.countByRecievedDateBefore(maxAge);
        log.info("Checking for mesages older than {} and found {}", maxAge, countOldEvents);

        if (countOldEvents > 0) {
            log.info("Deleting {} events from before {}", countOldEvents, maxAge);
            eventRepository.deleteByRecievedDateBefore(maxAge);
            log.info("Deletion complete");
        }
    } else {
        log.info("Age based housekeeping disabled");
    }
    // Secondly, if the max events has exceeded the specified limit then trim the database. 0 or -1 will disable. 
    if (applicationConfiguration.getMaintenance().getEventLimit() > 0) {
        long countTotalEvents = eventRepository.count();
        Long overrun = countTotalEvents - applicationConfiguration.getMaintenance().getEventLimit();
        log.info("Checking for event count of greather than {} and found {}",
                applicationConfiguration.getMaintenance().getEventLimit(), countTotalEvents);
        if (overrun > 0) {
            Page<Event> events = eventRepository
                    .findAll(new PageRequest(0, overrun.intValue(), new Sort(Direction.ASC, "recievedDate")));
            eventRepository.deleteInBatch(events);
            log.info("Deleted {} of {} events.", overrun, countTotalEvents);
        }
    } else {
        log.info("Event limit based housekeeping disabled");
    }
}

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

@Test
public void testFindAllByPageableAndSortDesc() {
    int count = 15;
    User lastUser = null;//w  w w.  j av  a2  s .com
    for (int i = 0; i < count; i++) {
        lastUser = userService.save(createUser());
    }

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

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