List of usage examples for javax.persistence.criteria CriteriaBuilder desc
Order desc(Expression<?> x);
From source file:th.co.geniustree.dental.spec.EmployeeSpec.java
public static Specification<Employee> emailLike(final String keyword) { return new Specification<Employee>() { @Override//from w w w .ja va 2 s . c om public Predicate toPredicate(Root<Employee> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { CriteriaQuery cc = cq.orderBy(cb.desc(root.get(Employee_.id))); return cb.like(cb.upper(root.get(Employee_.email)), keyword.toUpperCase()); } }; }
From source file:com.github.jinahya.persistence.ShadowTest.java
protected static List<Morton> MORTONS(final EntityManager manager, final int firstResult, final int maxResults) { final CriteriaBuilder builder = manager.getCriteriaBuilder(); final CriteriaQuery<Morton> query = builder.createQuery(Morton.class); final Root<Morton> morton = query.from(Morton.class); query.select(morton).orderBy(builder.desc(morton.get(Morton_.id))); return manager.createQuery(query).setFirstResult(firstResult).setMaxResults(maxResults).getResultList(); }
From source file:net.sf.companymanager.qbe.JpaUtil.java
public static <E> List<Order> buildJpaOrders(final Iterable<OrderBy> orders, final Root<E> root, final CriteriaBuilder builder) { List<Order> jpaOrders = new ArrayList<Order>(); for (OrderBy ob : orders) { Path<?> path = getPropertyPath(root, ob.getProperty()); if (ob.isOrderDesc()) { jpaOrders.add(builder.desc(path)); } else {//from ww w. j a v a 2s. co m jpaOrders.add(builder.asc(path)); } } return jpaOrders; }
From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java
/** * Adds the "order by" clause to a JPA 2 criteria query * /*from w w w. j a v a 2 s . c om*/ * @param builder * the criteria builder * @param cq * the criteria query * @param root * the query root * @param sortOrder * the sort object * @return */ private static <T, R> CriteriaQuery<R> addSortInformation(CriteriaBuilder builder, CriteriaQuery<R> cq, Root<T> root, SortOrder... sortOrders) { if (sortOrders != null && sortOrders.length > 0) { List<javax.persistence.criteria.Order> orders = new ArrayList<>(); for (SortOrder sortOrder : sortOrders) { Expression<?> property = (Expression<?>) getPropertyPath(root, sortOrder.getProperty()); orders.add(sortOrder.isAscending() ? builder.asc(property) : builder.desc(property)); } cq.orderBy(orders); } return cq; }
From source file:com.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java
@Override public ApplicationBuilt getLatestBuilt(Application application) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class); Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class); cq = cq.where(cb.equal(from.get(ApplicationBuilt_.application), application)) .orderBy(cb.desc(from.get(ApplicationBuilt_.startDate))); try {/*from w ww . jav a 2 s . c o m*/ return em.createQuery(cq).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { throw new ApplicationBuiltNotFoundException(e); } }
From source file:com.aimdek.ccm.dao.impl.BulkUploadRepositoryImpl.java
/** * {@inheritDoc}/*from ww w . j a va 2 s . c o m*/ */ public BulkUpload findLastBulkUpload() { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<BulkUpload> query = builder.createQuery(BulkUpload.class); Root<BulkUpload> root = query.from(BulkUpload.class); query.select(root); query.orderBy(builder.desc(root.get(FIELD_CONSTANT_CREATED_AT))); try { return entityManager.createQuery(query).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { LOGGER.error("Error while retrieving last bulkupload", e); } return null; }
From source file:eu.uqasar.service.ProductService.java
public List<Product> sortDescendingDates() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = cb.createQuery(Product.class); Root<Product> from = criteria.from(Product.class); criteria.select(from);/*from w ww .j av a2 s .com*/ return em.createQuery(criteria.orderBy(cb.desc(from.get("releaseDate")))).getResultList(); }
From source file:org.sloth.persistence.impl.ObservationDaoImpl.java
@Override public List<Observation> getNewestObservations(int count) { if (count <= 0) { return new LinkedList<Observation>(); }// www . j a v a2 s . com CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Observation> cq = cb.createQuery(Observation.class); Root<Observation> o = cq.from(Observation.class); cq.select(o).orderBy(cb.desc(o.get(Observation_.creationDate))); List<Observation> result = getEntityManager().createQuery(cq).setMaxResults(count).getResultList(); if (result.size() < count) { logger.info("Only {} Observations in the database", result.size()); } else { logger.info("Found the {} last Observations", result.size()); } return result; }
From source file:com.aimdek.ccm.dao.impl.BulkUploadRepositoryImpl.java
/** * Adds the sorting./*from w w w. j a v a 2s . c om*/ * * @param sortField * the sort field * @param sortOrder * the sort order * @param query * the query */ private void addSorting(String sortField, String sortOrder, CriteriaQuery query, CriteriaBuilder builder, Root<BulkUpload> root) { if (CommonUtil.isNotNull(sortField)) { if (sortOrder.startsWith(SORT_ORDER_ASCENDING)) { query.orderBy(builder.asc(root.get(sortField))); } else { query.orderBy(builder.desc(root.get(sortField))); } } }
From source file:de.egore911.persistence.selector.AbstractSelector.java
@Nonnull protected List<Order> generateOrderList(@Nonnull CriteriaBuilder builder, @Nonnull Root<T> from) { if (StringUtils.isNotEmpty(sortColumn)) { if (!Boolean.FALSE.equals(ascending)) { return Collections.singletonList(builder.asc(from.get(sortColumn))); }/*from w w w . jav a2s . c o m*/ return Collections.singletonList(builder.desc(from.get(sortColumn))); } return getDefaultOrderList(builder, from); }