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

The following examples show how to use org.springframework.data.domain.Sort#unsorted() . 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: PageableDataProvider.java    From spring-data-provider with Apache License 2.0 6 votes vote down vote up
private <T, F> Sort createSpringSort(Query<T, F> q) {
    List<QuerySortOrder> sortOrders;
    if (q.getSortOrders().isEmpty()) {
        sortOrders = getDefaultSortOrders();
    } else {
        sortOrders = q.getSortOrders();
    }
    List<Order> orders = sortOrders.stream()
            .map(PageableDataProvider::queryOrderToSpringOrder)
            .collect(Collectors.toList());
    if (orders.isEmpty()) {
        return Sort.unsorted();
    } else {
        return Sort.by(orders);
    }
}
 
Example 2
Source File: SpecificationUtils.java    From jbone with Apache License 2.0 6 votes vote down vote up
/**
 * 构建排序
 * @param sortDOS s
 * @return r
 */
public static Sort buildSort(List<SearchSortDO> sortDOS){
    Sort sort = null;
    //构建排序
    if(!CollectionUtils.isEmpty(sortDOS)){
        List<Sort.Order> orders = new ArrayList<>();
        for (SearchSortDO sortDO: sortDOS) {
            Sort.Order order = null;
            if(sortDO.getDirection() == SearchSortDO.Direction.ASC){
                order = Sort.Order.asc(sortDO.getProperty());
            }else{
                order = Sort.Order.desc(sortDO.getProperty());
            }
            orders.add(order);
        }
        sort = Sort.by(orders);
    }else{
        sort = Sort.unsorted();
    }
    return sort;
}
 
Example 3
Source File: AbstractPredicateBuilder.java    From spring-data-jpa-datatables with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a 'LIMIT .. OFFSET .. ORDER BY ..' clause for the given {@link DataTablesInput}.
 *
 * @return a {@link Pageable}, must not be {@literal null}.
 */
public Pageable createPageable() {
    List<Sort.Order> orders = new ArrayList<>();
    for (org.springframework.data.jpa.datatables.mapping.Order order : input.getOrder()) {
        Column column = input.getColumns().get(order.getColumn());
        if (column.getOrderable()) {
            String sortColumn = column.getData();
            Sort.Direction sortDirection = Sort.Direction.fromString(order.getDir());
            orders.add(new Sort.Order(sortDirection, sortColumn));
        }
    }
    Sort sort = orders.isEmpty() ? Sort.unsorted() : Sort.by(orders);

    if (input.getLength() == -1) {
        input.setStart(0);
        input.setLength(Integer.MAX_VALUE);
    }
    return new DataTablesPageRequest(input.getStart(), input.getLength(), sort);
}
 
Example 4
Source File: PageDelegate.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public Sort getSort() {
    List<io.micronaut.data.model.Sort.Order> orderBy = delegate.getSort().getOrderBy();
    if (CollectionUtils.isEmpty(orderBy)) {
        return Sort.unsorted();
    } else {
        return new SortDelegate(delegate.getSort());
    }
}
 
Example 5
Source File: SpringPageableRequestArgumentBinder.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public BindingResult<Pageable> bind(ArgumentConversionContext<Pageable> context, HttpRequest<?> source) {
    HttpParameters parameters = source.getParameters();
    int page = Math.max(parameters.getFirst(configuration.getPageParameterName(), Integer.class)
            .orElse(0), 0);
    final int configuredMaxSize = configuration.getMaxPageSize();
    final int defaultSize = configuration.getDefaultPageSize();
    int size = Math.min(parameters.getFirst(configuration.getSizeParameterName(), Integer.class)
            .orElse(defaultSize), configuredMaxSize);
    String sortParameterName = configuration.getSortParameterName();
    boolean hasSort = parameters.contains(sortParameterName);
    Pageable pageable;
    Sort sort;
    if (hasSort) {
        List<String> sortParams = parameters.getAll(sortParameterName);

        List<Sort.Order> orders = sortParams.stream()
                .map(sortMapper)
                .collect(Collectors.toList());
        sort = Sort.by(orders);
    } else {
        sort = Sort.unsorted();
    }

    if (size < 1) {
        if (page == 0 && configuredMaxSize < 1 && sort.isUnsorted()) {
            pageable = Pageable.unpaged();
        } else {
            pageable = PageRequest.of(page, defaultSize, sort);
        }
    } else {
        pageable = PageRequest.of(page, size, sort);
    }

    return () -> Optional.of(pageable);
}
 
Example 6
Source File: ProjectRepositorySortIT.java    From spring-data-cosmosdb with MIT License 5 votes vote down vote up
@Test
public void testFindAllUnSorted() {
    final Sort sort = Sort.unsorted();
    final List<SortedProject> projects = Lists.newArrayList(this.repository.findAll(sort));

    PROJECTS.sort(Comparator.comparing(SortedProject::getId));
    projects.sort(Comparator.comparing(SortedProject::getId));

    Assert.assertEquals(PROJECTS.size(), projects.size());
    Assert.assertEquals(PROJECTS, projects);
}
 
Example 7
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Add a dynamic part of query for the sorting support.
 *
 * @param sql  SQL text string.
 * @param sort Sort method.
 * @return Sorting criteria in StringBuilder.
 */
public static StringBuilder addSorting(StringBuilder sql, Sort sort) {
    if (sort != null && sort != Sort.unsorted()) {
        sql.append(" ORDER BY ");

        for (Sort.Order order : sort) {
            sql.append(order.getProperty()).append(" ").append(order.getDirection());

            if (order.getNullHandling() != Sort.NullHandling.NATIVE) {
                sql.append(" ").append("NULL ");

                switch (order.getNullHandling()) {
                    case NULLS_FIRST:
                        sql.append("FIRST");
                        break;
                    case NULLS_LAST:
                        sql.append("LAST");
                        break;
                    default:
                }
            }
            sql.append(", ");
        }

        sql.delete(sql.length() - 2, sql.length());
    }

    return sql;
}
 
Example 8
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Add a dynamic part of query for the sorting support.
 *
 * @param sql  SQL text string.
 * @param sort Sort method.
 * @return Sorting criteria in StringBuilder.
 */
public static StringBuilder addSorting(StringBuilder sql, Sort sort) {
    if (sort != null && sort != Sort.unsorted()) {
        sql.append(" ORDER BY ");

        for (Sort.Order order : sort) {
            sql.append(order.getProperty()).append(" ").append(order.getDirection());

            if (order.getNullHandling() != Sort.NullHandling.NATIVE) {
                sql.append(" ").append("NULL ");

                switch (order.getNullHandling()) {
                    case NULLS_FIRST:
                        sql.append("FIRST");
                        break;
                    case NULLS_LAST:
                        sql.append("LAST");
                        break;
                    default:
                }
            }
            sql.append(", ");
        }

        sql.delete(sql.length() - 2, sql.length());
    }

    return sql;
}
 
Example 9
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 10
Source File: BaseController.java    From mblog with GNU General Public License v3.0 5 votes vote down vote up
protected PageRequest wrapPageable(Sort sort) {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    int pageSize = ServletRequestUtils.getIntParameter(request, "pageSize", 10);
    int pageNo = ServletRequestUtils.getIntParameter(request, "pageNo", 1);

    if (null == sort) {
        sort = Sort.unsorted();
    }
    return PageRequest.of(pageNo - 1, pageSize, sort);
}
 
Example 11
Source File: CodelessDaoProxy.java    From sca-best-practice with Apache License 2.0 4 votes vote down vote up
protected <T> TypedQuery<T> getQuery(Class<T> clazz, @Nullable Specification<T> spec, Pageable pageable) {

        Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
        return getQuery(clazz, spec, sort);
    }
 
Example 12
Source File: SortAdapter.java    From graphql-spqr-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public Object getDefaultValue() {
    return Sort.unsorted();
}
 
Example 13
Source File: CosmosPageRequest.java    From spring-data-cosmosdb with MIT License 4 votes vote down vote up
public CosmosPageRequest(int page, int size, String requestContinuation) {
    super(page, size, Sort.unsorted());
    this.requestContinuation = requestContinuation;
}
 
Example 14
Source File: CosmosPageRequest.java    From spring-data-cosmosdb with MIT License 4 votes vote down vote up
private CosmosPageRequest(long offset, int page, int size, String requestContinuation) {
    super(page, size, Sort.unsorted());
    this.offset = offset;
    this.requestContinuation = requestContinuation;
}
 
Example 15
Source File: OffsetBasedPageRequest.java    From hawkbit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a new {@link OffsetBasedPageRequest}. Offsets are zero indexed,
 * thus providing 0 for {@code offset} will return the first entry.
 * 
 * @param offset
 *            zero-based offset index.
 * @param limit
 *            the limit of the page to be returned.
 */
public OffsetBasedPageRequest(final long offset, final int limit) {
    this(offset, limit, Sort.unsorted());
}