List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:com.datapine.dao.impl.UserDAOImpl.java
/** * Gets an iterator for the collection of all users sorted by id. * @return An iterator.// ww w . ja v a2 s.co 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.sixsq.slipstream.persistence.Run.java
public static List<RunView> viewList(User user, String moduleResourceUri, Integer offset, Integer limit, String cloudServiceName) throws ConfigurationException, ValidationException { List<RunView> views = null; EntityManager em = PersistenceUtil.createEntityManager(); try {//from www .j a va2 s. com CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Run> critQuery = builder.createQuery(Run.class); Root<Run> rootQuery = critQuery.from(Run.class); critQuery.select(rootQuery); Predicate where = viewListCommonQueryOptions(builder, rootQuery, user, moduleResourceUri, cloudServiceName); if (where != null) { critQuery.where(where); } critQuery.orderBy(builder.desc(rootQuery.get("startTime"))); TypedQuery<Run> query = em.createQuery(critQuery); if (offset != null) { query.setFirstResult(offset); } query.setMaxResults((limit != null) ? limit : DEFAULT_LIMIT); List<Run> runs = query.getResultList(); views = convertRunsToRunViews(runs); } finally { em.close(); } return views; }
From source file:org.sloth.persistence.impl.CategorieDaoImpl.java
@Override public Collection<Categorie> getAll() { CriteriaQuery<Categorie> cq = getEntityManager().getCriteriaBuilder().createQuery(Categorie.class); cq.select(cq.from(Categorie.class)); Collection<Categorie> list = getEntityManager().createQuery(cq).getResultList(); logger.info("Getting all Categories; Found: {}", list.size()); return list;/*w w w .j a va 2 s . c om*/ }
From source file:net.groupbuy.dao.impl.ReceiverDaoImpl.java
public Page<Receiver> findPage(Member member, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Receiver> criteriaQuery = criteriaBuilder.createQuery(Receiver.class); Root<Receiver> root = criteriaQuery.from(Receiver.class); criteriaQuery.select(root); if (member != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); }//ww w . j ava 2s.c o m return super.findPage(criteriaQuery, pageable); }
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}/*from ww w .j a v a 2 s.c om*/ */ public List<EntityType> retrieveAll(Class<EntityType> entityClass) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<EntityType> query = builder.createQuery(entityClass); Root<EntityType> root = query.from(entityClass); query.select(root); return entityManager.createQuery(query).getResultList(); }
From source file:org.wallride.repository.PostRepositoryImpl.java
@Override public void lock(long id) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<Post> root = query.from(Post.class); query.select(root.get(Post_.id)); query.where(cb.equal(root.get(Post_.id), id)); entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult(); }
From source file:pdsanchez.mywebtools.model.dao.jpa.GenericDAOJPAImpl.java
@Override public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root<T> rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); }
From source file:ispok.dao.TournamentHibernateJpaDao.java
@Override public Long getCount(Map<String, Object> filters) { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Tournament> t = cq.from(Tournament.class); cq.select(cb.count(t)); TypedQuery<Long> tq = em.createQuery(cq); return tq.getSingleResult(); }
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}/*from ww w . java 2s . c om*/ */ public EntityType findExact(String key, Object 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).getSingleResult(); }
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 *///from ww w. j ava 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(); }