本文整理匯總了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();
}
示例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);
}
示例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;
}
示例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
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}