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

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

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

Sort.and介绍

[英]Returns a new Sort consisting of the Orders of the current Sort combined with the given ones.
[中]返回由当前排序的顺序与给定顺序组合而成的新排序。

代码示例

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

  1. public SortOperation and(Sort sort) {
  2. return new SortOperation(this.sort.and(sort));
  3. }

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

  1. /**
  2. * Adds a {@link Sort} to the {@link Query} instance.
  3. *
  4. * @param sort
  5. * @return
  6. */
  7. public Query with(Sort sort) {
  8. Assert.notNull(sort, "Sort must not be null!");
  9. if (sort.isUnsorted()) {
  10. return this;
  11. }
  12. sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
  13. throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
  14. + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  15. });
  16. this.sort = this.sort.and(sort);
  17. return this;
  18. }

代码示例来源:origin: org.springframework.data/spring-data-mongodb

  1. public SortOperation and(Sort sort) {
  2. return new SortOperation(this.sort.and(sort));
  3. }

代码示例来源:origin: org.springframework.data/spring-data-mongodb

  1. /**
  2. * Adds a {@link Sort} to the {@link Query} instance.
  3. *
  4. * @param sort
  5. * @return
  6. */
  7. public Query with(Sort sort) {
  8. Assert.notNull(sort, "Sort must not be null!");
  9. if (sort.isUnsorted()) {
  10. return this;
  11. }
  12. sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
  13. throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
  14. + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  15. });
  16. this.sort = this.sort.and(sort);
  17. return this;
  18. }

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

  1. @Override
  2. public Message<?> pollMessageFromGroup(Object groupId) {
  3. Assert.notNull(groupId, "'groupId' must not be null");
  4. Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  5. if (this.priorityEnabled) {
  6. sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  7. }
  8. Query query = groupIdQuery(groupId).with(sort);
  9. MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  10. Message<?> message = null;
  11. if (document != null) {
  12. message = document.getMessage();
  13. }
  14. return message;
  15. }

代码示例来源:origin: SpringDataElasticsearchDevs/spring-data-elasticsearch

  1. @SuppressWarnings("unchecked")
  2. public final <T extends Query> T addSort(Sort sort) {
  3. if (sort == null) {
  4. return (T) this;
  5. }
  6. if (this.sort == null) {
  7. this.sort = sort;
  8. } else {
  9. this.sort = this.sort.and(sort);
  10. }
  11. return (T) this;
  12. }
  13. }

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

  1. /**
  2. * Add given {@link Sort}.
  3. *
  4. * @param sort {@literal null} {@link Sort} will be ignored.
  5. * @return
  6. */
  7. public Query<T> orderBy(Sort sort) {
  8. if (sort == null) {
  9. return this;
  10. }
  11. if (this.sort != null) {
  12. this.sort.and(sort);
  13. }
  14. else {
  15. this.sort = sort;
  16. }
  17. return this;
  18. }

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

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public final <T extends Query> T addSort(@Nullable Sort sort) {
  4. if (sort == null) {
  5. return (T) this;
  6. }
  7. if (this.sort == null) {
  8. this.sort = sort;
  9. } else {
  10. this.sort = this.sort.and(sort);
  11. }
  12. return (T) this;
  13. }

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

  1. public SortingOperation and(Sort sort) {
  2. return new SortingOperation(this.sort.and(sort));
  3. }
  4. }

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

  1. /**
  2. * Add given {@link Sort}.
  3. *
  4. * @param sort must not be {@literal null}.
  5. * @return
  6. */
  7. public KeyValueQuery<T> orderBy(Sort sort) {
  8. Assert.notNull(sort, "Sort must not be null!");
  9. if (this.sort.isSorted()) {
  10. this.sort = this.sort.and(sort);
  11. } else {
  12. this.sort = sort;
  13. }
  14. return this;
  15. }

