List of usage examples for javax.persistence.criteria CriteriaBuilder createQuery
<T> CriteriaQuery<T> createQuery(Class<T> resultClass);
CriteriaQuery
object with the specified result type. From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.ConferenceUserDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { this.emailParameter = this.createParameterExpression(String.class, "email"); this.getUsersByPrimaryEmailQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<ConferenceUserImpl>>() { @Override// w ww .j av a 2s . c o m public CriteriaQuery<ConferenceUserImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<ConferenceUserImpl> criteriaQuery = cb .createQuery(ConferenceUserImpl.class); final Root<ConferenceUserImpl> definitionRoot = criteriaQuery .from(ConferenceUserImpl.class); criteriaQuery.select(definitionRoot); criteriaQuery .where(cb.equal(definitionRoot.get(ConferenceUserImpl_.email), emailParameter)); return criteriaQuery; } }); this.getUsersByAnyEmailQuery = this .createCriteriaQuery(new Function<CriteriaBuilder, CriteriaQuery<ConferenceUserImpl>>() { @Override public CriteriaQuery<ConferenceUserImpl> apply(CriteriaBuilder cb) { final CriteriaQuery<ConferenceUserImpl> criteriaQuery = cb .createQuery(ConferenceUserImpl.class); final Root<ConferenceUserImpl> definitionRoot = criteriaQuery .from(ConferenceUserImpl.class); criteriaQuery.select(definitionRoot); criteriaQuery.where( cb.or(cb.equal(definitionRoot.get(ConferenceUserImpl_.email), emailParameter), cb.isMember(emailParameter, definitionRoot.get(ConferenceUserImpl_.additionalEmails)))); return criteriaQuery; } }); }
From source file:fr.amapj.service.services.authentification.PasswordManager.java
/** * Retrouve l'utilisateur avec cet e-mail * Retourne null si non trouv ou autre problme *//* w w w . ja va 2 s. c o m*/ private Utilisateur findUser(String email, EntityManager em) { if ((email == null) || email.equals("")) { return null; } CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Utilisateur> cq = cb.createQuery(Utilisateur.class); Root<Utilisateur> root = cq.from(Utilisateur.class); // On ajoute la condition where cq.where(cb.equal(root.get(Utilisateur.P.EMAIL.prop()), email)); List<Utilisateur> us = em.createQuery(cq).getResultList(); if (us.size() == 0) { return null; } if (us.size() > 1) { logger.warn("Il y a plusieurs utilisateurs avec l'adresse " + email); return null; } return us.get(0); }
From source file:com.sfs.captor.controller.ProductReleaseAction.java
/** * load product releases//from w ww . j a v a 2s . c o m */ private void loadList() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ProductRelease> c = cb.createQuery(ProductRelease.class); Root<ProductRelease> obj = c.from(ProductRelease.class); c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id"))); this.productReleases = em.createQuery(c).getResultList(); }
From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
/** * @see com.qpark.eip.core.spring.lockedoperation.dao.LockableOperationDao#unlockOperationOnServerStart() *//*from w ww . ja v a2 s. c o m*/ @Override @Transactional(value = EipLockedoperationConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public void unlockOperationOnServerStart() { CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<OperationLockControllType> q = cb.createQuery(OperationLockControllType.class); Root<OperationLockControllType> c = q.from(OperationLockControllType.class); q.where(cb.equal(c.<String>get("serverName"), this.hostName)); TypedQuery<OperationLockControllType> typedQuery = this.em.createQuery(q); try { List<OperationLockControllType> locks = typedQuery.getResultList(); for (OperationLockControllType lock : locks) { this.logger.debug(" remove lock on server start (this {}): {} {}", this.hostName, lock.getServerName(), lock.getLockDate()); this.em.remove(this.em.merge(lock)); } } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceTypeDomainService.java
private Query applicationServersForSuggestBox(String input) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<String> q = cb.createQuery(String.class); Root<ResourceEntity> r = q.from(ResourceEntity.class); Join<ResourceEntity, ResourceTypeEntity> resType = r.join("resourceType"); Predicate appServerNamePred = cb.like(resType.<String>get("name"), DefaultResourceTypeDefinition.APPLICATIONSERVER.name()); input = input + "%"; q.where(cb.and(appServerNamePred, cb.like(r.<String>get("name"), input))); q.select(r.<String>get("name")); q.distinct(true);/*w ww .j a v a 2 s. c om*/ q.orderBy(cb.asc(r.get("name"))); return entityManager.createQuery(q); }
From source file:dk.dma.msinm.common.settings.Settings.java
/** * Returns all settings from the database * @return all settings from the database *//*from ww w . java2 s .co m*/ public List<SettingsEntity> getAll() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<SettingsEntity> cq = cb.createQuery(SettingsEntity.class); cq.from(SettingsEntity.class); return em.createQuery(cq).getResultList(); }
From source file:name.marcelomorales.siqisiqi.openjpa.impl.OrmFinderImpl.java
@Override @TransactionAttribute//from w w w . j av a 2 s.co m public long countByAttribute(String attributeName, Object attributeValue) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> q = cb.createQuery(Long.class); Root<T> p = q.from(persistentClass); final Expression<Long> count = newCountExpression(cb, p); q.select(count); q.where(cb.equal(p.get(attributeName), attributeValue)); try { return entityManager.createQuery(q).getSingleResult(); } catch (NoResultException e) { return 0; } }
From source file:com.vladmihalcea.HibernateCriteriaTest.java
private Product getProduct_Mercilessly() { return transactionTemplate.execute(new TransactionCallback<Product>() { @Override/*w w w . j av a 2 s. c om*/ public Product doInTransaction(TransactionStatus transactionStatus) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Product> query = cb.createQuery(Product.class); Root<Product> productRoot = query.from(Product.class); query.select(productRoot) .where(cb.and(cb.equal(productRoot.get(Product_.code), "tvCode"), cb.gt( productRoot.get(Product_.warehouseProductInfo).get(WarehouseProductInfo_.quantity), 50))); return entityManager.createQuery(query).getSingleResult(); } }); }
From source file:com.vladmihalcea.HibernateCriteriaTest.java
private Product getProduct_Mercifully() { return transactionTemplate.execute(new TransactionCallback<Product>() { @Override/*from ww w.j a v a 2s .c om*/ public Product doInTransaction(TransactionStatus transactionStatus) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Product> query = cb.createQuery(Product.class); Root<Product> productRoot = query.from(Product.class); Join<Product, WarehouseProductInfo> warehouseProductInfoJoin = productRoot .join(Product_.warehouseProductInfo); query.select(productRoot).where(cb.and(cb.equal(productRoot.get(Product_.code), "tvCode"), cb.gt(warehouseProductInfoJoin.get(WarehouseProductInfo_.quantity), 50))); return entityManager.createQuery(query).getSingleResult(); } }); }
From source file:fr.amapj.service.services.authentification.PasswordManager.java
/** * Retrouve l'utilisateur avec ce resetPasswordSald * Retourne null si non trouv ou autre problme *//* w w w . j a v a 2s . co m*/ @DbRead public Utilisateur findUserWithResetPassword(String resetPasswordSalt) { EntityManager em = TransactionHelper.getEm(); if ((resetPasswordSalt == null) || resetPasswordSalt.equals("")) { return null; } CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Utilisateur> cq = cb.createQuery(Utilisateur.class); Root<Utilisateur> root = cq.from(Utilisateur.class); // On ajoute la condition where cq.where(cb.equal(root.get(Utilisateur.P.RESETPASSWORDSALT.prop()), resetPasswordSalt)); List<Utilisateur> us = em.createQuery(cq).getResultList(); if (us.size() == 0) { return null; } if (us.size() > 1) { logger.warn("Il y a plusieurs utilisateurs avec le salt " + resetPasswordSalt); return null; } Utilisateur u = us.get(0); if (u.getEtatUtilisateur() == EtatUtilisateur.INACTIF) { return null; } return u; }