List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
From source file:eu.uqasar.service.company.CompanyService.java
/** * /*from www . j a v a 2 s. c o m*/ * @param innovationObjective * @return */ public List<Company> getAllByAscendingNameFiltered(CompanyFilterStructure filter, int first, int count) { logger.infof("loading all Companies ordered by ascending name matching the given filter %s...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> criteria = cb.createQuery(Company.class); Root<Company> root = criteria.from(Company.class); criteria.where(cb.or(cb.equal(root.get(Company_.name), filter.getName()), cb.equal(root.get(Company_.shortName), filter.getShortName()), cb.equal(root.get(Company_.country), filter.getCountry())) ); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
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);/*from ww w. j ava 2 s . c o m*/ if (member != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("member"), member)); } return super.findPage(criteriaQuery, pageable); }
From source file:org.openmeetings.app.data.user.Salutationmanagement.java
/** * get a list of all availible Salutations * // w ww . jav a 2s . c om * @param user_level * @return */ public List<Salutations> getUserSalutations(long language_id) { try { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Salutations> cq = cb.createQuery(Salutations.class); Root<Salutations> from = cq.from(Salutations.class); CriteriaQuery<Salutations> select = cq.select(from); TypedQuery<Salutations> q = em.createQuery(select); List<Salutations> ll = q.getResultList(); for (Salutations ti : ll) { ti.setLabel(fieldmanagment.getFieldByIdAndLanguage(ti.getFieldvalues_id(), language_id)); } return ll; } catch (Exception ex2) { log.error("[addUserSalutation]", ex2); } return null; }
From source file:com.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java
@Override public ApplicationBuilt getLatestBuilt(Application application) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class); Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class); cq = cq.where(cb.equal(from.get(ApplicationBuilt_.application), application)) .orderBy(cb.desc(from.get(ApplicationBuilt_.startDate))); try {/* ww w . j a v a 2 s.co m*/ return em.createQuery(cq).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { throw new ApplicationBuiltNotFoundException(e); } }
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 w w w.j a v a2 s . c om 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: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 *//* w w w . jav a2s . c om*/ @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(); }
From source file:com.zergiu.tvman.dao.impl.TVShowDaoImpl.java
@Override public Long getTVShowsCount() { CriteriaBuilder criteria = em.getCriteriaBuilder(); CriteriaQuery<Long> query = criteria.createQuery(Long.class); query.select(criteria.countDistinct(query.from(TVShow.class))); Long count = em.createQuery(query).getSingleResult(); log.debug("all count: " + count); return count; }
From source file:org.wallride.repository.CustomFieldRepositoryImpl.java
@Override public void lock(long id) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<CustomField> root = query.from(CustomField.class); query.select(root.get(CustomField_.id)); query.where(cb.equal(root.get(CustomField_.id), id)); entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult(); }
From source file:com.datapine.dao.impl.UserDAOImpl.java
/** * Looks for the user by email.//from w w w . j a v a2s. com * @param email The specified email. * @return Found user. */ @Override public final User findByEmail(final String email) { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<User> query = builder.createQuery(User.class); final Root<User> root = query.from(User.class); query.where(builder.equal(root.get("email"), email)); return this.manager.createQuery(query).getResultList().get(0); }
From source file:com.datapine.dao.impl.UserDAOImpl.java
/** * Gets an iterator for the collection of all users sorted by id. * @return An iterator.//from w ww. ja va 2s . c om */ @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(); }