Codota Logo
Sort$Order.getProperty
Code IndexAdd Codota to your IDE (free)

How to use
getProperty
method
in
org.springframework.data.domain.Sort$Order

Best Java code snippets using org.springframework.data.domain.Sort$Order.getProperty (Showing top 20 results out of 603)

  • Common ways to obtain Sort$Order
private void myMethod () {
Sort$Order s =
  • Codota IconSort sort;String property;sort.getOrderFor(property)
  • Smart code suggestions by Codota
}
origin: apache/ignite

/**
 * Add a dynamic part of query for the sorting support.
 *
 * @param sql SQL text string.
 * @param sort Sort method.
 */
public static StringBuilder addSorting(StringBuilder sql, Sort sort) {
  if (sort != null) {
    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: 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-mongodb

/**
 * Creates a new {@link SortModifier} instance given {@link Sort}.
 *
 * @param sort must not be {@literal null}.
 */
SortModifier(Sort sort) {
  Assert.notNull(sort, "Sort must not be null!");
  for (Order order : sort) {
    if (order.isIgnoreCase()) {
      throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
          + "MongoDB does not support sorting ignoring case currently!", order.getProperty()));
    }
  }
  this.sort = sort;
}
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-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: spring-projects/spring-data-jpa

/**
 * Creates a criteria API {@link javax.persistence.criteria.Order} from the given {@link Order}.
 *
 * @param order the order to transform into a JPA {@link javax.persistence.criteria.Order}
 * @param from the {@link From} the {@link Order} expression is based on
 * @param cb the {@link CriteriaBuilder} to build the {@link javax.persistence.criteria.Order} with
 * @return
 */
@SuppressWarnings("unchecked")
private static javax.persistence.criteria.Order toJpaOrder(Order order, From<?, ?> from, CriteriaBuilder cb) {
  PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType());
  Expression<?> expression = toExpressionRecursively(from, property);
  if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) {
    Expression<String> lower = cb.lower((Expression<String>) expression);
    return order.isAscending() ? cb.asc(lower) : cb.desc(lower);
  } else {
    return order.isAscending() ? cb.asc(expression) : cb.desc(expression);
  }
}
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

/**
 * Returns the order clause for the given {@link Order}. Will prefix the clause with the given alias if the referenced
 * property refers to a join alias, i.e. starts with {@code $alias.}.
 *
 * @param joinAliases the join aliases of the original query. Must not be {@literal null}.
 * @param alias the alias for the root entity. May be {@literal null}.
 * @param order the order object to build the clause for. Must not be {@literal null}.
 * @return a String containing a order clause. Guaranteed to be not {@literal null}.
 */
private static String getOrderClause(Set<String> joinAliases, Set<String> functionAlias, @Nullable String alias,
    Order order) {
  String property = order.getProperty();
  checkSortExpression(order);
  if (functionAlias.contains(property)) {
    return String.format("%s %s", property, toJpaDirection(order));
  }
  boolean qualifyReference = !property.contains("("); // ( indicates a function
  for (String joinAlias : joinAliases) {
    if (property.startsWith(joinAlias.concat("."))) {
      qualifyReference = false;
      break;
    }
  }
  String reference = qualifyReference && StringUtils.hasText(alias) ? String.format("%s.%s", alias, property)
      : property;
  String wrapped = order.isIgnoreCase() ? String.format("lower(%s)", reference) : reference;
  return String.format("%s %s", wrapped, toJpaDirection(order));
}
origin: spring-projects/spring-data-mongodb

public void onCreation(PartTreeMongoQuery query) {
  PartTree tree = query.getTree();
  if (!tree.hasPredicate()) {
    return;
  }
  Index index = new Index();
  index.named(query.getQueryMethod().getName());
  Sort sort = tree.getSort();
  for (Part part : tree.getParts()) {
    if (GEOSPATIAL_TYPES.contains(part.getType())) {
      return;
    }
    String property = part.getProperty().toDotPath();
    Direction order = toDirection(sort, property);
    index.on(property, order);
  }
  // Add fixed sorting criteria to index
  if (sort.isSorted()) {
    for (Order order : sort) {
      index.on(order.getProperty(), order.getDirection());
    }
  }
  MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation();
  indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index);
  LOG.debug(String.format("Created %s!", index));
}
origin: spring-projects/spring-data-elasticsearch

FieldSortBuilder sort = SortBuilders.fieldSort(order.getProperty())
    .order(order.getDirection().isDescending() ? SortOrder.DESC : SortOrder.ASC);
