@Test public void listByPage() throws Exception { CompensationQuery query = new CompensationQuery(); query.setApplicationName("alipay-service"); PageParameter pageParameter = new PageParameter(1, 8); query.setPageParameter(pageParameter); final CommonPager<TccCompensationVO> pager = compensationService.listByPage(query); Assert.assertNotNull(pager.getDataList()); }
@Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> voCommonPager = new CommonPager<>(); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; final String rootPath = RepositoryPathUtils.buildZookeeperPathPrefix(query.getApplicationName()); List<String> zNodePaths; List<TccCompensationVO> voList; int totalCount; try { if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = zooKeeper.getChildren(rootPath, false); final List<TccCompensationVO> all = findAll(zNodePaths, rootPath); final List<TccCompensationVO> collect = all.stream() .filter(vo -> vo.getRetriedCount() < query.getRetry()).collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { zNodePaths = zooKeeper.getChildren(rootPath, false); totalCount = zNodePaths.size(); voList = findByPage(zNodePaths, rootPath, start, pageSize); } voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); voCommonPager.setDataList(voList); } catch (Exception e) { e.printStackTrace(); } return voCommonPager; }
ZookeeperCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> voCommonPager = new CommonPager<>(); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; final String rootPath = RepositoryPathUtils.buildZookeeperPathPrefix(query.getApplicationName()); List<String> zNodePaths; List<TccCompensationVO> voList; int totalCount; try { if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = zooKeeper.getChildren(rootPath, false); final List<TccCompensationVO> all = findAll(zNodePaths, rootPath); final List<TccCompensationVO> collect = all.stream() .filter(vo -> vo.getRetriedCount() < query.getRetry()).collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { zNodePaths = zooKeeper.getChildren(rootPath, false); totalCount = zNodePaths.size(); voList = findByPage(zNodePaths, rootPath, start, pageSize); } voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); voCommonPager.setDataList(voList); } catch (Exception e) { e.printStackTrace(); } return voCommonPager; } }
ZookeeperCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> voCommonPager = new CommonPager<>(); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; final String rootPath = RepositoryPathUtils.buildZookeeperPathPrefix(query.getApplicationName()); List<String> zNodePaths; List<TccCompensationVO> voList; int totalCount; try { if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = zooKeeper.getChildren(rootPath, false); final List<TccCompensationVO> all = findAll(zNodePaths, rootPath); final List<TccCompensationVO> collect = all.stream() .filter(vo -> vo.getRetriedCount() < query.getRetry()).collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { zNodePaths = zooKeeper.getChildren(rootPath, false); totalCount = zNodePaths.size(); voList = findByPage(zNodePaths, rootPath, start, pageSize); } voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); voCommonPager.setDataList(voList); } catch (Exception e) { e.printStackTrace(); } return voCommonPager; } ZookeeperCompensationServiceImpl(ZooKeeper zooKeeper, ObjectSerializer objectSerializer); }
ZookeeperCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> voCommonPager = new CommonPager<>(); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; final String rootPath = RepositoryPathUtils.buildZookeeperPathPrefix(query.getApplicationName()); List<String> zNodePaths; List<TccCompensationVO> voList; int totalCount; try { if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = zooKeeper.getChildren(rootPath, false); final List<TccCompensationVO> all = findAll(zNodePaths, rootPath); final List<TccCompensationVO> collect = all.stream() .filter(vo -> vo.getRetriedCount() < query.getRetry()).collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { zNodePaths = zooKeeper.getChildren(rootPath, false); totalCount = zNodePaths.size(); voList = findByPage(zNodePaths, rootPath, start, pageSize); } voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); voCommonPager.setDataList(voList); } catch (Exception e) { e.printStackTrace(); } return voCommonPager; } ZookeeperCompensationServiceImpl(ZooKeeper zooKeeper, ObjectSerializer objectSerializer); @Override CommonPager<TccCompensationVO> listByPage(final CompensationQuery query); @Override Boolean batchRemove(final List<String> ids, final String appName); @Override Boolean updateRetry(final String id, final Integer retry, final String appName); }
ZookeeperCompensationServiceImpl implements CompensationService { @Override public CommonPager<TccCompensationVO> listByPage(final CompensationQuery query) { CommonPager<TccCompensationVO> voCommonPager = new CommonPager<>(); final int currentPage = query.getPageParameter().getCurrentPage(); final int pageSize = query.getPageParameter().getPageSize(); int start = (currentPage - 1) * pageSize; final String rootPath = RepositoryPathUtils.buildZookeeperPathPrefix(query.getApplicationName()); List<String> zNodePaths; List<TccCompensationVO> voList; int totalCount; try { if (StringUtils.isBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = zooKeeper.getChildren(rootPath, false); final List<TccCompensationVO> all = findAll(zNodePaths, rootPath); final List<TccCompensationVO> collect = all.stream() .filter(vo -> vo.getRetriedCount() < query.getRetry()).collect(Collectors.toList()); totalCount = collect.size(); voList = collect.stream().skip(start).limit(pageSize).collect(Collectors.toList()); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.isNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath); } else if (StringUtils.isNoneBlank(query.getTransId()) && Objects.nonNull(query.getRetry())) { zNodePaths = Lists.newArrayList(query.getTransId()); totalCount = zNodePaths.size(); voList = findAll(zNodePaths, rootPath).stream().filter(vo -> vo.getRetriedCount() < query.getRetry()) .collect(Collectors.toList()); } else { zNodePaths = zooKeeper.getChildren(rootPath, false); totalCount = zNodePaths.size(); voList = findByPage(zNodePaths, rootPath, start, pageSize); } voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), totalCount)); voCommonPager.setDataList(voList); } catch (Exception e) { e.printStackTrace(); } return voCommonPager; } ZookeeperCompensationServiceImpl(ZooKeeper zooKeeper, ObjectSerializer objectSerializer); @Override CommonPager<TccCompensationVO> listByPage(final CompensationQuery query); @Override Boolean batchRemove(final List<String> ids, final String appName); @Override Boolean updateRetry(final String id, final Integer retry, final String appName);  }