public SortOperation and(Sort sort) { return new SortOperation(this.sort.and(sort)); }
/** * Adds a {@link Sort} to the {@link Query} instance. * * @param sort * @return */ public Query with(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); if (sort.isUnsorted()) { return this; } sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> { throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! " + "MongoDB does not support sorting ignoring case currently!", it.getProperty())); }); this.sort = this.sort.and(sort); return this; }
public SortOperation and(Sort sort) { return new SortOperation(this.sort.and(sort)); }
/** * Adds a {@link Sort} to the {@link Query} instance. * * @param sort * @return */ public Query with(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); if (sort.isUnsorted()) { return this; } sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> { throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! " + "MongoDB does not support sorting ignoring case currently!", it.getProperty())); }); this.sort = this.sort.and(sort); return this; }
@Override public Message<?> pollMessageFromGroup(Object groupId) { Assert.notNull(groupId, "'groupId' must not be null"); Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE); if (this.priorityEnabled) { sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort); } Query query = groupIdQuery(groupId).with(sort); MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName); Message<?> message = null; if (document != null) { message = document.getMessage(); } return message; }
@SuppressWarnings("unchecked") public final <T extends Query> T addSort(Sort sort) { if (sort == null) { return (T) this; } if (this.sort == null) { this.sort = sort; } else { this.sort = this.sort.and(sort); } return (T) this; } }
/** * Add given {@link Sort}. * * @param sort {@literal null} {@link Sort} will be ignored. * @return */ public Query<T> orderBy(Sort sort) { if (sort == null) { return this; } if (this.sort != null) { this.sort.and(sort); } else { this.sort = sort; } return this; }
@SuppressWarnings("unchecked") @Override public final <T extends Query> T addSort(@Nullable Sort sort) { if (sort == null) { return (T) this; } if (this.sort == null) { this.sort = sort; } else { this.sort = this.sort.and(sort); } return (T) this; }
public SortingOperation and(Sort sort) { return new SortingOperation(this.sort.and(sort)); } }
/** * Add given {@link Sort}. * * @param sort must not be {@literal null}. * @return */ public KeyValueQuery<T> orderBy(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); if (this.sort.isSorted()) { this.sort = this.sort.and(sort); } else { this.sort = sort; } return this; }
/** * Add given {@link Sort}. * * @param sort must not be {@literal null}. * @return */ public KeyValueQuery<T> orderBy(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); if (this.sort.isSorted()) { this.sort = this.sort.and(sort); } else { this.sort = sort; } return this; }
/** * Add given {@link Sort}. * * @param sort must not be {@literal null}. * @return */ public KeyValueQuery<T> orderBy(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); if (this.sort.isSorted()) { this.sort = this.sort.and(sort); } else { this.sort = sort; } return this; }
@Override protected Sort processSort(Sort sort) { if(sort.getOrderFor(DEFAULT_PERIOD_SORT_FIELD) != null){ return sort; } return sort.and(new Sort(Direction.ASC, DEFAULT_PERIOD_SORT_FIELD)); }
public DocumentQuery with(@NonNull Sort sort) { if (sort.isSorted()) { this.sort = sort.and(this.sort); } return this; }
/** * Creates the actual query object applying the given {@link Sort} parameter. Use this method in case you haven't * provided a {@link ParameterAccessor} in the first place but want to apply dynamic sorting nevertheless. * * @param dynamicSort must not be {@literal null}. * @return */ public T createQuery(Sort dynamicSort) { Assert.notNull(dynamicSort, "DynamicSort must not be null!"); return complete(createCriteria(tree), tree.getSort().and(dynamicSort)); }
/** * Creates the actual query object applying the given {@link Sort} parameter. Use this method in case you haven't * provided a {@link ParameterAccessor} in the first place but want to apply dynamic sorting nevertheless. * * @param sort * @return */ public T createQuery(Sort dynamicSort) { Sort staticSort = tree.getSort(); Sort sort = staticSort != null ? staticSort.and(dynamicSort) : dynamicSort; return complete(createCriteria(tree), sort); }
/** * Creates a new {@link Sort} instance from the given {@link SortDefault} or appends it to the given {@link Sort} * instance if it's not {@literal null}. * * @param sortDefault * @param sortOrNull * @return */ private Sort appendOrCreateSortTo(SortDefault sortDefault, Sort sortOrNull) { String[] fields = SpringDataAnnotationUtils.getSpecificPropertyOrDefaultFromValue(sortDefault, "sort"); if (fields.length == 0) { return Sort.unsorted(); } return sortOrNull.and(Sort.by(sortDefault.direction(), fields)); }
@Override public Message<?> pollMessageFromGroup(Object groupId) { Assert.notNull(groupId, "'groupId' must not be null"); Sort sort = Sort.by(MessageDocumentFields.LAST_MODIFIED_TIME, MessageDocumentFields.SEQUENCE); if (this.priorityEnabled) { sort = Sort.by(Sort.Direction.DESC, MessageDocumentFields.PRIORITY).and(sort); } Query query = groupIdQuery(groupId).with(sort); MessageDocument document = this.mongoTemplate.findAndRemove(query, MessageDocument.class, this.collectionName); Message<?> message = null; if (document != null) { message = document.getMessage(); } return message; }
public static Sort basicSort(SortDto... dtos) { Sort result = null; for(int i=0; i<dtos.length; i++) { SortDto dto = dtos[i]; if(result == null) { result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()); } else { result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField())); } } return result; } }
public static Sort basicSort(SortDto... dtos) { Sort result = null; for(int i=0; i<dtos.length; i++) { SortDto dto = dtos[i]; if(result == null) { result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()); } else { result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField())); } } return result; } }