當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。