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