public List<Post> getArchivePosts() { log.debug("Get all archive posts from database."); Pageable page = new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.DESC, "createdAt"); return postRepository.findAllByPostTypeAndPostStatus(PostType.POST, PostStatus.PUBLISHED, page) .getContent() .stream() .map(this::extractPostMeta) .collect(Collectors.toList()); }
/** * Performs the actual reading of a page via the repository. * Available for overriding as needed. * * @return the list of items that make up the page * @throws Exception Based on what the underlying method throws or related to the * calling of the method */ @SuppressWarnings("unchecked") protected List<T> doPageRead() throws Exception { Pageable pageRequest = PageRequest.of(page, pageSize, sort); MethodInvoker invoker = createMethodInvoker(repository, methodName); List<Object> parameters = new ArrayList<>(); if(arguments != null && arguments.size() > 0) { parameters.addAll(arguments); } parameters.add(pageRequest); invoker.setArguments(parameters.toArray()); Page<T> curPage = (Page<T>) doInvoke(invoker); return curPage.getContent(); }
private void verifyMultiArgRead(ArgumentCaptor<String> arg1Captor, ArgumentCaptor<String> arg2Captor, ArgumentCaptor<String> arg3Captor, String result) { assertEquals("Result returned from reader was not expected value.", TEST_CONTENT, result); assertEquals("ARG1 for calling method did not match expected result", ARG1, arg1Captor.getValue()); assertEquals("ARG2 for calling method did not match expected result", ARG2, arg2Captor.getValue()); assertEquals("ARG3 for calling method did not match expected result", ARG3, arg3Captor.getValue()); assertEquals("Result Total Pages did not match expected result", 10, this.pageRequestContainer.getValue().getPageSize()); } }
@Override public Page<UserRolesMappingResponse> getAllUserRolesMapping(String searchTerm, int page, int size) { Page<UserRolesMapping> userRoleMappings = userRolesMappingRepository.findAllUserRolesMappingDetails(searchTerm, new PageRequest(page, size)); List<UserRolesMappingResponse> allUserRoleMappingsList = userRoleMappings.getContent().parallelStream().map(fetchUserRolesMappingDetials).collect(Collectors.toList()); Page<UserRolesMappingResponse> allUserRoleMappings = new PageImpl<UserRolesMappingResponse>(allUserRoleMappingsList, new PageRequest(page, size), userRoleMappings.getTotalElements()); return allUserRoleMappings; }
public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) { List<S> sourceList = source.getContent(); List<T> list = new ArrayList<>(); for (int i = 0; i < sourceList.size(); i++) { T target = INSTANCE.map(sourceList.get(i), targetClass); list.add(target); } return new PageImpl<>(list, new PageRequest(source.getNumber(), source.getSize(), source.getSort()), source.getTotalElements()); } }
Pageable topTen = new PageRequest(0, 10); Page<User> result = repository.findByUsername("Matthews", topTen); Assert.assertThat(result.isFirstPage(), is(true));
@Override public Collection<T> getNext() { if (currentPage < 0) { return null; } Page<T> page = getNextPage(new PageRequest(currentPage, maxResults), repo); currentPage++; if (page.getTotalPages() == currentPage) { currentPage = -1; } return page.getContent(); }
@Override public Page<Rating> findByApiPageable(final String api, final Pageable pageable) throws TechnicalException { LOGGER.debug("Find rating by api [{}] with pagination", api); final org.springframework.data.domain.Page<RatingMongo> ratingPageMongo = internalRatingRepository.findByApi(api, new PageRequest(pageable.pageNumber(), pageable.pageSize(), Sort.Direction.DESC, "createdAt")); final List<Rating> ratings = ratingPageMongo.getContent().stream().map(this::map).collect(toList()); final Page<Rating> ratingPage = new Page<>(ratings, ratingPageMongo.getNumber(), ratingPageMongo.getNumberOfElements(), ratingPageMongo.getTotalElements()); LOGGER.debug("Find rating by api [{}] with pagination - DONE", api); return ratingPage; }
private void resultPrint(Specification<MyOrder> spec) { //分页查询 Pageable pageable = new PageRequest(0, 10, Sort.Direction.DESC, "id"); //查询的分页结果 Page<MyOrder> page = myOrderRepository.findAll(spec, pageable); System.out.println(page); System.out.println(page.getTotalElements()); System.out.println(page.getTotalPages()); for (MyOrder c : page.getContent()) { System.out.println(c.toString()); } }
@Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { int maxResult = 1000; Page<TermConcept> concepts = myConceptDao.findResourcesRequiringReindexing(new PageRequest(0, maxResult)); if (concepts.hasContent() == false) { if (myChildToParentPidCache != null) { ourLog.info("Clearing parent concept cache"); myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; myChildToParentPidCache = null; } return; } if (myChildToParentPidCache == null) { myChildToParentPidCache = ArrayListMultimap.create(); } ourLog.info("Indexing {} / {} concepts", concepts.getContent().size(), concepts.getTotalElements()); int count = 0; StopWatch stopwatch = new StopWatch(); for (TermConcept nextConcept : concepts) { if (isBlank(nextConcept.getParentPidsAsString())) { StringBuilder parentsBuilder = new StringBuilder(); createParentsString(parentsBuilder, nextConcept.getId()); nextConcept.setParentPids(parentsBuilder.toString()); } saveConcept(nextConcept); count++; } ourLog.info("Indexed {} / {} concepts in {}ms - Avg {}ms / resource", count, concepts.getContent().size(), stopwatch.getMillis(), stopwatch.getMillisPerOperation(count)); } });
private Page<AssetGroupView> buildAssetGroupView(final Page<AssetGroupDetails> allAssetGroups) { List<AssetGroupView> allAssetGroupList = Lists.newArrayList(); allAssetGroups.getContent().forEach(assetGroup -> { AssetGroupView assetGroupView = new AssetGroupView(); assetGroupView.setGroupId(assetGroup.getGroupId()); assetGroupView.setGroupName(assetGroup.getGroupName()); assetGroupView.setTargetTypes(assetGroup.getTargetTypes()); allAssetGroupList.add(assetGroupView); }); return new PageImpl<AssetGroupView>(allAssetGroupList, PageRequest.of(allAssetGroups.getNumber(), allAssetGroups.getSize()),allAssetGroups.getTotalElements()); }
private int check() { PageRequest pageable = PageRequest.of(0, 1); appService.findAll(pageable); return 0; }
@Override public boolean hasNext() { if (fetchedRows == null || !fetchedRows.hasNext()) { PageRequest pageRequest = new PageRequest(page++, FETCH_SIZE, new Sort(new Sort.Order(Direction.ASC, "rowNumber"))); Page<CocosQueryResultRow> rows = rowRepository.findByQueryResult(queryExecution, pageRequest); if (!rows.hasContent()) { return false; } fetchedRows = rows.getContent().iterator(); } return true; }
@GetMapping("") public String index(@RequestParam(defaultValue = "0") int page, Model model) { Page<Post> posts = postRepository.findAll(new PageRequest(page, PAGE_SIZE, Sort.Direction.DESC, "id")); model.addAttribute("totalPages", posts.getTotalPages()); model.addAttribute("page", page); model.addAttribute("posts", posts); return "admin/posts/index"; }
@GetMapping("/by-namespace/count") public long getInstancesCountByNamespace(@RequestParam("appId") String appId, @RequestParam("clusterName") String clusterName, @RequestParam("namespaceName") String namespaceName) { Page<Instance> instances = instanceService.findInstancesByNamespace(appId, clusterName, namespaceName, PageRequest.of(0, 1)); return instances.getTotalElements(); } }
@RequestMapping(value = "/{userId}", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<HueApiResponse> getApi(@PathVariable(value = "userId") String userId, HttpServletRequest request) { log.info("hue api root requested: " + userId + " from " + request.getRemoteAddr()); int pageNumber = request.getLocalPort()-portBase; Page<DeviceDescriptor> descriptorList = repository.findByDeviceType("switch", new PageRequest(pageNumber, 25)); if (descriptorList == null) { return new ResponseEntity<>(null, null, HttpStatus.NOT_FOUND); } Map<String, DeviceResponse> deviceList = new HashMap<>(); descriptorList.forEach(descriptor -> { DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor.getName(), descriptor.getId()); deviceList.put(descriptor.getId(), deviceResponse); } ); HueApiResponse apiResponse = new HueApiResponse(); apiResponse.setLights(deviceList); HttpHeaders headerMap = new HttpHeaders(); ResponseEntity<HueApiResponse> entity = new ResponseEntity<>(apiResponse, headerMap, HttpStatus.OK); return entity; }
private Long assignTargetsToGroupInNewTransaction(final JpaRollout rollout, final RolloutGroup group, final String targetFilter, final long limit) { return runInNewTransaction("assignTargetsToRolloutGroup", status -> { final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit)); final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), RolloutGroupStatus.READY, group); final Page<Target> targets = targetManagement.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); createAssignmentOfTargetsToGroup(targets, group); return Long.valueOf(targets.getNumberOfElements()); }); }
private Long assignTargetsToGroupInNewTransaction(final JpaRollout rollout, final RolloutGroup group, final String targetFilter, final long limit) { return DeploymentHelper.runInNewTransaction(txManager, "assignTargetsToRolloutGroup", status -> { final PageRequest pageRequest = PageRequest.of(0, Math.toIntExact(limit)); final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), RolloutGroupStatus.READY, group); final Page<Target> targets = targetManagement.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); createAssignmentOfTargetsToGroup(targets, group); return Long.valueOf(targets.getNumberOfElements()); }); }
private PublicationStatsImport getLastImportByType(StatisticType statisticType) { Pageable pageable = new PageRequest(0, 1, Direction.DESC, "collectionDate"); Page<PublicationStatsImport> imports = importRepository.getImportsByType(statisticType, pageable); if (imports.getTotalElements() == 0) { return null; } PublicationStatsImport lastImport = imports.getContent().get(0); return lastImport; }
public final Page<Target> convertToPage(Page<Source> sourcePage, Map<String, Object> parameters) { List<Target> targets = new ArrayList(sourcePage.getContent().size()); for (Source source : sourcePage) { targets.add(convert(source, parameters)); } Pageable pageable = new PageRequest(sourcePage.getNumber(), sourcePage.getSize(), sourcePage.getSort()); Page<Target> targetPage = new PageImpl(targets, pageable, sourcePage.getTotalElements()); return targetPage; }