List of usage examples for javax.persistence.criteria CriteriaQuery from
<X> Root<X> from(Class<X> entityClass);
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 o m*/ 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.j av a2 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(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.ja va2 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_.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;/*from ww w. ja v a2 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 www . j av a2 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_.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 List<User> getAllUsersByDescendingSkillCount(int first, int count) { logger.infof("loading all Users ordered by ascending name ..."); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> criteria = cb.createQuery(User.class); Root<User> root = criteria.from(User.class); criteria.orderBy(cb.desc(root.get(User_.skillCount))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:org.businessmanager.dao.GenericDaoImpl.java
@Override public List<T> findAll(SingularAttribute<T, ?> orderAttribute, boolean orderAsc, int firstResult, int maxResults, Map<SingularAttribute<T, ?>, Object> filterAttributes, boolean enableLikeSearch) { CriteriaBuilder queryBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = queryBuilder.createQuery(getPersistenceClass()); Root<T> rootQuery = criteriaQuery.from(getPersistenceClass()); CriteriaQuery<T> select = criteriaQuery.select(rootQuery); List<Predicate> predicateList = createFilterList(filterAttributes, enableLikeSearch, queryBuilder, rootQuery);//from w w w.j a v a 2 s . co m select.where(predicateList.toArray(new Predicate[0])); if (orderAsc) { criteriaQuery.orderBy(queryBuilder.asc(rootQuery.get(orderAttribute))); } else { criteriaQuery.orderBy(queryBuilder.desc(rootQuery.get(orderAttribute))); } TypedQuery<T> typedQuery = entityManager.createQuery(criteriaQuery); if (firstResult != -1) { typedQuery.setFirstResult(firstResult); } if (maxResults != -1) { typedQuery.setMaxResults(maxResults); } return typedQuery.getResultList(); }
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 w w.j a 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.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 long countAllFiltered(final UserFilterStructure filter) { logger.infof("counting all Users matching the filter %s ...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> criteria = cb.createQuery(Long.class); Root<User> from = criteria.from(User.class); List<Predicate> predicates = getFilterPredicates(filter, cb, from); if (!predicates.isEmpty()) { criteria.where(cb.and(predicates.toArray(new Predicate[predicates.size()]))); }/*from www . j a v a2s . com*/ criteria.select(cb.countDistinct(from)); return em.createQuery(criteria).getSingleResult(); }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getAllByAscendingNameFiltered(UserFilterStructure filter, int first, int count) { logger.infof("loading all Users ordered by ascending name matching the given filter %s...", filter); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<User> criteria = cb.createQuery(User.class); Root<User> root = criteria.from(User.class); List<Predicate> predicates = getFilterPredicates(filter, cb, root); if (!predicates.isEmpty()) { criteria.where(cb.and(predicates.toArray(new Predicate[predicates.size()]))); }/*from w w w .j ava 2 s. co m*/ criteria.orderBy(cb.asc(root.get(User_.lastName)), cb.asc(root.get(User_.firstName))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }