List of usage examples for javax.persistence.criteria CriteriaQuery where
CriteriaQuery<T> where(Predicate... restrictions);
From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java
@Override public List<NetworkVO> list(String name, String namePattern, String sortField, boolean sortOrderAsc, Integer take, Integer skip, Optional<HivePrincipal> principal) { CriteriaBuilder cb = criteriaBuilder(); CriteriaQuery<Network> criteria = cb.createQuery(Network.class); Root<Network> from = criteria.from(Network.class); Predicate[] nameAndPrincipalPredicates = CriteriaHelper.networkListPredicates(cb, from, ofNullable(name), ofNullable(namePattern), principal); criteria.where(nameAndPrincipalPredicates); CriteriaHelper.order(cb, criteria, from, ofNullable(sortField), sortOrderAsc); TypedQuery<Network> query = createQuery(criteria); cacheQuery(query, of(CacheConfig.refresh())); ofNullable(take).ifPresent(query::setMaxResults); ofNullable(skip).ifPresent(query::setFirstResult); List<Network> result = query.getResultList(); Stream<NetworkVO> objectStream = result.stream().map(Network::convertNetwork); return objectStream.collect(Collectors.toList()); }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getByCompany(final Company company) { logger.infof("loading User with company %s ...", company); User entity = null;/*from www . ja v a 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.equal(root.get(User_.company), company)); return em.createQuery(query).getResultList(); }
From source file:csns.model.core.dao.jpa.UserDaoImpl.java
@Override public List<User> getUsers(Long ids[]) { if (ids == null || ids.length < 1) return new ArrayList<User>(); CriteriaBuilder cbuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<User> cquery = cbuilder.createQuery(User.class); Root<User> user = cquery.from(User.class); Predicate criteria = cbuilder.equal(user.get("id"), ids[0]); for (int i = 1; i < ids.length; ++i) criteria = cbuilder.or(criteria, cbuilder.equal(user.get("id"), ids[i])); cquery.where(criteria); cquery.orderBy(cbuilder.asc(user.get("lastName")), cbuilder.asc(user.get("firstName"))); return entityManager.createQuery(cquery).getResultList(); }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getAllExceptOne(User user) { if (user == null) { return this.getAll(); }//w ww .ja v a 2 s .c om List<User> users; logger.infof("loading all Users except %s ...", user); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> query = cb.createQuery(User.class); Root<User> root = query.from(User.class); query.where(cb.notEqual(root.get(User_.id), user.getId())); return em.createQuery(query).getResultList(); }
From source file:eu.uqasar.service.user.UserService.java
public User getByUserName(final String userName) { logger.infof("loading User with username %s ...", userName); User entity = null;//from w ww. ja v a 2 s.c om 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_.userName), userName)); 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 getByMail(final String mail) { logger.infof("loading User with mail %s ...", mail); User entity = null;/*from w w w .j a va 2s. co m*/ 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_.mail), mail)); 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 getByLdapLogin(final String userName) { logger.infof("loading LDAP-based User with username %s ...", userName); User entity = null;//ww w. j a va2 s . c o 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 ww .ja v a 2 s .com*/ 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: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 . j a v a 2 s.c o m 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:com.devicehive.dao.rdbms.UserDaoRdbmsImpl.java
@Override public List<UserVO> list(String login, String loginPattern, Integer role, Integer status, String sortField, Boolean sortOrderAsc, Integer take, Integer skip) { CriteriaBuilder cb = criteriaBuilder(); CriteriaQuery<User> cq = cb.createQuery(User.class); Root<User> from = cq.from(User.class); Predicate[] predicates = CriteriaHelper.userListPredicates(cb, from, ofNullable(login), ofNullable(loginPattern), ofNullable(role), ofNullable(status)); cq.where(predicates); CriteriaHelper.order(cb, cq, from, ofNullable(sortField), Boolean.TRUE.equals(sortOrderAsc)); TypedQuery<User> query = createQuery(cq); cacheQuery(query, of(CacheConfig.refresh())); ofNullable(take).ifPresent(query::setMaxResults); ofNullable(skip).ifPresent(query::setFirstResult); return query.getResultList().stream().map(User::convertToVo).collect(Collectors.toList()); }