@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); }
@Override public String toString() { String result = String.format("%s: %s", property, direction); if (!NullHandling.NATIVE.equals(nullHandling)) { result += ", " + nullHandling; } if (ignoreCase) { result += ", ignoring case"; } return result; } }
/** * 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); }
/** * Transforms a {@code Sort.Order} object into a comparator item. * * @param sortOrder * the {@code Sort.Order} object * @return the comparator item */ public static ComparatorItem fromSortOrder(Sort.Order sortOrder) { if (sortOrder == null || sortOrder.getProperty() == null || sortOrder.getProperty().trim().length() == 0) { return null; } boolean nullIsFirst = Sort.NullHandling.NULLS_FIRST.equals(sortOrder.getNullHandling()); return new ComparatorItem(sortOrder.getProperty(), sortOrder.isAscending(), sortOrder.isIgnoreCase(), nullIsFirst); }
private static StructuredQuery.OrderBy createOrderBy(DatastorePersistentEntity<?> persistentEntity, Sort.Order order) { if (order.isIgnoreCase()) { throw new DatastoreDataException("Datastore doesn't support sorting ignoring case"); } if (!order.getNullHandling().equals(Sort.NullHandling.NATIVE)) { throw new DatastoreDataException("Datastore supports only NullHandling.NATIVE null handling"); } return new StructuredQuery.OrderBy( persistentEntity.getPersistentProperty(order.getProperty()).getFieldName(), (order.getDirection() == Sort.Direction.DESC) ? StructuredQuery.OrderBy.Direction.DESCENDING : StructuredQuery.OrderBy.Direction.ASCENDING); }
private static StructuredQuery.OrderBy createOrderBy(DatastorePersistentEntity<?> persistentEntity, Sort.Order order) { if (order.isIgnoreCase()) { throw new DatastoreDataException("Datastore doesn't support sorting ignoring case"); } if (!order.getNullHandling().equals(Sort.NullHandling.NATIVE)) { throw new DatastoreDataException("Datastore supports only NullHandling.NATIVE null handling"); } return new StructuredQuery.OrderBy( persistentEntity.getPersistentProperty(order.getProperty()).getFieldName(), (order.getDirection() == Sort.Direction.DESC) ? StructuredQuery.OrderBy.Direction.DESCENDING : StructuredQuery.OrderBy.Direction.ASCENDING); }
/** * 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); }