org.springframework.data.domain.Sort.Order#isIgnoreCase ( )源码实例Demo

下面列出了org.springframework.data.domain.Sort.Order#isIgnoreCase ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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

	Assert.notNull(order, "Order must not be null!");
	Assert.notNull(builder, "Builder 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;
}
 
源代码2 项目: spring-cloud-gcp   文件: PartTreeFirestoreQuery.java
/**
 * This method converts {@link org.springframework.data.domain.Sort.Order}
 * to {@link StructuredQuery.Order} for Firestore.
 */
private List<StructuredQuery.Order> createFirestoreSortOrders(Sort sort) {
	List<StructuredQuery.Order> sortOrders = new ArrayList<>();

	for (Order order : sort) {
		if (order.isIgnoreCase()) {
			throw new IllegalArgumentException("Datastore does not support ignore case sort orders.");
		}

		// Get the name of the field to sort on
		String fieldName =
				this.persistentEntity.getPersistentProperty(order.getProperty()).getFieldName();

		StructuredQuery.Direction dir =
				order.getDirection() == Direction.DESC
						? StructuredQuery.Direction.DESCENDING : StructuredQuery.Direction.ASCENDING;

		FieldReference ref = FieldReference.newBuilder().setFieldPath(fieldName).build();
		com.google.firestore.v1.StructuredQuery.Order firestoreOrder =
				com.google.firestore.v1.StructuredQuery.Order.newBuilder()
						.setField(ref)
						.setDirection(dir)
						.build();

		sortOrders.add(firestoreOrder);
	}

	return sortOrders;
}
 
/**
 * <p>
 * Sort on a sequence of fields, possibly none.
 * </P>
 *
 * @param query If not null, will contain one of more {@link Sort.Order} objects.
 * @return A sequence of comparators or {@code null}
 */
public Comparator<Entry<?, ?>> resolve(KeyValueQuery<?> query) {

    if (query == null || query.getSort() == Sort.unsorted()) {
        return null;
    }

    Comparator hazelcastPropertyComparator = null;

    for (Order order : query.getSort()) {

        if (order.getProperty().indexOf('.') > -1) {
            throw new UnsupportedOperationException("Embedded fields not implemented: " + order);
        }

        if (order.isIgnoreCase()) {
            throw new UnsupportedOperationException("Ignore case not implemented: " + order);
        }

        if (NullHandling.NATIVE != order.getNullHandling()) {
            throw new UnsupportedOperationException("Null handling not implemented: " + order);
        }

        if (hazelcastPropertyComparator == null) {
            hazelcastPropertyComparator = new HazelcastPropertyComparator(order.getProperty(),
                    order.isAscending());
        } else {
            hazelcastPropertyComparator = hazelcastPropertyComparator.thenComparing(
                    new HazelcastPropertyComparator(order.getProperty(),
                    order.isAscending()));
        }
    }

    return hazelcastPropertyComparator;
}