當前位置: 首頁>>代碼示例>>Java>>正文


Java Order類代碼示例

本文整理匯總了Java中javax.persistence.criteria.Order的典型用法代碼示例。如果您正苦於以下問題:Java Order類的具體用法?Java Order怎麽用?Java Order使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Order類屬於javax.persistence.criteria包,在下文中一共展示了Order類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createQueryWrapper

import javax.persistence.criteria.Order; //導入依賴的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

示例2: createSpecification

import javax.persistence.criteria.Order; //導入依賴的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

示例3: getOrdes

import javax.persistence.criteria.Order; //導入依賴的package包/類
/**
 * 加入排序依據
 */
private static <T> List<Order> getOrdes(BaseQueryForm form, Root<T> root) {
	String orderBy = form.getOrderMapping();
	if (StringUtils.isEmpty(orderBy)) {
		return Collections.emptyList();
	}
	String[] groups = orderBy.trim().split(",");
	List<Order> orders = new ArrayList<>(groups.length);
	for (String group : groups) {
		boolean ascending = true;
		String[] array = group.split("\\s", 2);
		String field = array[0];
		if (array.length > 1) {
			ascending = "asc".equals(array[1].toLowerCase());
		}
		Order order = new OrderImpl(getPath(root, field), ascending);
		orders.add(order);
	}
	return orders;
}
 
開發者ID:szsucok,項目名稱:sucok-framework,代碼行數:23,代碼來源:QueryFormHelper.java

示例4: listAll

import javax.persistence.criteria.Order; //導入依賴的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

示例5: findByParentId

import javax.persistence.criteria.Order; //導入依賴的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

示例6: getSort

import javax.persistence.criteria.Order; //導入依賴的package包/類
private <T> List<Order> getSort(Root<T> p_root, CriteriaBuilder p_builder, Sort[] p_sort) {
	
	List<Order> order = new LinkedList<Order>();
	
	if (p_sort != null && p_sort.length > 0) {				
		
		for (Sort sort : p_sort) {
			Path<?> property_path = null;		
			
			for (String hop : sort.getPropertyPath()) {
				if (property_path == null)
					property_path = p_root.get(hop);
				else
					property_path = property_path.get(hop);
			}
			if (sort.getOrderAscending()) {
				order.add(p_builder.asc(property_path));
			} else {
				order.add(p_builder.desc(property_path));
			}
		}			
	}
	
	return order;
}
 
開發者ID:awslabs,項目名稱:aws-photosharing-example,代碼行數:26,代碼來源:ServiceFacade.java

示例7: getResults

import javax.persistence.criteria.Order; //導入依賴的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: getPageable

import javax.persistence.criteria.Order; //導入依賴的package包/類
/**
 * Creates a 'LIMIT .. OFFSET .. ORDER BY ..' clause for the given {@link DatatableQuery}.
 * 
 * @param input
 *            the {@link DatatableQuery} mapped from the Ajax request
 * @return a {@link Pageable}, must not be {@literal null}.
 */
static <T> Pageable getPageable(final DatatableQuery<?, T> input) {
    final List<org.andresoviedo.datatable.Sort.Order> orders =
        new ArrayList<org.andresoviedo.datatable.Sort.Order>();
    for (final DatatableOrder order : input.getOrder()) {
        final DatatableColumn column = input.getColumns().get(order.getColumn());
        if (column.getOrderable()) {
            final String sortColumn = column.getData();
            final Direction sortDirection = Direction.fromString(order.getDir());
            orders.add(new org.andresoviedo.datatable.Sort.Order(sortDirection, sortColumn));
        }
    }
    org.andresoviedo.datatable.Sort sort = null;
    if (!orders.isEmpty()) {
        sort = new org.andresoviedo.datatable.Sort(orders);
    }

    if (input.getLength() == -1) {
        input.setStart(0);
        input.setLength(Integer.MAX_VALUE);
    }
    return new DataTablePage(input.getStart(), input.getLength(), sort);
}
 
開發者ID:andresoviedo,項目名稱:datatable-java,代碼行數:30,代碼來源:DatatableHelper.java

示例9: addOrdering

import javax.persistence.criteria.Order; //導入依賴的package包/類
/**
 * Adds sorting by given parameter and order type (ascending or descending).
 * 
 * @param parameter
 *            parameter by which sorting will be performed
 * @param ascendingly
 *            defines whether (<code>true</code>) or not (<code>false</code>)sorting will be ascending
 */
protected void addOrdering(Expression<?> parameter, boolean ascendingly) {
    ensureInitializedOrders();
    Order order = getExistingOrderExpression(parameter);
    if (order != null) {
        boolean orderingDiffers = order.isAscending() ^ ascendingly;
        if (orderingDiffers) {
            order.reverse();
            return;
        }
    } else {
        if (ascendingly) {
            orders.add(criteriaBuilder.asc(parameter));
        } else {
            orders.add(criteriaBuilder.desc(parameter));
        }
    }
}
 
開發者ID:psnc-dl,項目名稱:darceo,代碼行數:26,代碼來源:GenericQuerySorterBuilderImpl.java

示例10: listEntity

import javax.persistence.criteria.Order; //導入依賴的package包/類
/**
 * @deprecated Utiliser QueryDSL
 */
