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


Java Pageable.getSort方法代码示例

本文整理汇总了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));
}
 
开发者ID:ATLANTBH,项目名称:owl,代码行数:33,代码来源:ServicesUtils.java

示例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()))
            );
        }
    }
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:27,代码来源:CustomSearchRepositoryImpl.java

示例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);
    }
}
 
开发者ID:ElderByte-,项目名称:spring-cloud-starter-bootstrap,代码行数:18,代码来源:PageableQueryEncoder.java

示例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);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:21,代码来源:LinqImpl.java

示例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());
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:10,代码来源:Oracle9SqlGenerator.java

示例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());
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:11,代码来源:DefaultSqlGenerator.java

示例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);
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:15,代码来源:InfinispanRemoteQueryAdapter.java

示例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());
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:12,代码来源:AbstractQueryAdapter.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:40,代码来源:AbstractRdbmsKeyValueRepository.java

示例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);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:35,代码来源:JpaUtil.java

示例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);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:31,代码来源:LinqImpl.java

示例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());
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:8,代码来源:SQL2008SqlGenerator.java

示例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);
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:5,代码来源:PermittedRepository.java


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