org.springframework.data.domain.Sort.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.springframework.data.domain.Sort.<init>()方法的一些代码示例,展示了Sort.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.<init>()方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:<init>

Sort.<init>介绍

[英]Creates a new Sort instance.
[中]创建一个新的排序实例。

代码示例

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testSettingCurrentItemCountExplicitly() throws Exception {
  reader.setCurrentItemCount(3);
  reader.setPageSize(2);
  PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add("3");
    add("4");
  }}));
  request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add("5");
    add("6");
  }}));
  reader.open(new ExecutionContext());
  Object result = reader.read();
  assertEquals("3", result);
  assertEquals("4", reader.read());
  assertEquals("5", reader.read());
  assertEquals("6", reader.read());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testResetOfPage() throws Exception {
  reader.setPageSize(2);
  PageRequest request = PageRequest.of(0, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add("1");
    add("2");
  }}));
  request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add("3");
    add("4");
  }}));
  ExecutionContext executionContext = new ExecutionContext();
  reader.open(executionContext);
  Object result = reader.read();
  reader.close();
  assertEquals("1", result);
  reader.open(executionContext);
  assertEquals("1", reader.read());
  assertEquals("2", reader.read());
  assertEquals("3", reader.read());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testSettingCurrentItemCountRestart() throws Exception {
  reader.setCurrentItemCount(3);
  reader.setPageSize(2);
  PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add("3");
    add("4");
  }}));
  request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id"));
  when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add("5");
    add("6");
  }}));
  ExecutionContext executionContext = new ExecutionContext();
  reader.open(executionContext);
  Object result = reader.read();
  reader.update(executionContext);
  reader.close();
  assertEquals("3", result);
  reader.open(executionContext);
  assertEquals("4", reader.read());
  assertEquals("5", reader.read());
  assertEquals("6", reader.read());
}

代码示例来源:origin: spring-projects/spring-integration