@Deprecated
protected <T> List<T> listEntity(Class<T> objectClass, Expression<Boolean> filter, Integer limit, Integer offset, Order... orders) {
	CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
	CriteriaQuery<T> criteria = builder.createQuery(objectClass);
	rootCriteriaQuery(builder, criteria, objectClass);
	
	if (filter != null) {
		filterCriteriaQuery(criteria, filter);
	}
	if (orders != null && orders.length > 0) {
		criteria.orderBy(orders);
	}
	TypedQuery<T> query = buildTypedQuery(criteria, limit, offset);
	
	List<T> entities = query.getResultList();
	
	if (orders == null || orders.length == 0) {
		sort(entities);
	}
	
	return entities;
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:26,代碼來源:JpaDaoSupport.java

示例11: getUserNamespaceAuthorizationsByNamespace

import javax.persistence.criteria.Order; //導入依賴的package包/類
@Override
public List<UserNamespaceAuthorizationEntity> getUserNamespaceAuthorizationsByNamespace(String namespace)
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserNamespaceAuthorizationEntity> criteria = builder.createQuery(UserNamespaceAuthorizationEntity.class);

    // The criteria root is the user namespace authorization.
    Root<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntity = criteria.from(UserNamespaceAuthorizationEntity.class);

    // Join to the other tables we can filter on.
    Join<UserNamespaceAuthorizationEntity, NamespaceEntity> namespaceEntity =
        userNamespaceAuthorizationEntity.join(UserNamespaceAuthorizationEntity_.namespace);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespace.toUpperCase());

    // Order by user id.
    Order orderBy = builder.asc(userNamespaceAuthorizationEntity.get(UserNamespaceAuthorizationEntity_.userId));

    // Add all clauses for the query.
    criteria.select(userNamespaceAuthorizationEntity).where(queryRestriction).orderBy(orderBy);

    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:27,代碼來源:UserNamespaceAuthorizationDaoImpl.java

示例12: getTagTypes

import javax.persistence.criteria.Order; //導入依賴的package包/類
@Override
public List<TagTypeEntity> getTagTypes()
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TagTypeEntity> criteria = builder.createQuery(TagTypeEntity.class);

    // The criteria root is the tag type entity.
    Root<TagTypeEntity> tagTypeEntityRoot = criteria.from(TagTypeEntity.class);

    // Get the columns.
    Path<String> displayNameColumn = tagTypeEntityRoot.get(TagTypeEntity_.displayName);
    Path<Integer> tagTypeOrderColumn = tagTypeEntityRoot.get(TagTypeEntity_.orderNumber);

    // Order the results by tag type's order and display name.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(tagTypeOrderColumn));
    orderBy.add(builder.asc(displayNameColumn));

    // Add all clauses to the query.
    criteria.select(tagTypeEntityRoot).orderBy(orderBy);

    // Run the query and return the results.
    return entityManager.createQuery(criteria).getResultList();
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:26,代碼來源:TagTypeDaoImpl.java

示例13: sortUserJidsByEmail

import javax.persistence.criteria.Order; //導入依賴的package包/類
@Override
public List<String> sortUserJidsByEmail(Collection<String> userJids, String sortBy, String order) {
    CriteriaBuilder cb = JPA.em().getCriteriaBuilder();
    CriteriaQuery<String> query = cb.createQuery(String.class);
    Root<UserEmailModel> root = query.from(UserEmailModel.class);

    Predicate condition = root.get(UserEmailModel_.userJid).in(userJids);

    Order orderBy = null;
    if ("asc".equals(order)) {
        orderBy = cb.asc(root.get(sortBy));
    } else {
        orderBy = cb.desc(root.get(sortBy));
    }

    query.select(root.get(UserEmailModel_.userJid)).where(condition).orderBy(orderBy);
    return JPA.em().createQuery(query).getResultList();
}
 
開發者ID:judgels-deprecated,項目名稱:judgels-jophiel,代碼行數:19,代碼來源:UserEmailHibernateDao.java

示例14: sortUserJidsByUserAttribute

import javax.persistence.criteria.Order; //導入依賴的package包/類
@Override
public List<String> sortUserJidsByUserAttribute(Collection<String> userJids, String sortBy, String order) {
    CriteriaBuilder cb = JPA.em().getCriteriaBuilder();
    CriteriaQuery<String> query = cb.createQuery(String.class);
    Root<UserModel> root = query.from(UserModel.class);

    Predicate condition = root.get(UserModel_.jid).in(userJids);

    Order orderBy = null;
    if ("asc".equals(order)) {
        orderBy = cb.asc(root.get(sortBy));
    } else {
        orderBy = cb.desc(root.get(sortBy));
    }

    query.select(root.get(UserModel_.jid)).where(condition).orderBy(orderBy);
    return JPA.em().createQuery(query).getResultList();
}
 
開發者ID:judgels-deprecated,項目名稱:judgels-jophiel,代碼行數:19,代碼來源:UserHibernateDao.java

示例15: readAllStaticAssets

import javax.persistence.criteria.Order; //導入依賴的package包/類
public List<StaticAsset> readAllStaticAssets() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StaticAsset> criteria = builder.createQuery(StaticAsset.class);
    Root<StaticAssetImpl> handler = criteria.from(StaticAssetImpl.class);
    criteria.select(handler);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    List<Order> sorts = new ArrayList<Order>();
    try {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().setup(StaticAssetImpl.class, null);
            queryExtensionManager.getProxy().refineRetrieve(StaticAssetImpl.class, null, builder, criteria, handler, restrictions);
            queryExtensionManager.getProxy().refineOrder(StaticAssetImpl.class, null, builder, criteria, handler, sorts);
        }
        criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
        return em.createQuery(criteria).getResultList();
    } catch (NoResultException e) {
        return new ArrayList<StaticAsset>();
    }
}
 
開發者ID:takbani,項目名稱:blcdemo,代碼行數:20,代碼來源:StaticAssetDaoImpl.java


注:本文中的javax.persistence.criteria.Order類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。