List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
From source file:eu.uqasar.service.ProductService.java
public List fillVersionDropDownChoice() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = cb.createQuery(Product.class); Root<Product> from = criteria.from(Product.class); criteria.multiselect(from.get(Product_.version)); return (List) em.createQuery(criteria).getResultList(); }
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);//ww w . ja va 2 s. c om return em.createQuery(criteria.orderBy(cb.desc(from.get("releaseDate")))).getResultList(); }
From source file:com.june.app.board.repository.jpa.BoardRepositoryImpl.java
@Override public long boardListCnt(Board vo) { CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); int bbsId = vo.getBbsId(); CriteriaQuery<Long> countQuery = criteriaBuilder.createQuery(Long.class); Root<Board> from = countQuery.from(Board.class); countQuery.select(criteriaBuilder.count(from)); if (bbsId > 0) { countQuery.where(criteriaBuilder.equal(from.get("bbsId"), bbsId)); }/*w ww .j av a2 s . c o m*/ Long count = em.createQuery(countQuery).getSingleResult(); return count; }
From source file:com.moderndrummer.data.MemberDaoImpl.java
@Override public List<Member> findAllCreatedMembersByFromAndToDate(Date fromDate, Date toDate) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = cb.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); Path<Date> dateCreatedPath = member.get("createdDate"); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(cb.lessThanOrEqualTo(dateCreatedPath, toDate)); predicates.add(cb.greaterThanOrEqualTo(dateCreatedPath, fromDate)); criteria.where(predicates.toArray(new Predicate[predicates.size()])); criteria.select(member).orderBy(cb.asc(member.get("name"))); return em.createQuery(criteria).getResultList(); }
From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java
public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return em.createQuery(cq).getResultList(); }
From source file:com.moderndrummer.data.MemberDaoImpl.java
@Override public Member findByEmail(String email) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = builder.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); criteria.select(member).where(builder.equal(member.get("email"), email)); return em.createQuery(criteria).getSingleResult(); }
From source file:net.przemkovv.sphinx.dao.impl.DefaultGenericDAO.java
@Override public Long countAll() { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); cq.select(cb.count(cq.from(type))); return getEntityManager().createQuery(cq).getSingleResult(); }
From source file:eu.uqasar.service.ProductService.java
/** * /*from w w w . ja v a 2 s . 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.aimdek.ccm.dao.impl.CreditCardRepositoryImpl.java
/** * {@inheritDoc}// ww w .ja v a 2 s.c o m */ public long getCreditCardsCount(Map<String, Object> filters) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = builder.createQuery(Long.class); Root<CreditCard> root = query.from(CreditCard.class); query.select(builder.count(root)); addFilterCriteria(filters, builder, root, query); return entityManager.createQuery(query).getSingleResult(); }
From source file:com.samples.platform.serviceprovider.library.internal.dao.PlatformDao.java
/** * @param ISBN//ww w .j ava 2 s.c o m * the ISBN of the book to find. * @return the {@link BookType}. */ @Transactional(value = PersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public BookType getBookByISBN(final String ISBN) { BookType m = null; if (ISBN == null) { this.logger.debug("getBookByISBN: ISBN is null."); } else { CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<BookType> q = cb.createQuery(BookType.class); Root<BookType> c = q.from(BookType.class); q.where(cb.equal(c.<String>get(BookType_.ISBN), ISBN)); TypedQuery<BookType> typedQuery = this.em.createQuery(q); try { m = typedQuery.getSingleResult(); this.logger.debug("getBookByISBN: " + ToStringBuilder.reflectionToString(m)); } catch (NoResultException e) { this.logger.debug("getBookByISBN: non value found for ISBN=" + ISBN); m = null; } } return m; }