List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
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 ww.jav a2s .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_.mail), mail)); List<User> resultList = em.createQuery(query).setMaxResults(1).getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return entity; }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override @Transactional(value = "defaultTransactionManager") public void clearDuplicateRefreshTokens() { Query query = manager.createQuery( "select a.jwt, count(1) as c from OAuth2RefreshTokenEntity a GROUP BY a.jwt HAVING c > 1"); @SuppressWarnings("unchecked") List<Object[]> resultList = query.getResultList(); List<JWT> values = new ArrayList<>(); for (Object[] r : resultList) { logger.warn("Found duplicate refresh tokens: {}, {}", ((JWT) r[0]).serialize(), r[1]); values.add((JWT) r[0]);//from w ww .ja va2 s . c om } if (values.size() > 0) { CriteriaBuilder cb = manager.getCriteriaBuilder(); CriteriaDelete<OAuth2RefreshTokenEntity> criteriaDelete = cb .createCriteriaDelete(OAuth2RefreshTokenEntity.class); Root<OAuth2RefreshTokenEntity> root = criteriaDelete.from(OAuth2RefreshTokenEntity.class); criteriaDelete.where(root.get("jwt").in(values)); int result = manager.createQuery(criteriaDelete).executeUpdate(); logger.warn("Deleted {} duplicate refresh tokens", result); } }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getAllByAscendingName(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.asc(root.get(User_.lastName)), cb.asc(root.get(User_.firstName))); return em.createQuery(criteria).setFirstResult(first).setMaxResults(count).getResultList(); }
From source file:eu.uqasar.service.user.UserService.java
public List<User> getAllExceptOne(User user) { if (user == null) { return this.getAll(); }/*from w w w . ja v a 2s . 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:com.aimdek.ccm.dao.impl.BulkUploadRepositoryImpl.java
/** * Adds the filter criteria./*from w w w .j a v a2 s . co m*/ * * @param filters * the filters * @param query * the query */ private void addFilterCriteria(Map<String, Object> filters, CriteriaBuilder builder, Root<BulkUpload> root, CriteriaQuery query) { if (!filters.isEmpty()) { List<Predicate> predicates = new ArrayList<Predicate>(); for (Entry<String, Object> entry : filters.entrySet()) { if (CommonUtil.isNotNull(root.get(entry.getKey()))) { predicates.add(builder.like(root.<String>get(entry.getKey()), entry.getValue() + MODULO)); } } query.where(predicates.toArray(new Predicate[] {})); } }
From source file:eu.uqasar.service.user.UserService.java
public User getByPWResetToken(final String token) { if (token == null || token.isEmpty()) { return null; }//from w w w . j a v a2 s .c om 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: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 va 2s . 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: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: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 ww w . j ava2 s. co 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); }