List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:eu.uqasar.service.user.UserService.java
public User getByFullName(final String fullName) { logger.infof("loading User with fullName %s ...", fullName); User entity = null;//from w ww .jav a 2s.c om CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.equal(cb.lower(cb.concat(root.get(User_.firstName), root.get(User_.lastName))), fullName.toLowerCase())); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:eu.uqasar.service.user.UserService.java
public User getByPWResetToken(final String token) { if (token == null || token.isEmpty()) { return null; }/*w w w . j a va 2s.c o m*/ logger.infof("retrievung User with password reset token %s ...", token); User entity = null; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.equal(root.get(User_.resetPWRequestToken), token)); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:$.MemberDaoImpl.java
public Member findByEmail(String email) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = cb.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); /*/*w w w . ja va 2 s. co m*/ * Swap criteria statements if you would like to try out type-safe criteria queries, a new * feature in JPA 2.0 criteria.select(member).orderBy(cb.asc(member.get(Member_.name))); */ criteria.select(member).where(cb.equal(member.get("email"), email)); return em.createQuery(criteria).getSingleResult(); }
From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java
public List<Users> getAllUsers() { try {/*from ww w .ja v a2 s . c om*/ // get all non-deleted users CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Users> cq = cb.createQuery(Users.class); Root<Users> c = cq.from(Users.class); Predicate condition = cb.equal(c.get("deleted"), "false"); cq.where(condition); TypedQuery<Users> q = em.createQuery(cq); List<Users> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getAllUsers] ", ex2); } return null; }
From source file:eu.uqasar.service.user.UserService.java
public boolean ldapBasedUserExists(final LdapUser user) { logger.infof("looking for users with username %s or mail %s", user.getUserName(), user.getMail()); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); Predicate userName = cb.equal(root.get(User_.userName), user.getUserName()); Predicate mail = cb.equal(root.get(User_.mail), user.getMail()); query.where(cb.or(userName, mail));/*from w w w . j a va2 s . c o m*/ List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); return !resultList.isEmpty(); }
From source file:eu.uqasar.service.user.UserService.java
public User getLdapBasedUser(final LdapUser user) { logger.infof("looking for LDAP users with username %s or mail %s", user.getUserName(), user.getMail()); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); Predicate userName = cb.equal(root.get(User_.userName), user.getUserName()); Predicate mail = cb.equal(root.get(User_.mail), user.getMail()); query.where(cb.and(cb.or(userName, mail))); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); return resultList.isEmpty() ? null : resultList.get(0); }
From source file:com.sfs.captor.controller.ProjectPackageAction.java
/** * Load project packages/*from www . j a v a2 s . c o m*/ */ 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:eu.uqasar.service.user.UserService.java
public User getByLdapLogin(final String userName) { logger.infof("loading LDAP-based User with username %s ...", userName); User entity = null;//from ww w .j a va 2 s . co m CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.and(cb.equal(root.get(User_.userName), userName), cb.equal(root.get(User_.source), UserSource.LDAP))); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:eu.uqasar.service.user.UserService.java
public User getByRegistrationTokenAndRegistrationStatus(final String token, final RegistrationStatus status) { logger.infof("retrievung User with registration token %s ...", token); User entity = null;/*from w w w. java 2s. co m*/ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.and(cb.equal(root.get(User_.registrationToken), token), cb.equal(root.get(User_.registrationStatus), status))); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
/** * @see com.qpark.eip.core.spring.lockedoperation.dao.LockableOperationDao#unlockOperationOnServerStart() *//* w w w.j av a 2 s.co 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(); } }