Java Code Examples for org.springframework.data.domain.Page#nextPageable()
The following examples show how to use
org.springframework.data.domain.Page#nextPageable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpaSystemManagement.java From hawkbit with Eclipse Public License 1.0 | 7 votes |
@Override @Transactional(propagation = Propagation.NOT_SUPPORTED) // Exception squid:S2229 - calling findTenants without transaction is // intended in this case @SuppressWarnings("squid:S2229") public void forEachTenant(final Consumer<String> consumer) { Page<String> tenants; Pageable query = PageRequest.of(0, MAX_TENANTS_QUERY); do { tenants = findTenants(query); tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> { try { consumer.accept(tenant); } catch (final RuntimeException ex) { LOGGER.debug("Exception on forEachTenant execution for tenant {}. Continue with next tenant.", tenant, ex); LOGGER.error("Exception on forEachTenant execution for tenant {} with error message [{}]. " + "Continue with next tenant.", tenant, ex.getMessage()); } return null; })); } while ((query = tenants.nextPageable()) != Pageable.unpaged()); }
Example 2
Source File: PageableMemoRepositoryIT.java From spring-data-cosmosdb with MIT License | 6 votes |
private Set<PageableMemo> findAllWithPageSize(int pageSize) { final CosmosPageRequest pageRequest = new CosmosPageRequest(0, pageSize, null); Page<PageableMemo> page = repository.findAll(pageRequest); final Set<PageableMemo> outputSet = new HashSet<>(page.getContent()); while (page.hasNext()) { final Pageable pageable = page.nextPageable(); page = repository.findAll(pageable); outputSet.addAll((page.getContent())); } return outputSet; }
Example 3
Source File: PageablePersonRepositoryIT.java From spring-data-cosmosdb with MIT License | 6 votes |
private Set<PageablePerson> findAllWithPageSize(int pageSize, boolean checkContentLimit) { final CosmosPageRequest pageRequest = new CosmosPageRequest(0, pageSize, null); Page<PageablePerson> page = repository.findAll(pageRequest); final Set<PageablePerson> outputSet = new HashSet<>(page.getContent()); if (checkContentLimit) { // Make sure CosmosDB returns less number of documents than requested // This will verify the functionality of new pagination implementation assertThat(page.getContent().size()).isLessThan(pageSize); } while (page.hasNext()) { final Pageable pageable = page.nextPageable(); page = repository.findAll(pageable); outputSet.addAll((page.getContent())); } return outputSet; }
Example 4
Source File: PageDTO.java From heimdall with Apache License 2.0 | 5 votes |
public static <T> PageDTO<T> build(Page<T> p) { if (p == null){ return null; } else { PageDTO<T> page = new PageDTO<>(); page.setContent(p.getContent()); page.setHasContent(p.hasContent()); page.setNumber(p.getNumber()); page.setNumberOfElements(p.getNumberOfElements()); page.setSize(p.getSize()); page.setTotalElements(p.getTotalElements()); page.setTotalPages(p.getTotalPages()); page.setHasNextPage(p.hasNext()); page.setHasPreviousPage(p.hasPrevious()); page.setFirst(p.isFirst()); page.setLast(p.isLast()); if (p.previousPageable() != null) { page.setPreviousPage(p.previousPageable().getPageNumber()); } if (p.nextPageable() != null) { page.setNextPage(p.nextPageable().getPageNumber()); } return page; } }
Example 5
Source File: SimpleHazelcastRepositoryIT.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
@Test public void findAll_Pageable() { Set<String> yearsExpected = new TreeSet<>(); for (Object[] datum : TestData.bestMakeUp) { yearsExpected.add(datum[0].toString()); } Pageable pageRequest = PageRequest.of(PAGE_0, SIZE_10); Page<Makeup> pageResponse = this.theRepository.findAll(pageRequest); int page = 0; while (pageResponse != null) { assertThat("Page " + page + ", has content", pageResponse.hasContent(), equalTo(true)); List<Makeup> makeups = pageResponse.getContent(); assertThat("Page " + page + ", has makeups", makeups.size(), greaterThan(0)); for (Makeup makeup : makeups) { assertThat(makeup.toString(), yearsExpected.contains(makeup.getId()), equalTo(true)); yearsExpected.remove(makeup.getId()); } if (pageResponse.hasNext()) { pageRequest = pageResponse.nextPageable(); pageResponse = this.theRepository.findAll(pageRequest); } else { pageResponse = null; } page++; } assertThat("All years matched", yearsExpected, hasSize(0)); }
Example 6
Source File: PersistenceTests.java From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License | 4 votes |
private Pageable testNextPage(Pageable nextPage, String expectedProductIds, boolean expectsNextPage) { Page<ProductEntity> productPage = repository.findAll(nextPage); assertEquals(expectedProductIds, productPage.getContent().stream().map(p -> p.getProductId()).collect(Collectors.toList()).toString()); assertEquals(expectsNextPage, productPage.hasNext()); return productPage.nextPageable(); }
Example 7
Source File: ProbeServiceImpl.java From WIFIProbe with Apache License 2.0 | 4 votes |
@Override public Page<ProbeVo> findAll(int page, int size) { Page<ProbeEntity> probeEntities = probeDao.findAll(page, size); return new PageImpl<>(probeEntities.getContent().stream().map(ProbeVo::new).collect(Collectors.toList()), probeEntities.nextPageable(),probeEntities.getTotalElements()); }
Example 8
Source File: SimpleTaskExplorerTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
private void verifyPageResults(Pageable pageable, int totalNumberOfExecs) { Map<Long, TaskExecution> expectedResults = createSampleDataSet( totalNumberOfExecs); List<Long> sortedExecIds = getSortedOfTaskExecIds(expectedResults); Iterator<Long> expectedTaskExecutionIter = sortedExecIds.iterator(); // Verify pageable totals Page<TaskExecution> taskPage = this.taskExplorer.findAll(pageable); int pagesExpected = (int) Math .ceil(totalNumberOfExecs / ((double) pageable.getPageSize())); assertThat(taskPage.getTotalPages()) .as("actual page count return was not the expected total") .isEqualTo(pagesExpected); assertThat(taskPage.getTotalElements()) .as("actual element count was not the expected count") .isEqualTo(totalNumberOfExecs); // Verify pagination Pageable actualPageable = PageRequest.of(0, pageable.getPageSize()); boolean hasMorePages = taskPage.hasContent(); int pageNumber = 0; int elementCount = 0; while (hasMorePages) { taskPage = this.taskExplorer.findAll(actualPageable); hasMorePages = taskPage.hasNext(); List<TaskExecution> actualTaskExecutions = taskPage.getContent(); int expectedPageSize = pageable.getPageSize(); if (!hasMorePages && pageable.getPageSize() != actualTaskExecutions.size()) { expectedPageSize = totalNumberOfExecs % pageable.getPageSize(); } assertThat(actualTaskExecutions.size()).as(String.format( "Element count on page did not match on the %n page", pageNumber)) .isEqualTo(expectedPageSize); for (TaskExecution actualExecution : actualTaskExecutions) { assertThat(actualExecution.getExecutionId()) .as(String.format("Element on page %n did not match expected", pageNumber)) .isEqualTo((long) expectedTaskExecutionIter.next()); TestVerifierUtils.verifyTaskExecution( expectedResults.get(actualExecution.getExecutionId()), actualExecution); elementCount++; } actualPageable = taskPage.nextPageable(); pageNumber++; } // Verify actual totals assertThat(pageNumber).as("Pages processed did not equal expected") .isEqualTo(pagesExpected); assertThat(elementCount).as("Elements processed did not equal expected,") .isEqualTo(totalNumberOfExecs); }
Example 9
Source File: QueryIT.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
@Test public void findByOrderByLastnameDesc() { Person robert = new Person(); robert.setId("1980"); robert.setFirstname("Robert"); robert.setLastname("De Niro"); this.personMap.put(robert.getId(), robert); Person henry = new Person(); henry.setId("1981"); henry.setFirstname("Henry"); henry.setLastname("Fonda"); this.personMap.put(henry.getId(), henry); Person ben = new Person(); ben.setId("1982"); ben.setFirstname("Ben"); ben.setLastname("Kingsley"); this.personMap.put(ben.getId(), ben); int expectedNumberOfPages = this.personMap.size() / SIZE_3; int pagesRetrieved = 0; String previousLastname = null; Pageable pageRequest = PageRequest.of(PAGE_0, SIZE_3); Page<Person> pageResponse = this.personRepository.findByOrderByLastnameDesc(pageRequest); while (pageResponse != null) { assertThat("Not more than expected pages", pagesRetrieved, lessThan(expectedNumberOfPages)); pagesRetrieved++; assertThat("Page " + pagesRetrieved + " has content", pageResponse.hasContent(), equalTo(true)); List<Person> pageContent = pageResponse.getContent(); assertThat("Page " + pagesRetrieved + " content not null", pageContent, notNullValue()); assertThat("Page " + pagesRetrieved + " content not empty", pageContent.size(), greaterThan(0)); assertThat("Page " + pagesRetrieved + ", this page number", pageResponse.getNumber(), equalTo(pagesRetrieved - 1)); assertThat("Page " + pagesRetrieved + ", total page number", pageResponse.getTotalPages(), equalTo(expectedNumberOfPages)); assertThat("Page " + pagesRetrieved + ", item count v content", pageResponse.getNumberOfElements(), equalTo(pageContent.size())); if (pagesRetrieved != expectedNumberOfPages) { assertThat("Page " + pagesRetrieved + ", item count", pageResponse.getNumberOfElements(), equalTo(5)); } else { assertThat("Page " + pagesRetrieved + ", item count", pageResponse.getNumberOfElements(), greaterThan(0)); assertThat("Page " + pagesRetrieved + ", item count", pageResponse.getNumberOfElements(), lessThanOrEqualTo(SIZE_3)); } assertThat("Page " + pagesRetrieved + ", total item count", pageResponse.getTotalElements(), equalTo((long) this.personMap.size())); for (Person person : pageContent) { if (previousLastname != null) { assertThat("Descending lastname", person.getLastname(), lessThanOrEqualTo(previousLastname)); } previousLastname = person.getLastname(); } pageRequest = pageResponse.nextPageable(); if (pagesRetrieved == expectedNumberOfPages) { assertThat("Page " + pagesRetrieved + ", is last", pageResponse.hasNext(), equalTo(false)); assertThat("Page " + pagesRetrieved + ", no following page", pageRequest, equalTo(Pageable.unpaged())); pageResponse = null; } else { assertThat("Page " + pagesRetrieved + ", not last", pageResponse.hasNext(), equalTo(true)); assertThat("Page " + pagesRetrieved + ", has following page", pageRequest, not(equalTo(Pageable.unpaged()))); pageResponse = this.personRepository.findByOrderByLastnameDesc(pageRequest); } } assertThat("Not less than expected pages", pagesRetrieved, equalTo(expectedNumberOfPages)); }
Example 10
Source File: PagingSortingIT.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
@Test public void paging() { int PAGE_0 = 0; int PAGE_2 = 2; int SIZE_5 = 5; int SIZE_20 = 20; PageRequest thirdPageOf5Request = PageRequest.of(PAGE_2, SIZE_5); Page<Person> thirdPageOf5Response = this.personRepository.findAll(thirdPageOf5Request); assertThat("11 onwards returned", thirdPageOf5Response, notNullValue()); List<Person> thirdPageOf5Content = thirdPageOf5Response.getContent(); assertThat("11-15 returned", thirdPageOf5Content.size(), equalTo(5)); Pageable fourthPageOf5Request = thirdPageOf5Response.nextPageable(); Page<Person> fourthPageOf5Response = this.personRepository.findAll(fourthPageOf5Request); assertThat("16 onwards returned", fourthPageOf5Response, notNullValue()); List<Person> fourthPageOf5Content = fourthPageOf5Response.getContent(); assertThat("16-20 returned", fourthPageOf5Content.size(), equalTo(5)); PageRequest firstPageOf20Request = PageRequest.of(PAGE_0, SIZE_20); Page<Person> firstPageOf20Response = this.personRepository.findAll(firstPageOf20Request); assertThat("1 onwards returned", firstPageOf20Response, notNullValue()); List<Person> firstPageOf20Content = firstPageOf20Response.getContent(); assertThat("1-20 returned", firstPageOf20Content.size(), equalTo(20)); assertThat("11th", thirdPageOf5Content.get(0), equalTo(firstPageOf20Content.get(10))); assertThat("12th", thirdPageOf5Content.get(1), equalTo(firstPageOf20Content.get(11))); assertThat("13th", thirdPageOf5Content.get(2), equalTo(firstPageOf20Content.get(12))); assertThat("14th", thirdPageOf5Content.get(3), equalTo(firstPageOf20Content.get(13))); assertThat("15th", thirdPageOf5Content.get(4), equalTo(firstPageOf20Content.get(14))); assertThat("16th", fourthPageOf5Content.get(0), equalTo(firstPageOf20Content.get(15))); assertThat("17th", fourthPageOf5Content.get(1), equalTo(firstPageOf20Content.get(16))); assertThat("18th", fourthPageOf5Content.get(2), equalTo(firstPageOf20Content.get(17))); assertThat("19th", fourthPageOf5Content.get(3), equalTo(firstPageOf20Content.get(18))); assertThat("20th", fourthPageOf5Content.get(4), equalTo(firstPageOf20Content.get(19))); Set<String> ids = new TreeSet<>(); firstPageOf20Content.forEach(person -> ids.add(person.getId())); assertThat("20 different years", ids.size(), equalTo(20)); }