List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:com.ims.service.OrderService.java
public List<PurchaseOrder> searchPurchaseOrderList(final OrderSearchCriteria orderSearchCriteria) { List<PurchaseOrder> purchaseOrders = new ArrayList<PurchaseOrder>(); Specification<PurchaseOrder> speci = new Specification<PurchaseOrder>() { @Override//from ww w.ja va 2s . com public Predicate toPredicate(Root<PurchaseOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<Predicate>(); if (StringUtils.isNotEmpty(orderSearchCriteria.getPurchaseOrderStatus())) { predicates.add(cb.equal(root.get("status"), orderSearchCriteria.getPurchaseOrderStatus())); } if (StringUtils.isNotEmpty(orderSearchCriteria.getPurchaseOrderNum())) { predicates.add(cb.like(root.<String>get("purchaseOrderNumber"), "%" + orderSearchCriteria.getPurchaseOrderNum() + "%")); } if (StringUtils.isNotEmpty(orderSearchCriteria.getProformaInvoiceNum())) { predicates.add(cb.like(root.<String>get("piNumber"), "%" + orderSearchCriteria.getProformaInvoiceNum() + "%")); } query.where(cb.and(predicates.toArray(new Predicate[predicates.size()]))) .orderBy(cb.desc(root.get("changeLog").get("createdDate"))); return null; } }; return purchaseOrderRepository.findAll(speci); }
From source file:com.sfs.captor.controller.ProjectPackageAction.java
/** * Load project packages/*from ww w.j a v a2s. c om*/ */ private void loadList() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ProjectPackage> c = cb.createQuery(ProjectPackage.class); Root<ProjectPackage> obj = c.from(ProjectPackage.class); c.select(obj).where(cb.equal(obj.get("project"), this.project)).orderBy(cb.asc(obj.get("id"))); this.projectPackages = em.createQuery(c).getResultList(); }
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 w w w . jav 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.equal(root.get(User_.company), company)); return em.createQuery(query).getResultList(); }
From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java
public List<Users> getAllUsers() { try {/*w ww. j a v a 2 s . co m*/ // get all non-deleted users CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Users> cq = cb.createQuery(Users.class); Root<Users> c = cq.from(Users.class); Predicate condition = cb.equal(c.get("deleted"), "false"); cq.where(condition); TypedQuery<Users> q = em.createQuery(cq); List<Users> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getAllUsers] ", ex2); } return null; }
From source file:net.groupbuy.dao.impl.ReviewDaoImpl.java
public Page<Review> findPage(Member member, Product product, Type type, Boolean isShow, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Review> criteriaQuery = criteriaBuilder.createQuery(Review.class); Root<Review> root = criteriaQuery.from(Review.class); criteriaQuery.select(root);// w w w.j av a 2s . c om Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (product != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product)); } if (type == Type.positive) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number>get("score"), 4)); } else if (type == Type.moderate) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.<Number>get("score"), 3)); } else if (type == Type.negative) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number>get("score"), 2)); } if (isShow != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow)); } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }
From source file:net.groupbuy.dao.impl.ReviewDaoImpl.java
public Long count(Member member, Product product, Type type, Boolean isShow) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Review> criteriaQuery = criteriaBuilder.createQuery(Review.class); Root<Review> root = criteriaQuery.from(Review.class); criteriaQuery.select(root);/*from w w w. j a v a 2s.c om*/ Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (product != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product)); } if (type == Type.positive) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number>get("score"), 4)); } else if (type == Type.moderate) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.<Number>get("score"), 3)); } else if (type == Type.negative) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number>get("score"), 2)); } if (isShow != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java
@Override @Transactional(value = "defaultTransactionManager") public void clearDuplicateAccessTokens() { Query query = manager.createQuery( "select a.jwt, count(1) as c from OAuth2AccessTokenEntity 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 access tokens: {}, {}", ((JWT) r[0]).serialize(), r[1]); values.add((JWT) r[0]);/*w w w.java2 s . c o m*/ } if (values.size() > 0) { CriteriaBuilder cb = manager.getCriteriaBuilder(); CriteriaDelete<OAuth2AccessTokenEntity> criteriaDelete = cb .createCriteriaDelete(OAuth2AccessTokenEntity.class); Root<OAuth2AccessTokenEntity> root = criteriaDelete.from(OAuth2AccessTokenEntity.class); criteriaDelete.where(root.get("jwt").in(values)); int result = manager.createQuery(criteriaDelete).executeUpdate(); logger.warn("Deleted {} duplicate access tokens", result); } }
From source file:net.groupbuy.dao.impl.MessageDaoImpl.java
public Long count(Member member, Boolean read) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Message> criteriaQuery = criteriaBuilder.createQuery(Message.class); Root<Message> root = criteriaQuery.from(Message.class); criteriaQuery.select(root);//w ww . j av a 2 s . co m Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forMessage")), criteriaBuilder.equal(root.get("isDraft"), false)); if (member != null) { if (read != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or( criteriaBuilder.and(criteriaBuilder.equal(root.get("sender"), member), criteriaBuilder.equal(root.get("senderDelete"), false), criteriaBuilder.equal(root.get("senderRead"), read)), criteriaBuilder.and(criteriaBuilder.equal(root.get("receiver"), member), criteriaBuilder.equal(root.get("receiverDelete"), false), criteriaBuilder.equal(root.get("receiverRead"), read)))); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or( criteriaBuilder.and(criteriaBuilder.equal(root.get("sender"), member), criteriaBuilder.equal(root.get("senderDelete"), false)), criteriaBuilder.and(criteriaBuilder.equal(root.get("receiver"), member), criteriaBuilder.equal(root.get("receiverDelete"), false)))); } } else { if (read != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or( criteriaBuilder.and(criteriaBuilder.isNull(root.get("sender")), criteriaBuilder.equal(root.get("senderDelete"), false), criteriaBuilder.equal(root.get("senderRead"), read)), criteriaBuilder.and(criteriaBuilder.isNull(root.get("receiver")), criteriaBuilder.equal(root.get("receiverDelete"), false), criteriaBuilder.equal(root.get("receiverRead"), read)))); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or( criteriaBuilder.and(criteriaBuilder.isNull(root.get("sender")), criteriaBuilder.equal(root.get("senderDelete"), false)), criteriaBuilder.and(criteriaBuilder.isNull(root.get("receiver")), criteriaBuilder.equal(root.get("receiverDelete"), false)))); } } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:net.groupbuy.dao.impl.ReviewDaoImpl.java
public List<Review> findList(Member member, Product product, Type type, Boolean isShow, Integer count, List<Filter> filters, List<Order> orders) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Review> criteriaQuery = criteriaBuilder.createQuery(Review.class); Root<Review> root = criteriaQuery.from(Review.class); criteriaQuery.select(root);//from ww w .j a va2 s . c o m Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (product != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product)); } if (type == Type.positive) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.ge(root.<Number>get("score"), 4)); } else if (type == Type.moderate) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.<Number>get("score"), 3)); } else if (type == Type.negative) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.le(root.<Number>get("score"), 2)); } if (isShow != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow)); } criteriaQuery.where(restrictions); return super.findList(criteriaQuery, null, count, filters, orders); }
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;/* w w w .j a va 2s .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; }