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 getByLdapLogin(final String userName) { logger.infof("loading LDAP-based User with username %s ...", userName); User entity = null;/* w ww . jav 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 w w w .j ava 2s. c om 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:fr.amapj.service.services.authentification.PasswordManager.java
/** * Retrouve l'utilisateur avec ce resetPasswordSald * Retourne null si non trouv ou autre problme *///from www . j a v a 2s . co m @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:eu.uqasar.service.ProcessService.java
private List<Predicate> getFilterPredicates(final ProcessesFilterStructure filter, CriteriaBuilder cb, Root<Process> from) { List<Predicate> predicates = new ArrayList<>(); if (filter == null) { return predicates; }/* ww w . j a va 2 s. c o m*/ if (filter.getStartDate() != null) { predicates.add(cb.equal(from.get(Process_.startDate), filter.getStartDate())); } if (filter.getEndDate() != null) { predicates.add(cb.equal(from.get(Process_.endDate), filter.getEndDate())); } if (!StringUtils.isEmpty(filter.getName())) { Predicate firstName = cb.like(cb.lower(from.get(Process_.name)), LIKE_WILDCARD + filter.getName().toLowerCase() + LIKE_WILDCARD); predicates.add((firstName)); } return predicates; }
From source file:com.order.erp.web.controller.SystemController.java
@RequestMapping(path = "amoeba", method = RequestMethod.GET) public String amoebaIndex(HttpServletRequest request, @RequestParam(name = "keyword", required = false) String keyword, @PageableDefault(page = 0, size = 10, sort = "id", direction = Direction.ASC) Pageable pageable, ModelMap model) {/*from w ww . j a v a 2s . co m*/ Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); User me = staffService.findByAccountUsername(((UserDetails) principal).getUsername()); Company company = me.getCompany(); final String finalKeyword = keyword; final Company finalCompany = company; Page<Amoeba> page = adminService.findAmoebas(new Specification<Amoeba>() { public Predicate toPredicate(Root<Amoeba> root, CriteriaQuery<?> query, CriteriaBuilder cb) { query.distinct(true); Predicate p1 = cb.equal(root.get("company").as(Company.class), finalCompany); Predicate p2 = cb.conjunction(); if (StringUtils.isNotBlank(finalKeyword)) { p2 = cb.like(root.get("name").as(String.class), "%" + finalKeyword + "%"); } Predicate p_result = cb.and(p1, p2); return p_result; } }, pageable); model.put("user", me); model.put("company", company); model.put("page", page); String json = JSON.toJSONString(page, SerializerFeature.PrettyFormat); System.out.println(json); return "/system/amoeba_list"; }
From source file:org.openmeetings.app.data.basic.Configurationmanagement.java
public List<Configuration> getConfigurations(int start, int max, String orderby, boolean asc) { try {/* w ww. ja v a2 s. co m*/ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class); Root<Configuration> c = cq.from(Configuration.class); Predicate condition = cb.equal(c.get("deleted"), "false"); cq.where(condition); cq.distinct(asc); if (asc) { cq.orderBy(cb.asc(c.get(orderby))); } else { cq.orderBy(cb.desc(c.get(orderby))); } TypedQuery<Configuration> q = em.createQuery(cq); q.setFirstResult(start); q.setMaxResults(max); List<Configuration> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getConfigurations]", ex2); } return null; }
From source file:com.order.erp.web.controller.SystemController.java
@RequestMapping(path = "staff", method = RequestMethod.GET) public String staffIndex(HttpServletRequest request, @RequestParam(name = "keyword", required = false) String keyword, @PageableDefault(page = 0, size = 10, sort = "id", direction = Direction.ASC) Pageable pageable, ModelMap model) {/*from w w w . ja v a 2 s .c o m*/ Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); User me = staffService.findByAccountUsername(((UserDetails) principal).getUsername()); Company company = me.getCompany(); //List<User> userList = userService.findUsersByAmoebaId(company.getId()); final User meStaff = me; final String finalKeyword = keyword; final Company finalCompany = company; Page<User> page = staffService.findUsers(new Specification<User>() { public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) { query.distinct(true); Predicate p1 = cb.equal(root.get("company").as(Company.class), finalCompany); Predicate p2 = cb.conjunction(); if (StringUtils.isNotBlank(finalKeyword)) { Predicate p1_like = cb.like(root.get("account").get("username").as(String.class), "%" + finalKeyword + "%"); Predicate p2_like = cb.like(root.get("realname").as(String.class), "%" + finalKeyword + "%"); p2 = cb.or(p1_like, p2_like); } Predicate p3 = cb.notEqual(root.as(User.class), meStaff); Predicate p_result = cb.and(p1, p2, p3); return p_result; } }, pageable); model.put("user", me); model.put("company", company); model.put("page", page); return "/system/staff_list"; }
From source file:bq.jpa.demo.query.criteria.service.CriteriaService.java
/** * order by:/*from w w w. jav a 2s . c o m*/ * SELECT e.name, e.salary FROM jpa_query_employee e ORDER BY e.name DESC, e.salary DESC */ public void doOrderby() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Object[]> c = cb.createQuery(Object[].class); Root<Employee> e = c.from(Employee.class); c.multiselect(e.get("name"), e.get("salary")).orderBy(cb.desc(e.get("name")), cb.desc(e.get("salary"))); showResult(c); }
From source file:com.expressui.sample.dao.query.OpportunityQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Opportunity> query, Root<Opportunity> opportunity) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(accountName)) { ParameterExpression<String> accountNameExp = builder.parameter(String.class, "accountName"); predicates.add(//from www .ja v a2 s . co m builder.like(builder.upper(opportunity.get("account").<String>get("name")), accountNameExp)); } if (hasValue(salesStages)) { ParameterExpression<Set> salesStagesExp = builder.parameter(Set.class, "salesStages"); predicates.add(builder.in(opportunity.get("salesStage")).value(salesStagesExp)); } return predicates; }
From source file:com.vladmihalcea.HibernateCriteriaTest.java
private Product getProduct_Mercilessly() { return transactionTemplate.execute(new TransactionCallback<Product>() { @Override/*from www . ja va 2s . co m*/ public Product doInTransaction(TransactionStatus transactionStatus) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Product> query = cb.createQuery(Product.class); Root<Product> productRoot = query.from(Product.class); query.select(productRoot) .where(cb.and(cb.equal(productRoot.get(Product_.code), "tvCode"), cb.gt( productRoot.get(Product_.warehouseProductInfo).get(WarehouseProductInfo_.quantity), 50))); return entityManager.createQuery(query).getSingleResult(); } }); }