List of usage examples for javax.persistence.criteria CriteriaBuilder asc
Order asc(Expression<?> x);
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 {/* ww w . jav a 2 s . c o 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 * /* w w w .j a v a 2s .c o m*/ * @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.github.springtestdbunit.entity.EntityAssert.java
public void afterPropertiesSet() throws Exception { CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); this.criteriaQuery = cb.createQuery(SampleEntity.class); Root<SampleEntity> from = this.criteriaQuery.from(SampleEntity.class); this.criteriaQuery.orderBy(cb.asc(from.get("value").as(String.class))); }
From source file:eu.uqasar.service.company.CompanyService.java
/** * //from w w w .j a va 2s. c o m * @param innovationObjective * @return */ public List<Company> getAllByAscendingName() { logger.infof("loading all Company ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> criteria = cb.createQuery(Company.class); Root<Company> root = criteria.from(Company.class); criteria.orderBy(cb.asc(root.get(Company_.name))); return em.createQuery(criteria).getResultList(); }
From source file:com.datapine.dao.impl.ItemDAOImpl.java
@Override @PostFilter("hasRole('ROLE_ADMIN') or hasPermission(filterObject, 'read')") public final List<Item> findAllOrderById() { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<Item> query = builder.createQuery(Item.class); final Root<Item> root = query.from(Item.class); query.select(root).orderBy(builder.asc(root.get("id"))); return this.manager.createQuery(query).getResultList(); }
From source file:com.github.springtestdbunit.entity.OtherEntityAssert.java
public void afterPropertiesSet() throws Exception { CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); this.criteriaQuery = cb.createQuery(OtherSampleEntity.class); Root<OtherSampleEntity> from = this.criteriaQuery.from(OtherSampleEntity.class); this.criteriaQuery.orderBy(cb.asc(from.get("value").as(String.class))); }
From source file:com.excilys.ebi.sample.jpa.query.benchmark.repository.impl.JPACriteriaRepository.java
@Override public List<Song> getSongsByArtistNameOrderBySongTitle(final String name) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Song> query = builder.createQuery(Song.class); Root<Song> root = query.from(Song.class); query.where(builder.equal(root.get(Song_.artist).get(Artist_.name), name)) .orderBy(builder.asc(root.get(Song_.title))); return em.createQuery(query).getResultList(); }
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 .j a v a 2 s. c o m return Collections.singletonList(builder.desc(from.get(sortColumn))); } return getDefaultOrderList(builder, from); }
From source file:com.datapine.dao.impl.UserDAOImpl.java
/** * Gets an iterator for the collection of all users sorted by id. * @return An iterator.//w w w. j av a 2 s.c o m */ @Override public final Iterator<User> findAllOrderById() { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<User> query = builder.createQuery(User.class); final Root<User> root = query.from(User.class); query.select(root).orderBy(builder.asc(root.get("id"))); return this.manager.createQuery(query).getResultList().iterator(); }
From source file:com.aimdek.ccm.dao.impl.BulkUploadRepositoryImpl.java
/** * Adds the sorting./* w w w . ja v a2 s.c o m*/ * * @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))); } } }