List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
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 *//*from w w w . j a v a2 s .c om*/ 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.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
/** * @see com.qpark.eip.core.spring.lockedoperation.dao.LockableOperationDao#unlockOperation(com.qpark.eip.core.spring.lockedoperation.LockableOperation) *//* w w w .j a v a 2s. c o m*/ @Override @Transactional(value = EipLockedoperationConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public boolean unlockOperation(final LockableOperation operation) { this.logger.debug("+unlock# {} {} {}", new Object[] { this.hostName, operation.getUUID(), operation.getName() }); boolean unlocked = false; String logString = getOperationLockString(operation); 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("operationName"), logString)); TypedQuery<OperationLockControllType> typedQuery = this.em.createQuery(q); try { List<OperationLockControllType> locks = typedQuery.getResultList(); for (OperationLockControllType lock : locks) { this.em.remove(this.em.merge(lock)); } unlocked = true; } catch (Exception e) { e.printStackTrace(); } finally { this.logger.debug("-unlock# {} {} {} {}", new Object[] { this.hostName, unlocked ? "unlocked" : "not unlocked", operation.getUUID(), operation.getName() }); } return unlocked; }
From source file:net.shopxx.dao.impl.ProductNotifyDaoImpl.java
public Long count(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root);/*from w w w.java 2s .c o m*/ Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("goods").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
/** * @see com.qpark.eip.core.spring.lockedoperation.dao.LockableOperationDao#isLockedByThisServer(com.qpark.eip.core.spring.lockedoperation.LockableOperation) *///from ww w. j a v a2s . c om @Override @Transactional(value = EipLockedoperationConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public synchronized boolean isLockedByThisServer(final LockableOperation operation) { boolean lockedByThisServer = false; OperationLockControllType value = null; String logString = getOperationLockString(operation); 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("operationName"), logString)); TypedQuery<OperationLockControllType> typedQuery = this.em.createQuery(q); try { value = typedQuery.getSingleResult(); if (value != null) { if (value.getServerIpAddress().equals(this.hostAddress)) { lockedByThisServer = true; } this.logger.debug(" isLockedByThisServer# {} opeation {} {} locked by: {} {}", new Object[] { lockedByThisServer, operation.getUUID(), operation.getName(), value.getServerName(), value.getLockDate() }); } } catch (NoResultException e) { lockedByThisServer = false; } catch (NonUniqueResultException e) { lockedByThisServer = false; } return lockedByThisServer; }
From source file:gr.abiss.calipso.jpasearch.specifications.BooleanPredicateFactory.java
/** * @see gr.abiss.calipso.jpasearch.jpa.search.specifications.IPredicateFactory#addPredicate(javax.persistence.criteria.Root, * javax.persistence.criteria.CriteriaBuilder, java.lang.String, * java.lang.Class, java.lang.String[]) *//* w ww . j av a2s . com*/ @Override public Predicate getPredicate(Root<Persistable> root, CriteriaBuilder cb, String propertyName, Class fieldType, String[] propertyValues) { Predicate predicate = null; if (!Boolean.class.isAssignableFrom(fieldType)) { throw new IllegalArgumentException( fieldType + " is not a subclass of Boolean for field: " + propertyName); } Boolean b = BooleanUtils.toBooleanObject(propertyValues[0]); if (b == null) { b = Boolean.FALSE; } predicate = cb.equal(root.<Boolean>get(propertyName), b); return predicate; }
From source file:net.shopxx.dao.impl.ProductNotifyDaoImpl.java
public Page<ProductNotify> findPage(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent, Pageable pageable) {/* w w w . ja va 2s . co m*/ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root); Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("goods").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }
From source file:net.groupbuy.dao.impl.ProductNotifyDaoImpl.java
public Long count(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root);//from ww w.ja va 2 s .com Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:fr.amapj.service.services.authentification.PasswordManager.java
/** * Retrouve l'utilisateur avec ce resetPasswordSald * Retourne null si non trouv ou autre problme *//*from w ww . ja v a2 s. c om*/ @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; }
From source file:net.dontdrinkandroot.persistence.dao.ExampleGeneratedIdEntityDaoImpl.java
@Override @Transactional(readOnly = true)/*from ww w . ja v a2 s.c o m*/ public List<ExampleGeneratedIdEntity> findByOtherText(final String text) { final CriteriaBuilder builder = this.getCriteriaBuilder(); final CriteriaQuery<ExampleGeneratedIdEntity> criteriaQuery = builder.createQuery(this.entityClass); criteriaQuery.distinct(true); final Root<ExampleGeneratedIdEntity> root = criteriaQuery.from(this.entityClass); final ListJoin<ExampleGeneratedIdEntity, ExampleIdEntity> join = root .join(ExampleGeneratedIdEntity_.otherEntities); criteriaQuery.where(builder.equal(join.get(ExampleIdEntity_.text), text)); return this.find(criteriaQuery); }
From source file:net.groupbuy.dao.impl.ProductNotifyDaoImpl.java
public Page<ProductNotify> findPage(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent, Pageable pageable) {// w w w.j a va 2 s . c o m CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root); Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }