当前位置: 首页>>代码示例>>Java>>正文


Java Sort.Order方法代码示例

本文整理汇总了Java中org.springframework.data.domain.Sort.Order方法的典型用法代码示例。如果您正苦于以下问题:Java Sort.Order方法的具体用法?Java Sort.Order怎么用?Java Sort.Order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.domain.Sort的用法示例。


在下文中一共展示了Sort.Order方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSort

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
private Collection<SortField<?>> buildSort(final Sort sortSpecification){
    Collection<SortField<?>> querySortFields = new ArrayList<>(10);

    if (sortSpecification == null) {
        // What is the default sorting?
        // Consistent way to write it in all app?
        return querySortFields;
    }

    List<String> usedSortKey = new ArrayList<>(10);

    for (final Sort.Order specifiedField : sortSpecification) {
        String sortFieldName = specifiedField.getProperty();
        Sort.Direction sortDirection = specifiedField.getDirection();

        if (usedSortKey.contains(sortFieldName))
            throw new IllegalArgumentException("Well how should it be handled? And should be same for all app to be consistent");

        querySortFields.add(getSortedField(sortFieldName, sortDirection));
        usedSortKey.add(sortFieldName);
    }
    return querySortFields;
}
 
开发者ID:Blackdread,项目名称:filter-sort-jooq-api,代码行数:24,代码来源:TransferTimingPageRepositoryImplPureJooq.java

示例2: applyOrder

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
private static String applyOrder(String sql, Sort sort) {
    StringBuilder builder = new StringBuilder(sql);

    if (sort != null) {
        builder.append(ORDER_BY_SQL);
        String sep = "";
        for (Sort.Order order : sort) {
            builder.append(sep)
                .append(order.getProperty())
                .append(" ")
                .append(order.getDirection());
            sep = ", ";
        }
    }

    return builder.toString();
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:18,代码来源:PermittedRepository.java

示例3: pageRequestProtoToPageRequest

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
public static org.springframework.data.domain.PageRequest pageRequestProtoToPageRequest(PageRequest pageRequestProto) {
    if (pageRequestProto == null) {
        return null;
    }
    int page = pageRequestProto.getPage();
    int pageSize = pageRequestProto.getSize();

    // Limit lower bound
    pageSize = pageSize < 1 ? DEFAULT_PAGE_REQUEST.getPageSize() : pageSize;
    // Limit upper bound
    pageSize = pageSize > DEFAULT_MAX_PAGE_SIZE ? DEFAULT_MAX_PAGE_SIZE : pageSize;

    List<Sort.Order> orders = pageRequestProto.getOrdersList().stream()
        .map( o -> new Sort.Order(Sort.Direction.fromString(o.getDirection().toString()), o.getProperty()))
        .collect(Collectors.toList());
    Sort sort = orders.isEmpty() ? null : new Sort(orders);

    return new org.springframework.data.domain.PageRequest(page, pageSize, sort);
}
 
开发者ID:cbornet,项目名称:generator-jhipster-grpc,代码行数:20,代码来源:_ProtobufMappers.java

示例4: getReplyByPage

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
public Page<Reply> getReplyByPage(Integer postsId, int pageNo, int length) {
    Sort.Order order = new Sort.Order(Sort.Direction.ASC, "id");
    Sort sort = new Sort(order);
    PageRequest pageable = new PageRequest(pageNo, length, sort);

    Specification<Reply> specification = new Specification<Reply>() {

        @Override
        public Predicate toPredicate(Root<Reply> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
            Path<Integer> $posts = root.get("posts");
            Predicate predicate = criteriaBuilder.and(criteriaBuilder.equal($posts, postsId));
            return predicate;
        }
    };
    Page<Reply> page = repository.findAll(specification, pageable);
    return page;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:19,代码来源:ReplyServiceImpl.java

示例5: fetchFromBackEnd

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
protected Stream<T> fetchFromBackEnd(Query<T, ExampleFilter<T>> query) {
    int page = query.getOffset() / query.getLimit();

    List<Sort.Order> sortOrders = query.getSortOrders().stream()
                                       .map(sortOrder -> new Sort.Order(sortOrder.getDirection() == SortDirection.ASCENDING ? Sort.Direction.ASC
                                                                                                                            : Sort.Direction.DESC,
                                                                        sortOrder.getSorted()))
                                       .collect(Collectors.toList());

    PageRequest pageRequest = new PageRequest(page, query.getLimit(), sortOrders.isEmpty() ? null : new Sort(sortOrders));
    List<T> items = null;
    if (query.getFilter().isPresent()) {
        items = repository.findAll(query.getFilter().get().example, pageRequest).getContent();
    }
    else {
        items = repository.findAll(pageRequest).getContent();
    }
    return items.subList(query.getOffset() % query.getLimit(), items.size()).stream(); // TODO: comment why this is done
}
 
开发者ID:waschmittel,项目名称:springentityprovider,代码行数:21,代码来源:SpringEntityProvider.java

示例6: buildOrderBy

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
/**
 * TODO Change to List for return value
 *
 * @param sortSpecification Sort from Spring Data
 * @return Collection of fields to sort (can be empty if {@code sortSpecification} is null or no sort values)
 * @throws SortingApiException if any sort field given cannot be found (it should result in a 400 error message) or sort contains duplicate keys
 */
@NotNull
default Collection<SortField<?>> buildOrderBy(@Nullable final Sort sortSpecification) {
    Collection<SortField<?>> querySortFields = new ArrayList<>(10);

    if (sortSpecification == null) {
        return getDefaultSorting();
    }

    List<String> usedSortKey = new ArrayList<>(10);

    for (final Sort.Order specifiedField : sortSpecification) {
        String sortFieldName = specifiedField.getProperty();
        Sort.Direction sortDirection = specifiedField.getDirection();

        if (usedSortKey.contains(sortFieldName))
            throw new SortingApiException("Cannot sort on duplicate keys");

        SortValue sortValue = getTableField(sortFieldName);
        SortField<?> querySortField = convertTableFieldToSortField(sortValue, sortDirection);
        querySortFields.add(querySortField);
        usedSortKey.add(sortFieldName);
    }

    return querySortFields;
}
 
开发者ID:Blackdread,项目名称:filter-sort-jooq-api,代码行数:33,代码来源:SortingJooq.java

示例7: generateSort

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
/**
 * 调用的时候使用SimpleSortBuilder.generateSort("name","xh_d");表示先以name升序,之后以xh降序
 */
public static Sort generateSort(String... fields) {
    List<Sort.Order> orders = new ArrayList<Sort.Order>();
    for(String f:fields) {
        orders.add(generateOrder(f));
    }
    return new Sort(orders);
}
 
开发者ID:realxujiang,项目名称:itweet-boot,代码行数:11,代码来源:SimpleSortBuilder.java

示例8: getPostsByPage

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
public Page<Posts> getPostsByPage(String type, String search, int pageNo, int length) {
    List<Sort.Order> orders = new ArrayList<>();
    orders.add(new Sort.Order(Sort.Direction.DESC, "top"));
    orders.add(new Sort.Order(Sort.Direction.DESC, "id"));


    Sort sort = new Sort(orders);
    PageRequest pageable = new PageRequest(pageNo, length, sort);

    Specification<Posts> specification = new Specification<Posts>() {
        @Override
        public Predicate toPredicate(Root<Posts> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
            Path<Boolean> $top = root.get("top");
            Path<Boolean> $good = root.get("good");
            Path<String> $title = root.get("title");
            ArrayList<Predicate> list = new ArrayList<>();
            if (type != null && type.equals("good")) list.add(criteriaBuilder.equal($good, true));
            if (type != null && type.equals("top")) list.add(criteriaBuilder.equal($top, true));
            if (search != null && search != "") list.add(criteriaBuilder.like($title, "%" + search + "%"));

            Predicate predicate = criteriaBuilder.and(list.toArray(new Predicate[list.size()]));
            return predicate;
        }
    };
    Page<Posts> page = repository.findAll(specification, pageable);

    return page;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:30,代码来源:PostsServiceImpl.java

示例9: findByPage

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
public Page<Permission> findByPage(int pageNo, int length) {
    Sort.Order order = new Sort.Order(Sort.Direction.ASC, "sort");
    Sort sort = new Sort(order);
    PageRequest pageRequest = new PageRequest(pageNo, length,sort);
    Page<Permission> page = repository.findAll(pageRequest);
    return page;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:9,代码来源:PermissionServiceImpl.java

示例10: convertToEbeanOrderBy

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
/**
 * Convert spring data Sort to Ebean OrderBy.
 *
 * @param sort
 * @param <T>
 * @return
 */
public static <T> OrderBy<T> convertToEbeanOrderBy(Sort sort) {
  if (sort == null) {
    return null;
  }
  List<String> list = new ArrayList<>();
  while (sort.iterator().hasNext()) {
    Sort.Order so = sort.iterator().next();
    list.add(so.getDirection() == Sort.Direction.ASC ? so.getProperty() + " asc" : so.getProperty() + " desc");
  }
  return new OrderBy<T>(StringUtils.collectionToCommaDelimitedString(list));
}
 
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:19,代码来源:Converters.java

示例11: queryForPageableResults

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
private Page<D> queryForPageableResults(Pageable pageable, String selectClause, String tableName,
		String whereClause, Object[] queryParam, long totalCount) {
	//FIXME Possible performance improvement refactoring so factory isn't called every time.
	SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
	factoryBean.setSelectClause(selectClause);
	factoryBean.setFromClause(tableName);
	if (StringUtils.hasText(whereClause)) {
		factoryBean.setWhereClause(whereClause);
	}

	final Sort sort = pageable.getSort();
	final LinkedHashMap<String, Order> sortOrderMap = new LinkedHashMap<>();

	if (sort != null) {
		for (Sort.Order sortOrder : sort) {
			sortOrderMap.put(sortOrder.getProperty(), sortOrder.isAscending() ? Order.ASCENDING : Order.DESCENDING);
		}
	}

	if (!CollectionUtils.isEmpty(sortOrderMap)) {
		factoryBean.setSortKeys(sortOrderMap);
	}
	else {
		factoryBean.setSortKeys(this.orderMap);
	}

	factoryBean.setDataSource(this.dataSource);
	PagingQueryProvider pagingQueryProvider;
	try {
		pagingQueryProvider = factoryBean.getObject();
		pagingQueryProvider.init(this.dataSource);
	}
	catch (Exception e) {
		throw new IllegalStateException(e);
	}
	String query = pagingQueryProvider.getPageQuery(pageable);
	List<D> resultList = jdbcTemplate.query(query, queryParam, rowMapper);
	return new PageImpl<>(resultList, pageable, totalCount);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:40,代码来源:AbstractRdbmsKeyValueRepository.java

示例12: findAuthorityByPageAndOrder

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
public Page<Authority> findAuthorityByPageAndOrder(Integer starPage, Integer itemNumber) {
    List<Sort.Order> orders = new ArrayList<>();
    // orders.add(new Sort.Order(Sort.Direction.DESC,"name"));
    orders.add(new Sort.Order(Sort.Direction.DESC,"id"));
    //  orders.add(new Sort.Order(Sort.Direction.ASC,"parentId"));
    PageRequest pageRequest = new PageRequest(starPage,itemNumber,new Sort(orders));
    return authorityRepository.findAll(pageRequest);
}
 
开发者ID:mmdsyl,项目名称:BLOG-Microservice,代码行数:10,代码来源:AuthorityServiceImpl.java

示例13: findUserByPageAndOrder

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
@Override
public Page<User> findUserByPageAndOrder(Integer starPage, Integer itemNumber) {
    List<Sort.Order> orders = new ArrayList<>();
    // orders.add(new Sort.Order(Sort.Direction.DESC,"name"));
    orders.add(new Sort.Order(Sort.Direction.DESC,"id"));
    //  orders.add(new Sort.Order(Sort.Direction.ASC,"parentId"));
    PageRequest pageRequest = new PageRequest(starPage,itemNumber,new Sort(orders));
    return userRepository.findAll(pageRequest);
}
 
开发者ID:mmdsyl,项目名称:BLOG-Microservice,代码行数:10,代码来源:UserServiceImpl.java

示例14: applySort

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
private void applySort(RequestTemplate template, Sort sort){
    Collection<String> existingSorts = template.queries().get("sort");
    List<String> sortQueries  = existingSorts != null ? new ArrayList<>(existingSorts) : new ArrayList<>();
    for (Sort.Order order : sort) {
        sortQueries.add(order.getProperty() + "," + order.getDirection());
    }
    if(!sortQueries.isEmpty()){
        template.query("sort", sortQueries);
    }
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:11,代码来源:PageableQueryEncoder.java

示例15: orderBy

import org.springframework.data.domain.Sort; //导入方法依赖的package包/类
/**
 * Add sorting from a Spring Data Pageable
 * @param pageable
 * @return
 */
public YadaSql orderBy(Pageable pageable) {
	Iterator<Sort.Order> orders = pageable.getSort().iterator();
	while (orders.hasNext()) {
		Sort.Order order = orders.next();
		orderBy(order.getProperty() + " " + order.getDirection());
	}
	return this;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:14,代码来源:YadaSql.java


注:本文中的org.springframework.data.domain.Sort.Order方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。