private static Query whereGroupIdOrder(Object groupId) {
  return whereGroupIdIs(groupId).with(new Sort(Sort.Direction.DESC, GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
}

代码示例来源:origin: spring-projects/spring-integration

private void updateGroup(Object groupId, Update update) {
  Query query = whereGroupIdIs(groupId).with(new Sort(Sort.Direction.DESC, GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
  this.template.updateFirst(query, update, this.collectionName);
}

代码示例来源:origin: Exrick/x-boot

public static Pageable initPage(PageVo page){

    Pageable pageable=null;
    int pageNumber=page.getPageNumber();
    int pageSize=page.getPageSize();
    String sort=page.getSort();
    String order=page.getOrder();

    if(pageNumber<1){
      pageNumber=1;
    }
    if(pageSize<1){
      pageSize=10;
    }
    if(StrUtil.isNotBlank(sort)) {
      Sort.Direction d;
      if(StrUtil.isBlank(order)) {
        d = Sort.Direction.DESC;
      }else {
        d = Sort.Direction.valueOf(order.toUpperCase());
      }
      Sort s = new Sort(d,sort);
      pageable = PageRequest.of(pageNumber-1, pageSize,s);
    }else {
      pageable = PageRequest.of(pageNumber-1, pageSize);
    }
    return pageable;
  }
}

代码示例来源:origin: spring-projects/spring-data-solr

/**
 * Creates a new {@link SolrPageRequest} with sort parameters applied.
 * 
 * @param page zero-based page index.
 * @param size the size of the page to be returned.
 * @param direction the direction of the {@link Sort} to be specified, can be {@literal null}.
 * @param properties the properties to sort by, must not be {@literal null} or empty.
 */
public SolrPageRequest(int page, int size, Direction direction, String... properties) {
  this(page, size, new Sort(direction, properties));
}

代码示例来源:origin: naver/ngrinder

@SuppressWarnings("unchecked")
@Test
public void testGetTestListByKeyWord() {
  String strangeName = "DJJHG^%R&*^%^565(^%&^%(^%(^";
  createPerfTest(strangeName, Status.READY, new Date());
  ModelMap model = new ModelMap();
  Sort sort = new Sort("testName");
  Pageable pageable = new PageRequest(0, 10, sort);
  controller.getAll(getTestUser(), strangeName, null, null, pageable, model);
  Page<PerfTest> testPage = (Page<PerfTest>) model.get("testListPage");
  List<PerfTest> testList = testPage.getContent();
  assertThat(testList.size(), is(1));
  controller.getAll(getTestUser(), strangeName.substring(2, 10), null, null, new PageRequest(0, 10), model);
  testPage = (Page<PerfTest>) model.get("testListPage");
  testList = testPage.getContent();
  assertThat(testList.size(), is(1));
}

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

/**
 * 测试排序
 */
@RequestMapping("/sort")
public List<Person> sort() {
  List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  return people;
}

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

/**
 * 测试排序
 */
@RequestMapping("/sort")
public List<Person> sort() {
  List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  return people;
}

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

/**
 * 测试排序
 */
@RequestMapping("/sort")
public List<Person> sort() {
  List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  return people;
}

代码示例来源:origin: abixen/abixen-platform

@Override
public Sort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
  final ArrayNode node = jsonParser.getCodec().readTree(jsonParser);
  final Order[] orders = new Order[node.size()];
  int i = 0;
  for (JsonNode jsonNode : node) {
    orders[i] = new Order(Direction.valueOf(jsonNode.get("direction").asText()), jsonNode.get("property").asText());
    i++;
  }
  return new Sort(orders);
}

代码示例来源:origin: dyc87112/spring-cloud-config-admin

@Override
public List<UserDto> getUsers() {
  List<User> userList = userRepo.findAll(new Sort(Sort.Direction.DESC, "id"));
  List<UserDto> userDtoList = new ArrayList<>(userList.size());
  userList.forEach(user -> userDtoList.add(toDto(user)));
  return userDtoList;
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
public Sort createSort() {
  List<Order> orders = new ArrayList<Order>();
  orders.add(new Order(Direction.ASC, "organisation.id"));
  orders.add(new Order(Direction.ASC, "id"));
  Sort sort = new Sort(orders);
  return sort;
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@Override
public Sort createSort() {
  List<Order> orders = new ArrayList<Order>();
  orders.add(new Order(Direction.ASC, "ip"));
  orders.add(new Order(Direction.ASC, "organisation.id"));
  orders.add(new Order(Direction.ASC, "id"));
  Sort sort = new Sort(orders);
  return sort;
}

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-repository-jpa

@Override
public Optional<Action> findOldestActiveActionByTarget(final String controllerId) {
  if (!actionRepository.activeActionExistsForControllerId(controllerId)) {
    return Optional.empty();
  }
  // used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
  // DATAJPA-841 issue.
  return actionRepository.findFirstByTargetControllerIdAndActive(new Sort(Direction.ASC, "id"), controllerId,
      true);
}

代码示例来源:origin: pl.edu.icm.synat/synat-neo4j-graph-impl

@Override
@Transactional(value = "neo4jTransactionManager", readOnly = true)
public Page<Citation> getMostCitedAuhtorByOtherAuthors(Integer pageNumber, Integer pageSize, String authorId, CitationType citationType) {
  Pageable pageable = new PageRequest(pageNumber, pageSize, new Sort(Direction.DESC, "count"));
  return citationsPageFunction.apply(contentRepository.getMostCitedAuthorsByAuthor(authorId, citationType.name(), pageable));
}

代码示例来源:origin: dyc87112/spring-cloud-config-admin

@Override
public List<Permission> getPermission(Long userId) {
  if (!userService.existUser(userId)) {
    throw new ServiceException("用户不存在");
  }
  Sort sort = new Sort(Sort.Direction.ASC, "envId", "projectId");
  return permissionRepo.findAllByUserId(userId, sort);
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
public List<TestItem> loadItemsHistory(List<String> uniqueIds, List<String> launchesIds) {
  if (CollectionUtils.isEmpty(uniqueIds) || CollectionUtils.isEmpty(launchesIds)) {
    return Collections.emptyList();
  }
  Query query = query(where(LAUNCH_REFERENCE).in(launchesIds).and(UNIQUE_ID).in(uniqueIds));
  query.with(new Sort(ASC, ID));
  query.limit(HISTORY_LIMIT);
  return mongoTemplate.find(query, TestItem.class);
}

代码示例来源:origin: com.epam.reportportal/commons-dao

@Override
public List<TestItem> findForSpecifiedSubType(List<String> launchesIds, boolean hasChild, StatisticSubType type) {
  String issueField =
      "statistics.issueCounter." + TestItemIssueType.valueOf(type.getTypeRef()).awareStatisticsField() + "." + type.getLocator();
  Query query = query(where(LAUNCH_REFERENCE).in(launchesIds)).addCriteria(where(HAS_CHILD).is(hasChild))
      .addCriteria(where(issueField).exists(true))
      .with(new Sort(Sort.Direction.ASC, START_TIME));
  return mongoTemplate.find(query, TestItem.class);
}

相关文章