List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionTelephonyDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { this.findAllSessionTelephony = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<SessionTelephonyImpl>>() { @Override//www . j a v a 2s. c o m public CriteriaQuery<SessionTelephonyImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<SessionTelephonyImpl> criteriaQuery = cb .createQuery(SessionTelephonyImpl.class); final Root<SessionTelephonyImpl> definitionRoot = criteriaQuery .from(SessionTelephonyImpl.class); criteriaQuery.select(definitionRoot); return criteriaQuery; } }); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionRecordingDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { this.findAllSessionRecordings = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<SessionRecordingImpl>>() { @Override/*from w w w . j a v a2s . co m*/ public CriteriaQuery<SessionRecordingImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<SessionRecordingImpl> criteriaQuery = cb .createQuery(SessionRecordingImpl.class); final Root<SessionRecordingImpl> definitionRoot = criteriaQuery .from(SessionRecordingImpl.class); criteriaQuery.select(definitionRoot); return criteriaQuery; } }); }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
/** * find entity in the range//w w w .j a v a2s. co m * * @param range * @return */ public List<T> findRange(int[] range) { EntityManager em = getEntityManager(); CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); Query q = em.createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); }
From source file:de.egore911.persistence.selector.AbstractSelector.java
private TypedQuery<T> buildQuery() { EntityManager em = EntityManagerUtil.getEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<T> cq = builder.createQuery(getEntityClass()); Root<T> from = cq.from(getEntityClass()); List<Predicate> predicates = generatePredicateList(builder, from, cq); cq.where(predicates.toArray(new Predicate[predicates.size()])); cq.orderBy(generateOrderList(builder, from)); cq.select(from); return em.createQuery(cq); }
From source file:com.sfs.captor.controller.ProjectPackageAction.java
/** * Load project packages/*from w w w .j a va 2 s.com*/ */ private void loadList() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ProjectPackage> c = cb.createQuery(ProjectPackage.class); Root<ProjectPackage> obj = c.from(ProjectPackage.class); c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id"))); this.projectPackages = em.createQuery(c).getResultList(); }
From source file:org.broadleafcommerce.common.i18n.dao.TranslationDaoImpl.java
@Override public Long countTranslationEntries(TranslatedEntity entityType, ResultType stage) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = builder.createQuery(Long.class); Root<TranslationImpl> root = criteria.from(TranslationImpl.class); criteria.select(builder.count(root)); List<Predicate> restrictions = new ArrayList<Predicate>(); restrictions.add(builder.equal(root.get("entityType"), entityType.getFriendlyType())); try {//from w w w . ja v a 2 s . com if (extensionManager != null) { extensionManager.getProxy().setup(TranslationImpl.class, stage); extensionManager.getProxy().refineRetrieve(TranslationImpl.class, stage, builder, criteria, root, restrictions); } criteria.where(restrictions.toArray(new Predicate[restrictions.size()])); TypedQuery<Long> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); return query.getSingleResult(); } finally { if (extensionManager != null) { extensionManager.getProxy().breakdown(TranslationImpl.class, stage); } } }
From source file:dao.jpa.JpaUtilsTest.java
@Test @Transactional//from ww w. j av a2s. c om public void testCountFromComplexCriteria() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> bookQuery = cb.createQuery(Book.class); Root<Book> root = bookQuery.from(Book.class); Join<Book, Category> join = root .join(em.getMetamodel().entity(Book.class).getSingularAttribute("category", Category.class)); bookQuery.where(cb.equal(join.<String>get("name"), "Java")); bookQuery.from(Author.class); bookQuery.select(root); CriteriaQuery<Long> countQuery = JpaUtils.countCriteria(em, bookQuery); Long result = Long.valueOf(em.createQuery(bookQuery).getResultList().size()); assertEquals(result, (Long) em.createQuery(countQuery).getSingleResult()); }
From source file:cz.vse.webmail.EmailDAOBean.java
@Override public List<Email> getFilteredEmails(User user, EmailListFilter filter) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Email> criteria = cb.createQuery(Email.class); Root<Email> root = criteria.from(Email.class); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(cb.equal(root.<User>get("owner"), user)); if (StringUtils.isNoneBlank(filter.getTo())) { predicates.add(cb.like(root.<String>get("to"), "%" + filter.getTo() + "%")); }// www .j a va 2 s .c o m criteria.select(root).where(predicates.toArray(new Predicate[] {})); return entityManager.createQuery(criteria).getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
public long countAllFiltered(final CompanyFilterStructure filter) { logger.infof("counting all Companies matching the filter %s ...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<Company> from = criteria.from(Company.class); criteria.where(cb.or(cb.equal(from.get(Company_.name), filter.getName()), cb.equal(from.get(Company_.shortName), filter.getShortName()), cb.equal(from.get(Company_.country), filter.getCountry()))); criteria.select(cb.countDistinct(from)); return em.createQuery(criteria).getSingleResult(); }
From source file:org.sloth.persistence.impl.ObservationDaoImpl.java
@Override public Collection<Observation> getByKeyWord(String key) throws NullPointerException { if (key == null) { throw new NullPointerException(); }//from ww w.ja v a2 s. c o m key = "%" + key.trim().replace('*', '%').toUpperCase() + "%"; CriteriaBuilder b = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Observation> q = b.createQuery(Observation.class); Root<Observation> o = q.from(Observation.class); Join<Observation, Categorie> j = o.join(Observation_.categorie); Collection<Observation> result = getEntityManager().createQuery(q.select(o).distinct(true) .where(b.or(b.like(b.upper(j.get(Categorie_.title)), key), b.like(b.upper(j.get(Categorie_.description)), key), b.like(b.upper(o.get(Observation_.title)), key), b.like(b.upper(o.get(Observation_.description)), key)))) .getResultList(); logger.info("Searched for {}. Got {} Results.", key, result.size()); return result; }