List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}//from w ww.ja v a2 s. c om */ public List<EntityType> findExactList(String key, IDType value, Class<EntityType> entityClass) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EntityType> query = builder.createQuery(entityClass); Root<EntityType> root = query.from(entityClass); query.select(root); query.where(builder.equal(root.get(key), value)); return entityManager.createQuery(query).getResultList(); }
From source file:fi.vm.sade.organisaatio.dao.impl.YhteystietoElementtiDAOImpl.java
@Override public List<YhteystietoElementti> findAllKaytossa() { // Query query = getEntityManager().createQuery("SELECT x FROM YhteystietoElementti x where x.kaytossa = true"); // return query.getResultList(); CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<YhteystietoElementti> query = cb.createQuery(YhteystietoElementti.class); Root<YhteystietoElementti> root = query.from(YhteystietoElementti.class); query.select(root);/*w w w .j a v a 2 s . c om*/ Predicate whereClause = cb.equal(root.get("kaytossa"), true); query.where(whereClause); return getEntityManager().createQuery(query).getResultList(); }
From source file:org.sloth.persistence.impl.UserDaoImpl.java
@Override public User getByMail(String mail) { if (mail == null) { throw new NullPointerException(); }/*from w w w . ja va2 s . c o m*/ CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<User> cq = cb.createQuery(User.class); Root<User> user = cq.from(User.class); cq.select(user).where(cb.equal(user.get(User_.mail), mail)); User result = null; try { result = getEntityManager().createQuery(cq).getSingleResult(); } catch (NoResultException e) { logger.info("User with address {} not found", mail); } catch (NonUniqueResultException e) { logger.warn("Corrupt Database", e); } return result; }
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:org.sloth.persistence.impl.ReportDaoImpl.java
private Collection<Report> get(boolean processed) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Report> cq = cb.createQuery(Report.class); Root<Report> r = cq.from(Report.class); cq.select(r).where(cb.equal(r.get(Report_.processed), processed)); Collection<Report> result = getEntityManager().createQuery(cq).getResultList(); logger.info("{} {} Reports.", (processed) ? "processed" : "unprocessed", result.size()); return result; }
From source file:eu.uqasar.service.ProductService.java
/** * //from w w w . j a va 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:eu.uqasar.service.ProductService.java
/** * //from w w w .j a v a 2s. co m * @param productId * @return */ public boolean productExists(Long productId) { logger.info(String.format("checking if product with ID %d exists ...", productId)); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Product> from = criteria.from(Product.class); criteria.where(cb.equal(from.get(Product_.id), productId)); criteria.select(cb.countDistinct(from)); return (em.createQuery(criteria).getSingleResult() == 1); }
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:net.carinae.dev.async.dao.QueuedTaskHolderDaoJPA2.java
@Override public QueuedTaskHolder findNextTaskForExecution() { Calendar NOW = Calendar.getInstance(); // select qt from QueuedTask where // qt.startedStamp == null AND // (qth.triggerStamp == null || qth.triggerStamp < NOW) // order by qth.version ASC, qt.creationStamp ASC CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); CriteriaQuery<QueuedTaskHolder> cq = cb.createQuery(QueuedTaskHolder.class); Root<QueuedTaskHolder> qth = cq.from(QueuedTaskHolder.class); cq.select(qth)/*from www. j a v a2s. co m*/ .where(cb.and(cb.isNull(qth.get(QueuedTaskHolder_.startedStamp)), cb.or(cb.isNull(qth.get(QueuedTaskHolder_.triggerStamp)), cb.lessThan(qth.get(QueuedTaskHolder_.triggerStamp), NOW)))) .orderBy(cb.asc(qth.get(QueuedTaskHolder_.version)), cb.asc(qth.get(QueuedTaskHolder_.creationStamp))); List<QueuedTaskHolder> results = this.entityManager.createQuery(cq).setMaxResults(1).getResultList(); if (results.isEmpty()) { return null; } else { return results.get(0); } }
From source file:fi.vm.sade.organisaatio.dao.impl.YhteystietoArvoDAOImpl.java
/** * Returns yhteystietoarvos for a given yhteystietojen tyyppi * @param yhteystietojenTyyppi the yhteystietojen tyyppi given * @return the yhteystietoarvo objects matching the given yhteystietojen tyyppi */// ww w . j av a 2s.com @Override public List<YhteystietoArvo> findByYhteystietojenTyyppi(YhteystietojenTyyppi yhteystietojenTyyppi) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<YhteystietoArvo> query = cb.createQuery(YhteystietoArvo.class); Root<YhteystietoArvo> root = query.from(YhteystietoArvo.class); query.select(root); Predicate yhteystietojenTyyppiEquals = cb.equal(root.get("kentta").get("yhteystietojenTyyppi").get("oid"), yhteystietojenTyyppi.getOid()); query.where(yhteystietojenTyyppiEquals); return getEntityManager().createQuery(query).getResultList(); }