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

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

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

Sort.unsorted介绍

[英]Returns a Sort instances representing no sorting setup at all.
[中]返回一个表示完全没有排序设置的排序实例。

代码示例

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

@Override
public Optional<T> findOne(@Nullable Specification<T> spec) {
  try {
    return Optional.of(getQuery(spec, Sort.unsorted()).getSingleResult());
  } catch (NoResultException e) {
    return Optional.empty();
  }
}

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

@Override
public List<T> findAll() {
  return getQuery(null, Sort.unsorted()).getResultList();
}

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

@Override
public <S extends T> Flux<S> findAll(Example<S> example) {
  Assert.notNull(example, "Example must not be null!");
  return findAll(example, Sort.unsorted());
}

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

@Override
public List<T> findAll(@Nullable Specification<T> spec) {
  return getQuery(spec, Sort.unsorted()).getResultList();
}

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

@Override
public <S extends T> List<S> findAll(Example<S> example) {
  return findAll(example, Sort.unsorted());
}

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

@Override
public <S extends T> Optional<S> findOne(Example<S> example) {
  try {
    return Optional.of(
        getQuery(new ExampleSpecification<S>(example), example.getProbeType(), Sort.unsorted()).getSingleResult());
  } catch (NoResultException e) {
    return Optional.empty();
  }
}

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

@Override
public <S extends T> boolean exists(Example<S> example) {
  return !getQuery(new ExampleSpecification<S>(example), example.getProbeType(), Sort.unsorted()).getResultList()
      .isEmpty();
}

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

@Override
public List<T> findAllById(Iterable<ID> ids) {
  Assert.notNull(ids, "The given Iterable of Id's must not be null!");
  if (!ids.iterator().hasNext()) {
    return Collections.emptyList();
  }
  if (entityInformation.hasCompositeId()) {
    List<T> results = new ArrayList<T>();
    for (ID id : ids) {
      findById(id).ifPresent(results::add);
    }
    return results;
  }
  ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
  TypedQuery<T> query = getQuery(specification, Sort.unsorted());
  return query.setParameter(specification.parameter, ids).getResultList();
}

代码示例来源:origin: apache/ignite

/**
 * Add a dynamic part of query for the sorting support.
 *
 * @param sql SQL text string.
 * @param sort Sort method.
 * @return Sorting criteria in StringBuilder.
 */
public static StringBuilder addSorting(StringBuilder sql, Sort sort) {
  if (sort != null && sort != Sort.unsorted()) {
    sql.append(" ORDER BY ");
    for (Sort.Order order : sort) {
      sql.append(order.getProperty()).append(" ").append(order.getDirection());
      if (order.getNullHandling() != Sort.NullHandling.NATIVE) {
        sql.append(" ").append("NULL ");
        switch (order.getNullHandling()) {
          case NULLS_FIRST:
            sql.append("FIRST");
            break;
          case NULLS_LAST:
            sql.append("LAST");
            break;
        }
      }
      sql.append(", ");
    }
    sql.delete(sql.length() - 2, sql.length());
  }
  return sql;
}

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

@Override
public <S extends T> List<S> findAll(Example<S> example) {
  return getQuery(new ExampleSpecification<S>(example), example.getProbeType(), Sort.unsorted()).getResultList();
}

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

/**
 * Creates a new {@link TypedQuery} from the given {@link Specification}.
 *
 * @param spec can be {@literal null}.
 * @param domainClass must not be {@literal null}.
 * @param pageable must not be {@literal null}.
 * @return
 */
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
    Pageable pageable) {
  Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
  return getQuery(spec, domainClass, sort);
}

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

/**
 * Creates a new {@link TypedQuery} from the given {@link Specification}.
 *
 * @param spec can be {@literal null}.
 * @param pageable must not be {@literal null}.
 * @return
 */
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
  Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
  return getQuery(spec, getDomainClass(), sort);
}

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

private Sort getDynamicSort(Object[] values) {
    return parameters.potentiallySortsDynamically() //
        ? new ParametersParameterAccessor(parameters, values).getSort() //
        : Sort.unsorted();
  }
}

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public Sort getSort() {
  return Sort.unsorted();
}

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

@Override
public <S extends T> Flux<S> findAll(Example<S> example) {
  Assert.notNull(example, "Example must not be null!");
  return findAll(example, Sort.unsorted());
}

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

public String getCypherQuery(Sort sort) {
  // Custom queries in the OGM do not support pageable
  String result = cypherQuery;
  if (sort != Sort.unsorted()) {
    result = addSorting(cypherQuery, sort);
  }
  return result;
}

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

@Override
public <S extends T> List<S> findAll(Example<S> example) {
  return findAll(example, Sort.unsorted());
}

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

/**
 * Translates {@link Sort} orders from Jackson-mapped field names to {@link PersistentProperty} names. Properties
 * that cannot be resolved are dropped.
 *
 * @param input must not be {@literal null}.
 * @param rootEntity must not be {@literal null}.
 * @return {@link Sort} with translated field names or {@literal null} if translation dropped all sort fields.
 */
public Sort translateSort(Sort input, PersistentEntity<?, ?> rootEntity) {
  Assert.notNull(input, "Sort must not be null!");
  Assert.notNull(rootEntity, "PersistentEntity must not be null!");
  List<Order> filteredOrders = new ArrayList<Order>();
  for (Order order : input) {
    List<String> iteratorSource = new ArrayList<String>();
    Matcher matcher = SPLITTER.matcher("_" + order.getProperty());
    while (matcher.find()) {
      iteratorSource.add(matcher.group(1));
    }
    String mappedPropertyPath = getMappedPropertyPath(rootEntity, iteratorSource);
    if (mappedPropertyPath != null) {
      filteredOrders.add(order.withProperty(mappedPropertyPath));
    }
  }
  return filteredOrders.isEmpty() ? Sort.unsorted() : Sort.by(filteredOrders);
}

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

public String getCypherQuery(Pageable pageable, boolean forSlicing) {
  String result = cypherQuery;
  Sort sort = null;
  if (pageable.isPaged() && pageable.getSort() != Sort.unsorted()) {
    sort = pageable.getSort();
  }
  if (sort != Sort.unsorted()) {
    // Custom queries in the OGM do not support pageable
    result = addSorting(result, sort);
  }
  result = addPaging(result, pageable, forSlicing);
  return result;
}

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

public static SortOrder convert(Sort sort) {

    SortOrder sortOrder = new SortOrder();

    if (sort != Sort.unsorted()) {
      for (Sort.Order order : sort) {
        if (order.isAscending()) {
          sortOrder.add(order.getProperty());
        } else {
          sortOrder.add(SortOrder.Direction.DESC, order.getProperty());
        }
      }
    }
    return sortOrder;
  }
}

相关文章