public Document getIndexKeys() { Document document = new Document(); for (Entry<String, Direction> entry : fieldSpec.entrySet()) { document.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1); } return document; }
public Document getIndexKeys() { Document document = new Document(); for (Entry<String, Direction> entry : fieldSpec.entrySet()) { document.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1); } return document; }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (!(obj instanceof Order)) { return false; } Order that = (Order) obj; return this.direction.equals(that.direction) && this.property.equals(that.property) && this.ignoreCase == that.ignoreCase && this.nullHandling.equals(that.nullHandling); }
final SortDirection direction = order.getDirection().equals(Sort.Direction.ASC) ? SortDirection.ASCENDING : SortDirection.DESCENDING; final NullHandling nullHandling; switch (order.getNullHandling()) {
final SortDirection direction = order.getDirection().equals(Sort.Direction.ASC) ? SortDirection.ASCENDING : SortDirection.DESCENDING; final NullHandling nullHandling; switch (order.getNullHandling()) {
if (Direction.DESC.equals(order.getDirection())) {
if (Direction.DESC.equals(order.getDirection())) {
protected void applySortIfSpecified(QueryRequest queryRequest, List<String> permittedPropertyNames) { if (permittedPropertyNames.size() > 2) { throw new UnsupportedOperationException("Can only sort by at most a single global hash and range key"); } if (sort != null) { boolean sortAlreadySet = false; for (Order order : sort) { if (permittedPropertyNames.contains(order.getProperty())) { if (sortAlreadySet) { throw new UnsupportedOperationException("Sorting by multiple attributes not possible"); } if (queryRequest.getKeyConditions().size() > 1 && !hasIndexHashKeyEqualCondition()) { throw new UnsupportedOperationException( "Sorting for global index queries with criteria on both hash and range not possible"); } queryRequest.setScanIndexForward(order.getDirection().equals(Direction.ASC)); sortAlreadySet = true; } else { throw new UnsupportedOperationException("Sorting only possible by " + permittedPropertyNames + " for the criteria specified"); } } } }
if (Direction.DESC.equals(order.getDirection())) {
protected void applySortIfSpecified(QueryRequest queryRequest, List<String> permittedPropertyNames) { if (permittedPropertyNames.size() > 2) { throw new UnsupportedOperationException("Can only sort by at most a single global hash and range key"); } boolean sortAlreadySet = false; for (Order order : sort) { if (permittedPropertyNames.contains(order.getProperty())) { if (sortAlreadySet) { throw new UnsupportedOperationException("Sorting by multiple attributes not possible"); } if (queryRequest.getKeyConditions().size() > 1 && !hasIndexHashKeyEqualCondition()) { throw new UnsupportedOperationException( "Sorting for global index queries with criteria on both hash and range not possible"); } queryRequest.setScanIndexForward(order.getDirection().equals(Direction.ASC)); sortAlreadySet = true; } else { throw new UnsupportedOperationException("Sorting only possible by " + permittedPropertyNames + " for the criteria specified and not for " + order.getProperty()); } } }
protected void applySortIfSpecified(DynamoDBQueryExpression<T> queryExpression, List<String> permittedPropertyNames) { if (permittedPropertyNames.size() > 1) { throw new UnsupportedOperationException("Can only sort by at most a single range or index range key"); } if (sort != null) { boolean sortAlreadySet = false; for (Order order : sort) { if (permittedPropertyNames.contains(order.getProperty())) { if (sortAlreadySet) { throw new UnsupportedOperationException("Sorting by multiple attributes not possible"); } queryExpression.setScanIndexForward(order.getDirection().equals(Direction.ASC)); sortAlreadySet = true; } else { throw new UnsupportedOperationException("Sorting only possible by " + permittedPropertyNames + " for the criteria specified"); } } } }
protected void applySortIfSpecified(DynamoDBQueryExpression<T> queryExpression, List<String> permittedPropertyNames) { if (permittedPropertyNames.size() > 1) { throw new UnsupportedOperationException("Can only sort by at most a single range or index range key"); } boolean sortAlreadySet = false; for (Order order : sort) { if (permittedPropertyNames.contains(order.getProperty())) { if (sortAlreadySet) { throw new UnsupportedOperationException("Sorting by multiple attributes not possible"); } queryExpression.setScanIndexForward(order.getDirection().equals(Direction.ASC)); sortAlreadySet = true; } else { throw new UnsupportedOperationException( "Sorting only possible by " + permittedPropertyNames + " for the criteria specified"); } } }
protected Criteria getCriteria(Sort sortParam, Pageable pageable) { Criteria criteria = getSession().createCriteria(getDomainClass()); Sort sort = pageable == null ? sortParam : pageable.getSort(); if(sort != null) { for(Sort.Order order : sort) { if(order.getDirection().equals(Sort.Direction.ASC)) { criteria.addOrder(Order.asc(order.getProperty())); } else if(order.getDirection().equals(Sort.Direction.DESC)) { criteria.addOrder(Order.desc(order.getProperty())); } } } if(pageable != null) { criteria.setFirstResult(pageable.getOffset()); criteria.setMaxResults(pageable.getPageSize()); } return criteria; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Comparator<?> aerospikePropertyComparator(Query<?> query ) { if (query == null || query.getSort() == null) { return null; } CompoundComparator compoundComperator = new CompoundComparator(); for (Order order : query.getSort()) { if (Direction.DESC.equals(order.getDirection())) { compoundComperator.addComparator(new PropertyComparator(order.getProperty(), true, false)); }else { compoundComperator.addComparator(new PropertyComparator(order.getProperty(), true, true)); } } return compoundComperator; }
/** * Given a sort parameter from the Spring Data framework, will determine the appropriate sort metadata compatible * with this framework * @param sort the sort specification * @return converted sort metadata */ protected Sort getSort(org.springframework.data.domain.Sort sort) { final List<Order> orders = new ArrayList<>(); for (org.springframework.data.domain.Sort.Order order : sort) { final SortDirection sortDirection = order.getDirection().equals(ASC) ? SortDirection.ASCENDING : SortDirection.DESCENDING; final NullHandling nullHandling = order.getNullHandling().equals(NULLS_FIRST) ? NullHandling.NULLS_FIRST : (order.getNullHandling().equals(NULLS_LAST) ? NullHandling.NULLS_LAST : NullHandling.DEFAULT); orders.add(new ImmutableOrder(sortDirection, order.getProperty(), nullHandling)); } return new ImmutableSort(orders); }
/** * Given a sort parameter from the Spring Data framework, will determine the appropriate sort metadata compatible * with this framework * @param sort the sort specification * @return converted sort metadata */ protected Sort getSort(org.springframework.data.domain.Sort sort) { final List<Order> orders = new ArrayList<>(); for (org.springframework.data.domain.Sort.Order order : sort) { final SortDirection sortDirection = order.getDirection().equals(ASC) ? SortDirection.ASCENDING : SortDirection.DESCENDING; final NullHandling nullHandling = order.getNullHandling().equals(NULLS_FIRST) ? NullHandling.NULLS_FIRST : (order.getNullHandling().equals(NULLS_LAST) ? NullHandling.NULLS_LAST : NullHandling.DEFAULT); orders.add(new ImmutableOrder(sortDirection, order.getProperty(), nullHandling)); } return new ImmutableSort(orders); }
/** * Returns whether the direction is descending. * * @return * @since 1.13 */ public boolean isDescending() { return this.equals(DESC); }
/** * Returns whether the direction is ascending. * * @return * @since 1.13 */ public boolean isAscending() { return this.equals(ASC); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Order)) { return false; } Order that = (Order) obj; return this.direction.equals(that.direction) && this.property.equals(that.property); }
/** * Returns whether sorting for this property shall be ascending. * * @return */ public boolean isAscending() { return this.direction.equals(Direction.ASC); }