List of usage examples for javax.persistence.criteria CriteriaQuery select
CriteriaQuery<T> select(Selection<? extends T> selection);
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.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}//from www . j a v a 2 s. c om */ public EntityType findById(IDType id, 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(FIELD_CONSTANT_ID), id)); return entityManager.createQuery(query).getSingleResult(); }
From source file:com.aimdek.ccm.dao.impl.BasicAbstractGenericDaoImpl.java
/** * {@inheritDoc}//from w w w . j a v a 2s. c o m */ 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:com.greendot.db.jpa.core.AbstractSearchDao.java
@Transactional(readOnly = true) public Optional<E> findByCharacterType(final String key, final String value) { notNull(key, "Mandatory argument 'key' is missing."); notNull(value, "Mandatory argument 'value' is missing."); final CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); final CriteriaQuery<E> query = builder.createQuery(getEntityType()); final Root<E> root = query.from(getEntityType()); query.select(root).where(builder.and(builder.equal(root.get(key), value))).distinct(true); final List<E> results = getEntityManager().createQuery(query).getResultList(); if ((results != null) && (results.size() == 1)) return Optional.of(results.get(0)); return Optional.empty(); }
From source file:com.movies.dao.impl.BaseDaoImpl.java
@Override public <T> List<T> getAllObjects(Class clazz) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(clazz); Root<T> object = cq.from(clazz); cq.select(object); TypedQuery<T> q = em.createQuery(cq); return q.getResultList(); }
From source file:org.osiam.resource_server.storage.dao.ExtensionDao.java
/** * Get all stored extensions./* www .j a v a 2s .co m*/ * * @return all extensions. */ public List<ExtensionEntity> getAllExtensions() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ExtensionEntity> cq = cb.createQuery(ExtensionEntity.class); Root<ExtensionEntity> extension = cq.from(ExtensionEntity.class); cq.select(extension); TypedQuery<ExtensionEntity> query = em.createQuery(cq); return query.getResultList(); }
From source file:fi.vm.sade.organisaatio.dao.impl.YhteystietoArvoDAOImpl.java
@Override public YhteystietoArvo findByOrganisaatioAndNimi(String organisaatioOid, String nimi) { CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<YhteystietoArvo> query = cb.createQuery(YhteystietoArvo.class); Root<YhteystietoArvo> root = query.from(YhteystietoArvo.class); query.select(root); Predicate organisaatioEquals = cb.equal(root.get("organisaatio").get("oid"), organisaatioOid); Predicate nameEquals = cb.equal(root.get("kentta").get("nimi"), nimi); Predicate whereClause = cb.and(organisaatioEquals, nameEquals); query.where(whereClause);/*from w w w.ja va 2s .co m*/ return getEntityManager().createQuery(query).getSingleResult(); // Organisaatio org = organisaatioDAO.findBy("oid", organisaatioOid).get(0); // Query query = getEntityManager().createQuery("SELECT x FROM YhteystietoArvo x " + // "WHERE x.kentta.nimi = :nimi AND x.organisaatio.id = :organisaatioId"); // query.setParameter("nimi", nimi); // query.setParameter("organisaatioId", org.getId()); // return (YhteystietoArvo) query.getSingleResult(); }
From source file:org.sloth.persistence.impl.ReportDaoImpl.java
@Override public Collection<Report> getAll() { CriteriaQuery<Report> cq = getEntityManager().getCriteriaBuilder().createQuery(Report.class); cq.select(cq.from(Report.class)); Collection<Report> list = getEntityManager().createQuery(cq).getResultList(); logger.info("Getting all Reports; Found: {}", list.size()); return list;//from w w w . j a va 2s.c o m }
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 . j av a 2 s . com*/ 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:com.fantasy.stataggregator.workers.StatCompilerTask.java
@Override public void setYear(int year) throws Exception { this.year = year; GameDataRepository gdr = ctx.getBean(GameDataRepository.class); if (year == Integer.MAX_VALUE) { gamesData = gdr.findAll();// ww w .j a v a2s .com } else { SimpleDateFormat sdf = ctx.getBean(SimpleDateFormat.class); sdf.applyLocalizedPattern("yyyyMMdd"); Date min = sdf.parse(year + START_OF_YEAR); Date max = sdf.parse(year + END_OF_YEAR); CriteriaBuilder cb = gdr.getCriteriaBuilder(); CriteriaQuery<GameData> cq = gdr.getCriteriaQuery(); Root<GameData> gameData = gdr.getRoot(); Path<GameDataPK> pk = gameData.get(GameData_.gameDataPK); cq.select(gameData).where(cb.equal(pk.get(GameDataPK_.year), year)) .orderBy(cb.asc(pk.get(GameDataPK_.gameIdentifier))); gamesData = gdr.getCriteriaList(cq); System.out.println(gamesData.size()); } }