本文整理匯總了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);
}
};
}
示例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;
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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));
}
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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>();
}
}