use of org.springframework.data.keyvalue.core.query.KeyValueQuery in project spring-data-keyvalue by spring-projects.
the class SpelSortAccessor method resolve.
/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.SortAccessor#resolve(org.springframework.data.keyvalue.core.query.KeyValueQuery)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@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"));
}
use of org.springframework.data.keyvalue.core.query.KeyValueQuery in project spring-data-keyvalue by spring-projects.
the class KeyValuePartTreeQuery method prepareQuery.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);
Object criteria = instance.getCriteria();
if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {
SpelExpression spelExpression = getSpelExpression(criteria);
EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(), parameters);
criteria = new SpelCriteria(spelExpression, context);
}
KeyValueQuery<?> query = new KeyValueQuery(criteria);
Pageable pageable = accessor.getPageable();
Sort sort = accessor.getSort();
query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));
if (pageable.isPaged()) {
query.setRows(pageable.getPageSize());
} else if (instance.getRows() >= 0) {
query.setRows(instance.getRows());
}
query.setSort(sort.isUnsorted() ? instance.getSort() : sort);
return query;
}
Aggregations