List of usage examples for javax.persistence.criteria CriteriaBuilder asc
Order asc(Expression<?> x);
From source file:eu.uqasar.service.ProductService.java
/** * /*from ww w . j av a2s.c om*/ * @return */ public List<Product> getAllByAscendingName(int first, int count) { logger.infof("loading all Products ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = cb.createQuery(Product.class); Root<Product> root = criteria.from(Product.class); criteria.orderBy(cb.asc(root.get(Product_.name))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:com.moderndrummer.data.MemberDaoImpl.java
@Override public List<Member> findAllOrderedByName() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = cb.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); criteria.select(member).orderBy(cb.asc(member.get("name"))); return em.createQuery(criteria).getResultList(); }
From source file:eu.uqasar.service.ProcessService.java
/** * //from ww w . j a v a2 s . c o m * @param first * @param count * @return */ public List<Process> getAllByAscendingName(int first, int count) { logger.infof("loading all Processes ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Process> criteria = cb.createQuery(Process.class); Root<Process> root = criteria.from(Process.class); criteria.orderBy(cb.asc(root.get(Process_.name))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:com.aimdek.ccm.dao.impl.StatementRepositoryImpl.java
/** * Adds the sorting./*from www . j a v a 2 s . c om*/ * * @param sortField * the sort field * @param sortOrder * the sort order * @param query * the query * @param builder * the builder * @param root * the root */ private void addSorting(String sortField, String sortOrder, CriteriaQuery query, CriteriaBuilder builder, Root<Statement> 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:eu.uqasar.service.ProductService.java
public List<Product> sortAscendingDates() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = cb.createQuery(Product.class); Root<Product> from = criteria.from(Product.class); criteria.select(from);//from w w w . jav a 2s .c om return em.createQuery(criteria.orderBy(cb.asc(from.get("releaseDate")))).getResultList(); }
From source file:com.aimdek.ccm.dao.impl.TransactionRepositoryImpl.java
/** * Adds the sorting.//from w w w .j av a2 s. c o m * * @param sortField * the sort field * @param sortOrder * the sort order * @param query * the query * @param builder * the builder * @param root * the root */ private void addSorting(String sortField, String sortOrder, CriteriaQuery query, CriteriaBuilder builder, Root<Transaction> 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:com.fantasy.stataggregator.workers.StatCompilerTask.java
@Override public void setYear(int year) throws Exception { this.year = year; GameDataRepository gdr = ctx.getBean(GameDataRepository.class); if (year == Integer.MAX_VALUE) { gamesData = gdr.findAll();// www .ja v a 2s .c om } else { SimpleDateFormat sdf = ctx.getBean(SimpleDateFormat.class); sdf.applyLocalizedPattern("yyyyMMdd"); Date min = sdf.parse(year + START_OF_YEAR); Date max = sdf.parse(year + END_OF_YEAR); CriteriaBuilder cb = gdr.getCriteriaBuilder(); CriteriaQuery<GameData> cq = gdr.getCriteriaQuery(); Root<GameData> gameData = gdr.getRoot(); Path<GameDataPK> pk = gameData.get(GameData_.gameDataPK); cq.select(gameData).where(cb.equal(pk.get(GameDataPK_.year), year)) .orderBy(cb.asc(pk.get(GameDataPK_.gameIdentifier))); gamesData = gdr.getCriteriaList(cq); System.out.println(gamesData.size()); } }
From source file:net.groupbuy.dao.impl.TagDaoImpl.java
public List<Tag> findList(Type type) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Tag> criteriaQuery = criteriaBuilder.createQuery(Tag.class); Root<Tag> root = criteriaQuery.from(Tag.class); criteriaQuery.select(root);/* w ww . j a v a 2 s. c om*/ if (type != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:com.excilys.ebi.sample.jpa.query.benchmark.repository.impl.JPACriteriaRepository.java
@Override public List<Song> getSongsBySameArtistOrderBySongTitle(final Integer songId) { // select s.artist.songs from Song s where s.id=? CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Song> query = builder.createQuery(Song.class); Root<Song> song1 = query.from(Song.class); Join<Artist, Song> artistSongs = song1.join(Song_.artist).join(Artist_.songs); query.select(artistSongs).where(builder.equal(song1.get(Song_.id), songId)) .orderBy(builder.asc(artistSongs.get(Song_.title))); return em.createQuery(query).getResultList(); }
From source file:net.dontdrinkandroot.persistence.dao.TypedJpaDao.java
@Override @Transactional(propagation = Propagation.MANDATORY, readOnly = true) public List<E> findAll(final SingularAttribute<? super E, ?> attribute, final boolean asc) { final CriteriaBuilder builder = this.getCriteriaBuilder(); final CriteriaQuery<E> criteriaQuery = builder.createQuery(this.entityClass); final Root<E> from = criteriaQuery.from(this.entityClass); if (asc) {// w w w.j ava 2s . c o m criteriaQuery.orderBy(builder.asc(from.get(attribute))); } else { criteriaQuery.orderBy(builder.desc(from.get(attribute))); } return this.find(criteriaQuery); }