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

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

本文整理了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

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

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

/**
 * Adds a {@link Sort} to the {@link Query} instance.
 *
 * @param sort
 * @return
 */
public Query with(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (sort.isUnsorted()) {
    return this;
  }
  sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
    throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
        + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  });
  this.sort = this.sort.and(sort);
  return this;
}

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

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

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

/**
 * Adds a {@link Sort} to the {@link Query} instance.
 *
 * @param sort
 * @return
 */
public Query with(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (sort.isUnsorted()) {
    return this;
  }
  sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {
    throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
        + "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
  });
  this.sort = this.sort.and(sort);
  return this;
}

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

@Override
public Message<?> pollMessageFromGroup(Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  if (this.priorityEnabled) {
    sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  }
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
  }
  return message;
}

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

@SuppressWarnings("unchecked")
  public final <T extends Query> T addSort(Sort sort) {
    if (sort == null) {
      return (T) this;
    }

    if (this.sort == null) {
      this.sort = sort;
    } else {
      this.sort = this.sort.and(sort);
    }

    return (T) this;
  }
}

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

/**
 * Add given {@link Sort}.
 * 
 * @param sort {@literal null} {@link Sort} will be ignored.
 * @return
 */
public Query<T> orderBy(Sort sort) {
  if (sort == null) {
    return this;
  }
  if (this.sort != null) {
    this.sort.and(sort);
  }
  else {
    this.sort = sort;
  }
  return this;
}

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

@SuppressWarnings("unchecked")
@Override
public final <T extends Query> T addSort(@Nullable Sort sort) {
  if (sort == null) {
    return (T) this;
  }
  if (this.sort == null) {
    this.sort = sort;
  } else {
    this.sort = this.sort.and(sort);
  }
  return (T) this;
}

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

public SortingOperation and(Sort sort) {
    return new SortingOperation(this.sort.and(sort));
  }
}

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

/**
 * Add given {@link Sort}.
 *
 * @param sort must not be {@literal null}.
 * @return
 */
public KeyValueQuery<T> orderBy(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (this.sort.isSorted()) {
    this.sort = this.sort.and(sort);
  } else {
    this.sort = sort;
  }
  return this;
}

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

/**
 * Add given {@link Sort}.
 *
 * @param sort must not be {@literal null}.
 * @return
 */
public KeyValueQuery<T> orderBy(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (this.sort.isSorted()) {
    this.sort = this.sort.and(sort);
  } else {
    this.sort = sort;
  }
  return this;
}

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

/**
 * Add given {@link Sort}.
 *
 * @param sort must not be {@literal null}.
 * @return
 */
public KeyValueQuery<T> orderBy(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  if (this.sort.isSorted()) {
    this.sort = this.sort.and(sort);
  } else {
    this.sort = sort;
  }
  return this;
}

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

@Override
protected Sort processSort(Sort sort) {
  if(sort.getOrderFor(DEFAULT_PERIOD_SORT_FIELD) != null){
    return sort;
  }
  return sort.and(new Sort(Direction.ASC, DEFAULT_PERIOD_SORT_FIELD));
}

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

public DocumentQuery with(@NonNull Sort sort) {
  if (sort.isSorted()) {
    this.sort = sort.and(this.sort);
  }
  return this;
}

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

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

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

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

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

/**
 * Creates a new {@link Sort} instance from the given {@link SortDefault} or appends it to the given {@link Sort}
 * instance if it's not {@literal null}.
 *
 * @param sortDefault
 * @param sortOrNull
 * @return
 */
private Sort appendOrCreateSortTo(SortDefault sortDefault, Sort sortOrNull) {
  String[] fields = SpringDataAnnotationUtils.getSpecificPropertyOrDefaultFromValue(sortDefault, "sort");
  if (fields.length == 0) {
    return Sort.unsorted();
  }
  return sortOrNull.and(Sort.by(sortDefault.direction(), fields));
}

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

@Override
public Message<?> pollMessageFromGroup(Object groupId) {
  Assert.notNull(groupId, "'groupId' must not be null");
  Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE);
  if (this.priorityEnabled) {
    sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort);
  }
  Query query = groupIdQuery(groupId).with(sort);
  MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName);
  Message<?> message = null;
  if (document != null) {
    message = document.getMessage();
  }
  return message;
}

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

public static Sort basicSort(SortDto... dtos) {
    Sort result = null;
    for(int i=0; i<dtos.length; i++) {
      SortDto dto = dtos[i];
      if(result == null) {
        result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField());
      } else {
        result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()));
      }
    }
    return result;
  }
}

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

public static Sort basicSort(SortDto... dtos) {
    Sort result = null;
    for(int i=0; i<dtos.length; i++) {
      SortDto dto = dtos[i];
      if(result == null) {
        result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField());
      } else {
        result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()));
      }
    }
    return result;
  }
}

相关文章