本文整理汇总了Java中org.springframework.data.domain.Pageable.getSort方法的典型用法代码示例。如果您正苦于以下问题:Java Pageable.getSort方法的具体用法?Java Pageable.getSort怎么用?Java Pageable.getSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.domain.Pageable
的用法示例。
在下文中一共展示了Pageable.getSort方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPageRequest
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
/**
* Create pageable request with default sort.
*
* @param page Page.
* @param defaultSort Default sort object.
* @param caseSensitiveSortProperties List of case sensitive properties or {@link #CASE_SENSITIVE_PROPERTIES} for
* all properties to be case sensitive.
* @return Page object.
*/
public static PageRequest createPageRequest(Pageable page, Sort defaultSort,
Collection<String> caseSensitiveSortProperties) {
Sort sort = page.getSort();
sort = sort == null ? defaultSort : sort.and(defaultSort);
List<Sort.Order> ignoreCaseOrderList = Collections.emptyList();
if (sort != null) {
ignoreCaseOrderList = StreamUtils.createStreamFromIterator(sort.iterator())
.map(order -> {
if (caseSensitiveSortProperties == CASE_SENSITIVE_PROPERTIES ||
caseSensitiveSortProperties.contains(order.getProperty())) {
return order.ignoreCase();
}
return order;
})
.collect(Collectors.toList());
}
if (ignoreCaseOrderList.isEmpty()) {
return new PageRequest(page.getPageNumber(), page.getPageSize());
}
return new PageRequest(page.getPageNumber(), page.getPageSize(), new Sort(ignoreCaseOrderList));
}
示例2: addPagingAndSortingToSearchRequest
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
/**
* add the sort order to the request searchRequestBuilder
* if the frontend send sort with "path : desc". It should be converted to "path.raw" : {"order" : "desc" }
* https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html#multi-fields
*
* @param pageable
* @param searchRequestBuilder
*/
private void addPagingAndSortingToSearchRequest(Pageable pageable, SearchRequestBuilder searchRequestBuilder) {
//par défaut, renvoi la première page trié sur le _score ou le _doc, si rien n'est spécifié
//effectue le tri
if (pageable != null) {
searchRequestBuilder
.setFrom(pageable.getOffset())
.setSize(pageable.getPageSize());
if (pageable.getSort() != null) {
pageable.getSort().forEach(
order -> searchRequestBuilder.addSort(
Constants.ORDER_FIELD_MAPPING.get(order.getProperty()),
SortOrder.valueOf(order.getDirection().name()))
);
}
}
}
示例3: encode
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if(object instanceof Pageable) {
Pageable pageable = (Pageable) object;
template.query("page", pageable.getPageNumber() + "");
template.query("size", pageable.getPageSize() + "");
if (pageable.getSort() != null) {
applySort(template, pageable.getSort());
}
}else if(object instanceof Sort){
Sort sort = (Sort)object;
applySort(template, sort);
}else{
delegate.encode(object, bodyType, template);
}
}
示例4: list
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public <T> List<T> list(Pageable pageable) {
if (parent != null) {
applyPredicateToCriteria(sq);
return parent.list(pageable);
}
if (pageable == null) {
return list();
} else {
Sort sort = pageable.getSort();
orders.addAll(QueryUtils.toOrders(sort, root, cb));
applyPredicateToCriteria(criteria);
TypedQuery<?> query = em.createQuery(criteria);
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
return transform(query, false);
}
}
示例5: selectAll
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public String selectAll(TableDescription table, String whereClause, Pageable page) {
Sort sort = page.getSort() != null ? page.getSort() : sortById(table);
return format("SELECT t2__.* FROM ( "
+ "SELECT t1__.*, ROWNUM as rn__ FROM ( %s ) t1__ "
+ ") t2__ WHERE t2__.rn__ > %d AND ROWNUM <= %d",
selectAll(table, whereClause, sort), page.getOffset(), page.getPageSize());
}
示例6: selectAll
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
public String selectAll(TableDescription table, String whereClause, Pageable page) {
Sort sort = page.getSort() != null ? page.getSort() : sortById(table);
return format(
"SELECT t2__.* FROM ( "
+ "SELECT row_number() OVER (ORDER BY %s) AS rn__, t1__.* FROM ( %s ) t1__ "
+ ") t2__ WHERE t2__.rn__ BETWEEN %s AND %s",
orderByExpression(sort), selectAll(table, whereClause), page.getOffset() + 1,
page.getOffset() + page.getPageSize());
}
示例7: applyQuery
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
protected void applyQuery(me.snowdrop.data.core.spi.Query<T> query) {
// we need to sort before creating query
Sort sort = query.getSort();
if (sort == null || sort.isUnsorted()) {
Pageable pageable = query.getPageable();
if (pageable != null && pageable.isPaged()) {
sort = pageable.getSort();
}
}
if (sort != null && sort.isSorted()) {
queryHelper.convert(sort);
}
}
示例8: addPagingToQuery
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
protected void addPagingToQuery(me.snowdrop.data.core.spi.Query<T> query) {
Pageable pageable = query.getPageable();
if (pageable != null && pageable.isPaged()) {
org.springframework.data.domain.Sort sort = pageable.getSort();
if (query.getSort() == null && sort.isSorted()) {
addSortToQuery(sort);
}
setFirstResult(pageable.getOffset());
setMaxResults(pageable.getPageSize());
}
}
示例9: queryForPageableResults
import org.springframework.data.domain.Pageable; //导入方法依赖的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);
}
示例10: findAll
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
/**
* 分页条件查询
* @param cq 条件
* @param pageable 分页信息
* @param <T> 领域类(实体类)范型
* @return 分页结果
*/
public static <T> Page<T> findAll(CriteriaQuery<T> cq, Pageable pageable) {
Class<T> domainClass = cq.getResultType();
Root<T> root;
if (CollectionUtils.isEmpty(cq.getRoots())) {
root = cq.from(domainClass);
} else {
root = (Root<T>) cq.getRoots().iterator().next();
}
EntityManager em = getEntityManager(domainClass);
if (pageable == null) {
List<T> list = findAll(cq);
return new PageImpl<T>(list);
} else {
Sort sort = pageable.getSort();
cq.orderBy(QueryUtils.toOrders(sort, root, em.getCriteriaBuilder()));
TypedQuery<T> query = em.createQuery(cq);
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
Long total = count(cq);
List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T> emptyList();
return new PageImpl<T>(content, pageable, total);
}
}
示例11: paging
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public <T> Page<T> paging(Pageable pageable) {
if (parent != null) {
applyPredicateToCriteria(sq);
return parent.paging(pageable);
}
List<T> list;
if (pageable == null) {
list = list();
return new PageImpl<T>(list);
} else {
Sort sort = pageable.getSort();
if (sort != null) {
orders.addAll(QueryUtils.toOrders(sort, root, cb));
}
applyPredicateToCriteria(criteria);
TypedQuery<?> query = em.createQuery(criteria);
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
Long total = JpaUtil.count(criteria);
List<T> content = Collections.<T> emptyList();
if (total > pageable.getOffset()) {
content = transform(query, false);
}
return new PageImpl<T>(content, pageable, total);
}
}
示例12: selectAll
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public String selectAll(TableDescription table, String whereClause, Pageable page) {
Sort sort = page.getSort() != null ? page.getSort() : sortById(table);
return format("%s OFFSET %d ROWS FETCH NEXT %d ROW ONLY",
selectAll(table, whereClause, sort), page.getOffset(), page.getPageSize());
}
示例13: createSelectQuery
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
protected <T> TypedQuery<T> createSelectQuery(String selectSql, Pageable pageable, Class<T> entityClass) {
Sort sort = pageable == null ? null : pageable.getSort();
return em.createQuery(applyOrder(selectSql, sort), entityClass);
}