List of usage examples for javax.persistence.criteria Root as
<X> Expression<X> as(Class<X> type);
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Find the Root with type class on CriteriaQuery Root Set * @param <T> root type/* w ww . j av a 2 s . c o m*/ * @param query criteria query * @param clazz root type * @return Root<T> of null if none */ @SuppressWarnings("unchecked") public static <T> Root<T> findRoot(CriteriaQuery<?> query, Class<T> clazz) { for (Root<?> r : query.getRoots()) { if (clazz.equals(r.getJavaType())) { return (Root<T>) r.as(clazz); } } return (Root<T>) query.getRoots().iterator().next(); }
From source file:com.zero.dao.impl.BaseDaoImpl.java
private Root<T> getRoot(CriteriaQuery<?> criteriaQuery, Class<T> clazz) { if (criteriaQuery != null && criteriaQuery.getRoots() != null && clazz != null) { for (Root<?> root : criteriaQuery.getRoots()) { if (clazz.equals(root.getJavaType())) { return (Root<T>) root.as(clazz); }// w w w .java2 s . c om } } 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) {/*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:org.agric.oxm.utils.JpaUtils.java
/** * Find the Root with type class on CriteriaQuery Root Set * /*from w w w.j a va 2 s. c o m*/ * @param <T> * root type * @param query * criteria query * @param clazz * root type * @return Root<T> of null if none */ public static <T> Root<T> findRoot(CriteriaQuery<?> query, Class<T> clazz) { for (Root<?> r : query.getRoots()) { if (clazz.equals(r.getJavaType())) { return (Root<T>) r.as(clazz); } } return null; }