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

The following examples show how to use org.springframework.data.domain.Sort.Order#getProperty() . 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: OrderAdapter.java    From springlets with Apache License 2.0 5 votes vote down vote up
@Override
public OrderDto marshal(Order order) {

  if (order == null) {
    return null;
  }

  OrderDto dto = new OrderDto();
  dto.direction = order.getDirection();
  dto.property = order.getProperty();
  return dto;
}
 
Example 2
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;
}
 
Example 3
Source File: SpelSortAccessor.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@Override
public Comparator<?> resolve(KeyValueQuery<?> query) {

	if (query.getSort().isUnsorted()) {
		return null;
	}

	Optional<Comparator<?>> comparator = Optional.empty();
	for (Order order : query.getSort()) {

		SpelPropertyComparator<Object> spelSort = new SpelPropertyComparator<>(order.getProperty(), parser);

		if (Direction.DESC.equals(order.getDirection())) {

			spelSort.desc();

			if (!NullHandling.NATIVE.equals(order.getNullHandling())) {
				spelSort = NullHandling.NULLS_FIRST.equals(order.getNullHandling()) ? spelSort.nullsFirst()
						: spelSort.nullsLast();
			}
		}

		if (!comparator.isPresent()) {
			comparator = Optional.of(spelSort);
		} else {

			SpelPropertyComparator<Object> spelSortToUse = spelSort;
			comparator = comparator.map(it -> it.thenComparing(spelSortToUse));
		}
	}

	return comparator.orElseThrow(
			() -> new IllegalStateException("No sort definitions have been added to this CompoundComparator to compare"));
}
 
Example 4
Source File: VisitorRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 * 
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<VisitorEntity> query, VisitorEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "username":
				if (next.isAscending()) {
					query.orderBy($(alias.getUsername()).asc());
				} else {
					query.orderBy($(alias.getUsername()).desc());
				}
				break;
			case "name":
				if (next.isAscending()) {
					query.orderBy($(alias.getName()).asc());
				} else {
					query.orderBy($(alias.getName()).desc());
				}
				break;
			case "phoneNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getPhoneNumber()).asc());
				} else {
					query.orderBy($(alias.getPhoneNumber()).desc());
				}
				break;
			case "password":
				if (next.isAscending()) {
					query.orderBy($(alias.getPassword()).asc());
				} else {
					query.orderBy($(alias.getPassword()).desc());
				}
				break;
			case "acceptedCommercial":
				if (next.isAscending()) {
					query.orderBy($(alias.getAcceptedCommercial()).asc());
				} else {
					query.orderBy($(alias.getAcceptedCommercial()).desc());
				}
				break;
			case "acceptedTerms":
				if (next.isAscending()) {
					query.orderBy($(alias.getAcceptedTerms()).asc());
				} else {
					query.orderBy($(alias.getAcceptedTerms()).desc());
				}
				break;
			case "userType":
				if (next.isAscending()) {
					query.orderBy($(alias.getUserType()).asc());
				} else {
					query.orderBy($(alias.getUserType()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}
 
Example 5
Source File: QueueRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 *
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<QueueEntity> query, QueueEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "name":
				if (next.isAscending()) {
					query.orderBy($(alias.getName()).asc());
				} else {
					query.orderBy($(alias.getName()).desc());
				}
				break;
			case "logo":
				if (next.isAscending()) {
					query.orderBy($(alias.getLogo()).asc());
				} else {
					query.orderBy($(alias.getLogo()).desc());
				}
				break;
			case "currentNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getCurrentNumber()).asc());
				} else {
					query.orderBy($(alias.getCurrentNumber()).desc());
				}
				break;
			case "attentionTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getAttentionTime()).asc());
				} else {
					query.orderBy($(alias.getAttentionTime()).desc());
				}
				break;
			case "minAttentionTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getMinAttentionTime()).asc());
				} else {
					query.orderBy($(alias.getMinAttentionTime()).desc());
				}
				break;
			case "active":
				if (next.isAscending()) {
					query.orderBy($(alias.getActive()).asc());
				} else {
					query.orderBy($(alias.getActive()).desc());
				}
				break;
			case "customers":
				if (next.isAscending()) {
					query.orderBy($(alias.getCustomers()).asc());
				} else {
					query.orderBy($(alias.getCustomers()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}
 
Example 6
Source File: AccessCodeRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 *
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<AccessCodeEntity> query, AccessCodeEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "ticketNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getTicketNumber()).asc());
				} else {
					query.orderBy($(alias.getTicketNumber()).desc());
				}
				break;
			case "creationTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getCreationTime()).asc());
				} else {
					query.orderBy($(alias.getCreationTime()).desc());
				}
				break;
			case "startTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getStartTime()).asc());
				} else {
					query.orderBy($(alias.getStartTime()).desc());
				}
				break;
			case "endTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getEndTime()).asc());
				} else {
					query.orderBy($(alias.getEndTime()).desc());
				}
				break;
			case "visitor":
				if (next.isAscending()) {
					query.orderBy($(alias.getVisitor().getId()).asc());
				} else {
					query.orderBy($(alias.getVisitor().getId()).desc());
				}
				break;
			case "queue":
				if (next.isAscending()) {
					query.orderBy($(alias.getQueue().getId()).asc());
				} else {
					query.orderBy($(alias.getQueue().getId()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}