Java Code Examples for org.springframework.data.domain.Sort.Order#isIgnoreCase()

The following examples show how to use org.springframework.data.domain.Sort.Order#isIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyValueQuerydslUtils.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: PartTreeFirestoreQuery.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: HazelcastSortAccessor.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
/**
 * <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;
}