本文整理了Java中org.springframework.data.domain.Sort.isUnsorted()
方法的一些代码示例,展示了Sort.isUnsorted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.isUnsorted()
方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:isUnsorted
暂无
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Turns the given {@link Sort} into {@link javax.persistence.criteria.Order}s.
*
* @param sort the {@link Sort} instance to be transformed into JPA {@link javax.persistence.criteria.Order}s.
* @param from must not be {@literal null}.
* @param cb must not be {@literal null}.
* @return a {@link List} of {@link javax.persistence.criteria.Order}s.
*/
public static List<javax.persistence.criteria.Order> toOrders(Sort sort, From<?, ?> from, CriteriaBuilder cb) {
if (sort.isUnsorted()) {
return Collections.emptyList();
}
Assert.notNull(from, "From must not be null!");
Assert.notNull(cb, "CriteriaBuilder must not be null!");
List<javax.persistence.criteria.Order> orders = new ArrayList<>();
for (org.springframework.data.domain.Sort.Order order : sort) {
orders.add(toJpaOrder(order, from, cb));
}
return orders;
}
代码示例来源:origin: spring-projects/spring-data-mongodb
private static Direction toDirection(Sort sort, String property) {
if (sort.isUnsorted()) {
return Direction.DESC;
}
Order order = sort.getOrderFor(property);
return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
}
}
代码示例来源: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: spring-projects/spring-data-jpa
/**
* Adds {@literal order by} clause to the JPQL query.
*
* @param query the query string to which sorting is applied. Must not be {@literal null} or empty.
* @param sort the sort specification to apply.
* @param alias the alias to be used in the order by clause. May be {@literal null} or empty.
* @return the modified query string.
*/
public static String applySorting(String query, Sort sort, @Nullable String alias) {
Assert.hasText(query, "Query must not be null or empty!");
if (sort.isUnsorted()) {
return query;
}
StringBuilder builder = new StringBuilder(query);
if (!ORDER_BY.matcher(query).matches()) {
builder.append(" order by ");
} else {
builder.append(", ");
}
Set<String> aliases = getOuterJoinAliases(query);
Set<String> functionAliases = getFunctionAliases(query);
for (Order order : sort) {
builder.append(getOrderClause(aliases, functionAliases, alias, order)).append(", ");
}
builder.delete(builder.length() - 2, builder.length());
return builder.toString();
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* @return the sort {@link Document}.
*/
public Document getSortObject() {
if (this.sort.isUnsorted()) {
return new Document();
}
Document document = new Document();
this.sort.stream()//
.forEach(order -> document.put(order.getProperty(), order.isAscending() ? 1 : -1));
return document;
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Applies sorting to the given {@link JPQLQuery}.
*
* @param sort
* @param query must not be {@literal null}.
* @return the Querydsl {@link JPQLQuery}
*/
public <T> JPQLQuery<T> applySorting(Sort sort, JPQLQuery<T> query) {
if (sort.isUnsorted()) {
return query;
}
if (sort instanceof QSort) {
return addOrderByFrom((QSort) sort, query);
}
return addOrderByFrom(sort, query);
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
private static List<FieldSortBuilder> sort(Query query, ElasticsearchPersistentEntity<?> entity) {
if (query.getSort() == null || query.getSort().isUnsorted()) {
return Collections.emptyList();
}
List<FieldSortBuilder> mappedSort = new ArrayList<>();
for (Sort.Order order : query.getSort()) {
ElasticsearchPersistentProperty property = entity.getPersistentProperty(order.getProperty());
String fieldName = property != null ? property.getFieldName() : order.getProperty();
FieldSortBuilder sort = SortBuilders.fieldSort(fieldName)
.order(order.getDirection().isDescending() ? SortOrder.DESC : SortOrder.ASC);
if (order.getNullHandling() == Sort.NullHandling.NULLS_FIRST) {
sort.missing("_first");
} else if (order.getNullHandling() == Sort.NullHandling.NULLS_LAST) {
sort.missing("_last");
}
mappedSort.add(sort);
}
return mappedSort;
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
private static Direction toDirection(Sort sort, String property) {
if (sort.isUnsorted()) {
return Direction.DESC;
}
Order order = sort.getOrderFor(property);
return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
}
}
代码示例来源: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-data-rest
@Override
public Sort resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
Sort sort = delegate.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
return sort.isUnsorted() ? sort : translator.translateSort(sort, methodParameter, webRequest);
}
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
/**
* @return the sort {@link Document}.
*/
public Document getSortObject() {
if (this.sort.isUnsorted()) {
return new Document();
}
Document document = new Document();
this.sort.stream()//
.forEach(order -> document.put(order.getProperty(), order.isAscending() ? 1 : -1));
return document;
}
代码示例来源:origin: Microsoft/spring-data-cosmosdb
private String generateQuerySort(@NonNull Sort sort) {
if (sort.isUnsorted()) {
return "";
}
final String queryTail = "ORDER BY";
final List<String> subjects = sort.stream().map(this::getParameter).collect(Collectors.toList());
return queryTail + " " + String.join(",", subjects);
}
代码示例来源:origin: org.springframework.data/spring-data-jpa
/**
* Turns the given {@link Sort} into {@link javax.persistence.criteria.Order}s.
*
* @param sort the {@link Sort} instance to be transformed into JPA {@link javax.persistence.criteria.Order}s.
* @param from must not be {@literal null}.
* @param cb must not be {@literal null}.
* @return a {@link List} of {@link javax.persistence.criteria.Order}s.
*/
public static List<javax.persistence.criteria.Order> toOrders(Sort sort, From<?, ?> from, CriteriaBuilder cb) {
if (sort.isUnsorted()) {
return Collections.emptyList();
}
Assert.notNull(from, "From must not be null!");
Assert.notNull(cb, "CriteriaBuilder must not be null!");
List<javax.persistence.criteria.Order> orders = new ArrayList<>();
for (org.springframework.data.domain.Sort.Order order : sort) {
orders.add(toJpaOrder(order, from, cb));
}
return orders;
}
代码示例来源:origin: hatunet/spring-data-mybatis
@Override
public List<T> findAll(Sort sort) {
if (null == sort || sort.isUnsorted()) {
return findAll();
}
return selectList("__find", Collections.singletonMap("__sort", sort));
}
代码示例来源:origin: spring-cloud/spring-cloud-gcp
public static StringBuilder applySort(Sort sort, StringBuilder sql,
Function<Order, String> sortedPropertyNameFunction) {
if (sort == null || sort.isUnsorted()) {
return sql;
}
sql.append(" ORDER BY ");
StringJoiner sj = new StringJoiner(" , ");
sort.iterator().forEachRemaining((o) -> {
String sortedPropertyName = sortedPropertyNameFunction.apply(o);
String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")"
: sortedPropertyName;
sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC"));
});
return sql.append(sj);
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-spanner
public static StringBuilder applySort(Sort sort, StringBuilder sql,
Function<Order, String> sortedPropertyNameFunction) {
if (sort == null || sort.isUnsorted()) {
return sql;
}
sql.append(" ORDER BY ");
StringJoiner sj = new StringJoiner(" , ");
sort.iterator().forEachRemaining((o) -> {
String sortedPropertyName = sortedPropertyNameFunction.apply(o);
String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")"
: sortedPropertyName;
sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC"));
});
return sql.append(sj);
}
代码示例来源:origin: org.springframework.data/spring-data-rest-webmvc
@Override
public Sort resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
Sort sort = delegate.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
return sort.isUnsorted() ? sort : translator.translateSort(sort, methodParameter, webRequest);
}
}
代码示例来源:origin: org.springframework.data/spring-data-jpa
/**
* Applies sorting to the given {@link JPQLQuery}.
*
* @param sort
* @param query must not be {@literal null}.
* @return the Querydsl {@link JPQLQuery}
*/
public <T> JPQLQuery<T> applySorting(Sort sort, JPQLQuery<T> query) {
if (sort.isUnsorted()) {
return query;
}
if (sort instanceof QSort) {
return addOrderByFrom((QSort) sort, query);
}
return addOrderByFrom(sort, query);
}
代码示例来源:origin: hatunet/spring-data-mybatis
protected String buildStandardOrderBy(Sort sort) {
if (null == sort || sort.isUnsorted()) {
return "";
}
final Map<String, String> map = findNormalColumns().stream()
.collect(Collectors.toMap(p -> p.getName(), p -> p.getColumnName()));
return " order by " + sort.stream()
.map(order -> map.getOrDefault(order.getProperty(), order.getProperty())
+ ' ' + order.getDirection().name().toLowerCase())
.collect(Collectors.joining(","));
}
代码示例来源:origin: hatunet/spring-data-mybatis
@Override
public <X extends T> List<T> findAll(Sort sort, X condition) {
if (null == sort || sort.isUnsorted()) {
return findAll(condition);
}
return selectList("__find", new HashMap<String, Object>() {
{
put("__sort", sort);
put("__condition", condition);
}
});
}
内容来源于网络,如有侵权,请联系作者删除!