if (order.getNullHandling() == Sort.NullHandling.NULLS_FIRST) {
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: spring-projects/spring-data-jpa

  /**
   * Check any given {@link JpaOrder#isUnsafe()} order for presence of at least one property offending the
   * {@link #PUNCTATION_PATTERN} and throw an {@link Exception} indicating potential unsafe order by expression.
   *
   * @param order
   */
  private static void checkSortExpression(Order order) {

    if (order instanceof JpaOrder && ((JpaOrder) order).isUnsafe()) {
      return;
    }

    if (PUNCTATION_PATTERN.matcher(order.getProperty()).find()) {
      throw new InvalidDataAccessApiUsageException(String.format(UNSAFE_PROPERTY_REFERENCE, order));
    }
  }
}
origin: org.springframework.data/spring-data-mongodb

  @Override
  public Document toDocument(AggregationOperationContext context) {

    Document object = new Document();

    for (Order order : sort) {

      // Check reference
      FieldReference reference = context.getReference(order.getProperty());
      object.put(reference.getRaw(), order.isAscending() ? 1 : -1);
    }

    return new Document("$sort", object);
  }
}
origin: spring-projects/spring-data-mongodb

  @Override
  public Document toDocument(AggregationOperationContext context) {

    Document object = new Document();

    for (Order order : sort) {

      // Check reference
      FieldReference reference = context.getReference(order.getProperty());
      object.put(reference.getRaw(), order.isAscending() ? 1 : -1);
    }

    return new Document("$sort", object);
  }
}
origin: org.springframework.data/spring-data-mongodb

private static Document getSortObject(Sort sort) {
  Document document = new Document();
  for (Order order : sort) {
    document.put(order.getProperty(), order.isAscending() ? 1 : -1);
  }
  return document;
}
origin: spring-projects/spring-data-mongodb

/**
 * Transforms a plain {@link Order} into a Querydsl specific {@link OrderSpecifier}.
 *
 * @param order
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected OrderSpecifier<?> toOrder(Order order) {
  Expression<Object> property = builder.get(order.getProperty());
  return new OrderSpecifier(
      order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, property);
}
origin: spring-projects/spring-data-neo4j

private String getSortOrder(Sort sort) {
  return sort.stream()
      .map(order -> order.getProperty() + " " + order.getDirection())
      .collect(Collectors.joining(", "));
}
origin: spring-projects/spring-data-mongodb

private static Document getSortObject(Sort sort) {
  Document document = new Document();
  for (Order order : sort) {
    document.put(order.getProperty(), order.isAscending() ? 1 : -1);
  }
  return document;
}
origin: org.springframework.data/spring-data-mongodb

  /**
   * Transforms a plain {@link Order} into a Querydsl specific {@link OrderSpecifier}.
   *
   * @param order
   * @return
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  private OrderSpecifier<?> toOrder(Order order) {

    Expression<Object> property = builder.get(order.getProperty());

    return new OrderSpecifier(
        order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, property);
  }
}
origin: spring-projects/spring-data-jpa

  /**
   * Creates an {@link Expression} for the given {@link Order} property.
   *
   * @param order must not be {@literal null}.
   * @return
   */
  private Expression<?> buildOrderPropertyPathFrom(Order order) {

    Assert.notNull(order, "Order must not be null!");

    PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
    Expression<?> sortPropertyExpression = builder;

    while (path != null) {

      if (!path.hasNext() && order.isIgnoreCase()) {
        // if order is ignore-case we have to treat the last path segment as a String.
        sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
      } else {
        sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
      }

      path = path.next();
    }

    return sortPropertyExpression;
  }
}
org.springframework.data.domainSort$OrdergetProperty

Javadoc

Returns the property to order for.

Popular methods of Sort$Order

  • getDirection
    Returns the order the property shall be sorted for.
  • <init>
    Creates a new Order instance. if order is null then order defaults to Sort#DEFAULT_DIRECTION
  • isAscending
    Returns whether sorting for this property shall be ascending.
  • isIgnoreCase
  • getNullHandling
  • ignoreCase
  • by
  • desc
    Creates a new Order instance. Takes a single property. Direction is Direction#ASC and NullHandling N
  • with
  • asc
    Creates a new Order instance. Takes a single property. Direction is Direction#ASC and NullHandling N
  • isDescending
    Returns whether sorting for this property shall be descending.
  • withProperty
  • isDescending,
  • withProperty

Popular in Java

  • Finding current android device location
  • startActivity (Activity)
  • getSharedPreferences (Context)
  • getSystemService (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Collectors (java.util.stream)
  • JList (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now