代码示例来源:origin: org.springframework.data/spring-data-keyvalue

  1. /**
  2. * Add given {@link Sort}.
  3. *
  4. * @param sort must not be {@literal null}.
  5. * @return
  6. */
  7. public KeyValueQuery<T> orderBy(Sort sort) {
  8. Assert.notNull(sort, "Sort must not be null!");
  9. if (this.sort.isSorted()) {
  10. this.sort = this.sort.and(sort);
  11. } else {
  12. this.sort = sort;
  13. }
  14. return this;
  15. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Add given {@link Sort}.
  3. *
  4. * @param sort must not be {@literal null}.
  5. * @return
  6. */
  7. public KeyValueQuery<T> orderBy(Sort sort) {
  8. Assert.notNull(sort, "Sort must not be null!");
  9. if (this.sort.isSorted()) {
  10. this.sort = this.sort.and(sort);
  11. } else {
  12. this.sort = sort;
  13. }
  14. return this;
  15. }

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

  1. @Override
  2. protected Sort processSort(Sort sort) {
  3. if(sort.getOrderFor(DEFAULT_PERIOD_SORT_FIELD) != null){
  4. return sort;
  5. }
  6. return sort.and(new Sort(Direction.ASC, DEFAULT_PERIOD_SORT_FIELD));
  7. }

代码示例来源:origin: Microsoft/spring-data-cosmosdb

  1. public DocumentQuery with(@NonNull Sort sort) {
  2. if (sort.isSorted()) {
  3. this.sort = sort.and(this.sort);
  4. }
  5. return this;
  6. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Creates the actual query object applying the given {@link Sort} parameter. Use this method in case you haven't
  3. * provided a {@link ParameterAccessor} in the first place but want to apply dynamic sorting nevertheless.
  4. *
  5. * @param dynamicSort must not be {@literal null}.
  6. * @return
  7. */
  8. public T createQuery(Sort dynamicSort) {
  9. Assert.notNull(dynamicSort, "DynamicSort must not be null!");
  10. return complete(createCriteria(tree), tree.getSort().and(dynamicSort));
  11. }

代码示例来源:origin: org.springframework.data/spring-data-commons-core

  1. /**
  2. * Creates the actual query object applying the given {@link Sort} parameter. Use this method in case you haven't
  3. * provided a {@link ParameterAccessor} in the first place but want to apply dynamic sorting nevertheless.
  4. *
  5. * @param sort
  6. * @return
  7. */
  8. public T createQuery(Sort dynamicSort) {
  9. Sort staticSort = tree.getSort();
  10. Sort sort = staticSort != null ? staticSort.and(dynamicSort) : dynamicSort;
  11. return complete(createCriteria(tree), sort);
  12. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Creates a new {@link Sort} instance from the given {@link SortDefault} or appends it to the given {@link Sort}
  3. * instance if it's not {@literal null}.
  4. *
  5. * @param sortDefault
  6. * @param sortOrNull
  7. * @return
  8. */
  9. private Sort appendOrCreateSortTo(SortDefault sortDefault, Sort sortOrNull) {
  10. String[] fields = SpringDataAnnotationUtils.getSpecificPropertyOrDefaultFromValue(sortDefault, "sort");
  11. if (fields.length == 0) {
  12. return Sort.unsorted();
  13. }
  14. return sortOrNull.and(Sort.by(sortDefault.direction(), fields));
  15. }

代码示例来源:origin: org.springframework.integration/spring-integration-mongodb

  1. @Override
  2. public Message<?> pollMessageFromGroup(Object groupId) {
  3. Assert.notNull(groupId, "'groupId' must not be null");
  4. Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  5. if (this.priorityEnabled) {
  6. sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  7. }
  8. Query query = groupIdQuery(groupId).with(sort);
  9. MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  10. Message<?> message = null;
  11. if (document != null) {
  12. message = document.getMessage();
  13. }
  14. return message;
  15. }

代码示例来源:origin: zsl131/spring-boot-test

  1. public static Sort basicSort(SortDto... dtos) {
  2. Sort result = null;
  3. for(int i=0; i<dtos.length; i++) {
  4. SortDto dto = dtos[i];
  5. if(result == null) {
  6. result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField());
  7. } else {
  8. result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()));
  9. }
  10. }
  11. return result;
  12. }
  13. }

代码示例来源:origin: zsl131/spring-boot-test

  1. public static Sort basicSort(SortDto... dtos) {
  2. Sort result = null;
  3. for(int i=0; i<dtos.length; i++) {
  4. SortDto dto = dtos[i];
  5. if(result == null) {
  6. result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField());
  7. } else {
  8. result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()));
  9. }
  10. }
  11. return result;
  12. }
  13. }

相关文章