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


Java CriteriaQuery.orderBy方法代码示例

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


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

示例1: applyOrder

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Apply ordering criteria.
 */
private <T> void applyOrder(final UiPageRequest uiPageRequest, final Map<String, String> mapping, final CriteriaBuilder builder,
		final CriteriaQuery<T> query, final Root<T> root) {
	// Apply the sort
	if (uiPageRequest.getUiSort() != null) {

		// Need to order the result
		final UiSort uiSort = uiPageRequest.getUiSort();
		final String ormColumn = mapping.get(uiSort.getColumn());
		if (ormColumn != null) {

			// ORM column is validated
			final Sort sort = new Sort(uiSort.getDirection(), mapping.get(uiSort.getColumn()));
			query.orderBy(QueryUtils.toOrders(sort, root, builder));
		}
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:20,代码来源:PaginationDao.java

示例2: createQueryWrapper

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public static <T> QueryWrapper createQueryWrapper(final BaseQueryForm form) {
	return  (Root<?> root, CriteriaQuery<?> query, CriteriaBuilder cb, boolean sort)-> {
			List<Predicate> predicates = new ArrayList<>();
			addSearch(form, predicates, root, cb);
			addAndFields(form, predicates, root, cb);
			//加入或条件
			addOrFields(form, predicates, root, cb);
			Predicate[] array = new Predicate[predicates.size()];
			predicates.toArray(array);
			query.where(array);
			// 加入排序
			if (sort) {
				List<Order> orders = getOrdes(form, root);
				query.orderBy(orders);
			}

	};
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:19,代码来源:QueryFormHelper.java

示例3: createSpecification

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public static <T> Specification<T> createSpecification(final PaginationForm form) {
	return (Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb)-> {
			List<Predicate> predicates = new ArrayList<>();
			//加入搜索条件
			addSearch(form, predicates, root, cb);

			//加入与条件

			addAndFields(form, predicates, root, cb);
			//加入或条件
			addOrFields(form, predicates, root, cb);
			Predicate[] array = new Predicate[predicates.size()];
			predicates.toArray(array);
			query.where(array);
			// 加入排序
			List<Order> orders = getOrdes(form, root);
			query.orderBy(orders);
			return null;

	};
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:22,代码来源:QueryFormHelper.java

示例4: findByDateRange

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public Collection<EndPointCheck> findByDateRange(final EndPoint endPoint, final Date startDate,
        final Date endDate) {
    final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
    final CriteriaQuery<EndPointCheck> criteriaQuery = criteriaBuilder.createQuery(getEntityClass());
    final Root<EndPointCheck> root = criteriaQuery
            .from(getEntityManager().getMetamodel().entity(getEntityClass()));

    final ParameterExpression<EndPoint> endPointParameter = criteriaBuilder.parameter(EndPoint.class);
    final ParameterExpression<Date> startDateParameter = criteriaBuilder.parameter(Date.class);
    final ParameterExpression<Date> endDateParameter = criteriaBuilder.parameter(Date.class);

    final Predicate endPointIdPredicate = criteriaBuilder
            .equal(root.get("endPoint"), endPointParameter);

    final Path<Date> checkDatePath = root.<Date> get("checkDate");

    final Predicate startDatePredicate = criteriaBuilder
            .greaterThanOrEqualTo(checkDatePath, startDateParameter);

    final Predicate endDatePredicate = criteriaBuilder.lessThanOrEqualTo(
        checkDatePath,
        endDateParameter);

    criteriaQuery.where(criteriaBuilder.and(endPointIdPredicate, startDatePredicate, endDatePredicate));

    criteriaQuery.orderBy(Arrays.asList(criteriaBuilder.asc(checkDatePath)));

    return getEntityManager().createQuery(criteriaQuery)
            .setParameter(endPointParameter, endPoint)
            .setParameter(startDateParameter, startDate, TemporalType.DATE)
            .setParameter(endDateParameter, endDate, TemporalType.DATE)
            .getResultList();
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:34,代码来源:EndPointCheckDao.java

示例5: listAll

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<T> listAll(boolean asc, String... orderby) {
    CriteriaBuilder cb = this.em.getCriteriaBuilder();

    CriteriaQuery<T> query = cb.createQuery(this.clazz);
    Root<T> from = query.from(this.clazz);
    query = query.select(from).distinct(true);

    if (orderby != null) {
        query = query.orderBy(Arrays.stream(orderby)
                .map(f -> from.get(f))
                .map(e -> asc ? cb.asc(e) : cb.desc(e))
                .toArray(i -> new Order[i]));
    }
    List<T> ls = this.em.createQuery(query).getResultList();
    return ls;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:OSCEntityManager.java

示例6: findByParentId

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Find list of children entities by their parent Id
 *
 * @param parentEntityName
 *            The parent entity name by which id will be queried.
 * @param parentId
 *            Parent entity identifier for which children are queried.
 * @return List of children owned by parent entity
 */
public List<T> findByParentId(String parentEntityName, Long parentId, String... orderby) {

    CriteriaBuilder cb = this.em.getCriteriaBuilder();

    CriteriaQuery<T> query = cb.createQuery(this.clazz);

    Root<T> root = query.from(this.clazz);
    query = query.select(root)
            .distinct(true)
            .where(
            cb.equal(root.join(parentEntityName).get("id"), parentId));

    if (orderby != null) {
        query = query.orderBy(Arrays.stream(orderby)
                .map(f -> cb.asc(root.get(f)))
                .toArray(i -> new Order[i]));
    }

    List<T> list = this.em.createQuery(query).getResultList();

    return list;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:32,代码来源:OSCEntityManager.java

示例7: getResults

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Obtem lista com os resultados
 * @return Lista de resultados
 */
public List<T> getResults() {
    CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(entityClass);
    Root<T> root                   = criteriaQuery.from(entityClass);
    setupQuery(criteriaQuery, root);

    // ORDER BY
    if ( ! orders.isEmpty() ) {
        ArrayList<Order> jpaOrders = new ArrayList<>();
        for (OrderEntry orderField : orders) {
            if ( orderField.order.equals(OrderDirection.ASC) ) {
                jpaOrders.add( criteriaBuilder.asc(getPath(orderField.fieldNames, root)));
            } else {
                jpaOrders.add( criteriaBuilder.desc(getPath(orderField.fieldNames, root)));
            }
        }
        criteriaQuery.orderBy( jpaOrders );
    }

    if ( pageNumber != null ) {
        return em.createQuery(criteriaQuery).setFirstResult( (pageNumber - 1) * pageSize ).setMaxResults(pageSize)
                        .getResultList();
    } else {
        return em.createQuery(criteriaQuery).getResultList();
    }
}
 
开发者ID:jhonystein,项目名称:Pedidex,代码行数:30,代码来源:JpaCriteriaHelper.java

示例8: readPage

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Returns a page of objects.
 *
 * @param entityClass The entity class.
 * @param page The page index (zero indexed).
 * @param pageSize The page size.
 * @return A page of objects.
 */
@Override
public <T extends BaseEntity> List<T> readPage(
        final Class<T> entityClass,
        final int page,
        final int pageSize) {

    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<T> cq = cb.createQuery(entityClass);
    final Root<T> root = cq.from(entityClass);
    cq.select(root);
    cq.orderBy(cb.desc(root.get("id")));
    return em.createQuery(cq)
            .setFirstResult(page * pageSize)
            .setMaxResults(pageSize)
            .getResultList();
}
 
开发者ID:minijax,项目名称:minijax,代码行数:25,代码来源:DefaultBaseDao.java

示例9: findAll

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的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

示例10: findByProperty

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<T> findByProperty(String name, Object value, String orderBy) {
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<T> query = cb.createQuery(entityClass);
	Root<T> root = query.from(entityClass);
	query.where(cb.equal(QueryFormHelper.getPath(root, name), value));
	if (!StringUtils.isEmpty(orderBy)) {
		List<Order> orders = QueryFormHelper.getOrdes(orderBy, root);
		query.orderBy(orders);
	}
	TypedQuery<T> typedQuery = em.createQuery(query);
	return typedQuery.getResultList();
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:13,代码来源:BaseDao.java

示例11: buscarTodos

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public List<T> buscarTodos() {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
    Root<T> root = cq.from(entityClass);
    cq.select(cb.construct(entityClass));
    cq.orderBy(cb.desc(root.get("id")));
    return entityManager.createQuery(cq).getResultList();
}
 
开发者ID:JDanielT,项目名称:search-doc,代码行数:10,代码来源:DAOGenerico.java

示例12: buscarComLimite

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<T> buscarComLimite(int paginaAtual, int tamanhoPagina) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<T> cq = cb.createQuery(entityClass);
    Root<T> root = cq.from(entityClass);
    cq.select(root);
    cq.orderBy(cb.desc(root.get("id")));
    TypedQuery typedQuery = entityManager.createQuery(cq);
    typedQuery.setFirstResult(paginaAtual);
    typedQuery.setMaxResults(tamanhoPagina);
    return typedQuery.getResultList();
}
 
开发者ID:JDanielT,项目名称:search-doc,代码行数:12,代码来源:DAOGenerico.java

示例13: setOrdering

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private void setOrdering(OperationFilter operationFilter, CriteriaBuilder criteriaBuilder, CriteriaQuery<OperationDto> query,
    Root<OperationDto> root) {
    if (operationFilter.getOrderDirection() == OrderDirection.ASCENDING) {
        query.orderBy(criteriaBuilder.asc(root.get(operationFilter.getOrderAttribute())));
    } else {
        query.orderBy(criteriaBuilder.desc(root.get(operationFilter.getOrderAttribute())));
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:9,代码来源:OperationDtoDao.java

示例14: list

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public synchronized <T> ListResponse<T> list(ListRequest<T> p_request) {		 		 	

  	CriteriaBuilder builder = em().getCriteriaBuilder();

  	CriteriaQuery<T> search = builder.createQuery(p_request.getType());		
CriteriaQuery<Long> count = builder.createQuery(Long.class);

Root<T> root = search.from(p_request.getType());			
		
count.select(builder.count(root));
count.from(p_request.getType());

search.select(root);								

Predicate or_predicate = getFilterPredicate(builder::or, root, builder, p_request.getORFilter());
Predicate and_predicate = getFilterPredicate(builder::and, root, builder, p_request.getANDFilter());	
Predicate member_predicate = getIsMemberOfPredicate(root, builder, p_request.getMemberFilter());
Predicate filter_predicate = null;							

if (and_predicate != null && or_predicate != null)
	filter_predicate = builder.and(and_predicate, or_predicate);
else if (and_predicate != null)
	filter_predicate = and_predicate;
else if (or_predicate != null)
	filter_predicate = or_predicate;	
if (member_predicate != null) {
	if  (filter_predicate != null)
		filter_predicate = builder.and(filter_predicate, member_predicate);
	else
		filter_predicate = member_predicate;					
}


if (filter_predicate != null) {
	search.where(filter_predicate);
	count.where(filter_predicate);
}					

List<Order> order = getSort(root,  builder,  p_request.getSort());

if (order.size() > 0) {
	search.orderBy(order);
}
	

List<T> results = em().createQuery(search)
	.setHint("org.hibernate.cacheable", p_request.getCachable())
	.setFirstResult(p_request.getFirst())
	.setMaxResults(p_request.getMax())				
	.getResultList();					

Long total = em().createQuery(count)
				.setHint("org.hibernate.cacheable", p_request.getCachable())
				.getSingleResult();					
						
done();

return new ListResponse<T>(results, p_request.getFirst(), p_request.getMax(), total.intValue());
  }
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:60,代码来源:ServiceFacade.java

示例15: findAllImpl1

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
  private <R> List<R> findAllImpl1(final DatatableQuery<R, T> input, final Specifications<T> specifications,
      final Pageable pageable) {

      // create query
  	final EntityManager entityManager = entityManagerFactory.createEntityManager();
      final CriteriaBuilder qb = entityManager.getCriteriaBuilder();
      final CriteriaQuery<T> cq = qb.createQuery(this.entity);

      // Etablir entité racine
      final Root<T> from = cq.from(this.entity);

      // select
      cq.select(from);

      // where
      if (specifications != null) {
          cq.where(specifications.toPredicate(from, cq, qb));
      }

      // group by
      if (input.getGroupByColumns() != null && !input.getGroupByColumns().isEmpty()) {
          final List<Expression<?>> groupByList = new ArrayList<Expression<?>>();
          DatatableHelper.getExpressions(from, input.getGroupByColumns(), groupByList);
          cq.groupBy(groupByList);
      }

      // order by
      if (pageable != null && pageable.getSort() != null) {
          cq.orderBy(DatatableHelper.getOrderBy(from, qb, pageable));
      }

      // page limit
      final TypedQuery<T> q = entityManager.createQuery(cq);
      if (pageable != null) {
          q.setFirstResult(pageable.getOffset());
          q.setMaxResults(pageable.getPageSize());
      }

      // execute query
      final List<R> ret = (List<R>) q.getResultList();
      entityManager.close();
return ret;
  }
 
开发者ID:andresoviedo,项目名称:datatable-java,代码行数:45,代码来源:DatatableDAOImpl.java


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