List of usage examples for org.springframework.data.domain Page isLast
boolean isLast();
From source file:de.olivergierke.deepdive.CustomerRepositoryIntegrationTest.java
/** * @since Step 4.1/*from ww w . j a va 2 s. c o m*/ */ @Test public void accessesCustomersPageByPage() { Page<Customer> result = repository.findAll(new PageRequest(1, 1)); assertThat(result, is(notNullValue())); assertThat(result.isFirst(), is(false)); assertThat(result.isLast(), is(false)); assertThat(result.getNumberOfElements(), is(1)); }
From source file:demo.CustomerRepositoryIntegrationTest.java
/** * @since Step 4.1/*from w w w. j ava 2 s . c o m*/ */ @Test public void accessesCustomersPageByPage() { Page<Customer> result = repository.findAll(new PageRequest(/* page:*/ 1, /* page size:*/ 1)); assertThat(result).isNotNull(); assertThat(result.isFirst()).isFalse(); assertThat(result.isLast()).isFalse(); assertThat(result.getNumberOfElements()).isEqualTo(1); }
From source file:com.rizki.mufrizal.belajar.spring.data.mongodb.service.impl.CategoryServiceImpl.java
@Override public TreeMap<String, Object> getCategories(Pageable pageable) { Page<Category> categories = categoryRepository.findAll(pageable); List<Category> categorys = new ArrayList<>(); for (Category category : categories) { category.setDepartment(departmentRepository.findOne(category.getDepartmentId())); categorys.add(category);/* ww w.j a v a2 s. c o m*/ } TreeMap<String, Object> map = new TreeMap<>(); map.put("content", categorys); map.put("last", categories.isLast()); map.put("totalPages", categories.getTotalPages()); map.put("totalElements", categories.getTotalElements()); map.put("size", categories.getSize()); map.put("number", categories.getNumber()); map.put("sort", categories.getSort()); map.put("first", categories.isFirst()); map.put("numberOfElements", categories.getNumberOfElements()); return map; }
From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java
public void reweight() { int batchSize = 100; Sort sort = new Sort(Sort.Direction.DESC, "weight"); Pageable pageable = new PageRequest(0, batchSize, sort); Page<M> page = findAll(pageable); do {/*from w w w. ja v a2s .c o m*/ //doReweight?requiresNew ((BaseMovableService) AopContext.currentProxy()).doReweight(page); RepositoryHelper.clear(); if (page.isLast()) { break; } pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort); page = findAll(pageable); } while (true); }
From source file:com.yqboots.web.thymeleaf.processor.element.PaginationElementProcessor.java
/** * Gets the link node of the last page./*w w w .j a v a 2 s . c om*/ * * @param page the pagination object * @param contextPath current context path of servlet * @return the node */ private Element getLastElement(final Page<?> page, final String contextPath) { final Element result = new Element("li"); final Element a = new Element("a"); a.setAttribute("href", getPagedParams(contextPath, page.getTotalPages() - 1, page.getSize())); result.addChild(a); final Element icon = new Element("i"); icon.setAttribute("class", "glyphicon glyphicon-step-forward"); a.addChild(icon); if (page.isLast()) { result.setAttribute("class", "disabled"); } return result; }
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void findsPagedPersons() throws Exception { Page<Person> result = repository.findAll(new PageRequest(1, 2, Direction.ASC, "lastname", "firstname")); assertThat(result.isFirst(), is(false)); assertThat(result.isLast(), is(false)); assertThat(result, hasItems(dave, stefan)); }
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void executesPagedFinderCorrectly() throws Exception { Page<Person> page = repository.findByLastnameLike("*a*", new PageRequest(0, 2, Direction.ASC, "lastname", "firstname")); assertThat(page.isFirst(), is(true)); assertThat(page.isLast(), is(false)); assertThat(page.getNumberOfElements(), is(2)); assertThat(page, hasItems(carter, stefan)); }
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception { Page<Person> page = repository.findByLastnameLikeWithPageable(".*a.*", new PageRequest(0, 2, Direction.ASC, "lastname", "firstname")); assertThat(page.isFirst(), is(true)); assertThat(page.isLast(), is(false)); assertThat(page.getNumberOfElements(), is(2)); assertThat(page, hasItems(carter, stefan)); }
From source file:org.thingsplode.server.infrastructure.DeviceService.java
@Transactional public void setConfigurationForDevices(List<Configuration> configurations) { int pageIndex = 0; Page<Device> devicePage; do {//from w w w. j a v a2s . c om devicePage = deviceRepo.findAll(new PageRequest(pageIndex, pageSize)); if (devicePage != null && devicePage.getSize() > 0) { devicePage.getContent().stream().forEach((d) -> { d.getConfiguration().clear(); }); deviceRepo.save(devicePage.getContent()); deviceRepo.flush(); devicePage.getContent().stream().forEach((d) -> { d.getConfiguration().addAll(configurations); }); deviceRepo.save(devicePage.getContent()); } pageIndex += 1; } while (devicePage != null && (!devicePage.isLast() || devicePage.getNumber() > 0)); }
From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java
@Test public void findAllByPageable() throws Exception { // given/* w ww. ja v a 2 s . c o m*/ dbSetupTracker.skipNextLaunch(); // when PageRequest page1 = new PageRequest(0, 2); PageRequest page2 = new PageRequest(1, 2); Page<BookApi> bookApis1 = repository.findAll(page1); Page<BookApi> bookApis2 = repository.findAll(page2); // then assertThat(bookApis1).isNotNull().isNotEmpty().hasSize(2).extracting("id", "name", "url").containsExactly( tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"), tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes")); assertThat(bookApis1.getNumber()).isEqualTo(0); assertThat(bookApis1.getNumberOfElements()).isEqualTo(2); assertThat(bookApis1.getSize()).isEqualTo(2); assertThat(bookApis1.getTotalPages()).isEqualTo(2); assertThat(bookApis1.getTotalElements()).isEqualTo(3); assertThat(bookApis1.isFirst()).isTrue(); assertThat(bookApis1.isLast()).isFalse(); assertThat(bookApis1.hasNext()).isTrue(); assertThat(bookApis1.hasPrevious()).isFalse(); assertThat(bookApis2).isNotNull().isNotEmpty().hasSize(1).extracting("id", "name", "url") .containsExactly(tuple(3, "?API", "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522")); assertThat(bookApis2.getNumber()).isEqualTo(1); assertThat(bookApis2.getNumberOfElements()).isEqualTo(1); assertThat(bookApis2.getSize()).isEqualTo(2); assertThat(bookApis2.getTotalPages()).isEqualTo(2); assertThat(bookApis2.getTotalElements()).isEqualTo(3); assertThat(bookApis2.isFirst()).isFalse(); assertThat(bookApis2.isLast()).isTrue(); assertThat(bookApis2.hasNext()).isFalse(); assertThat(bookApis2.hasPrevious()).isTrue(); }