List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:net.groupbuy.dao.impl.NavigationDaoImpl.java
public List<Navigation> findList(Position position) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Navigation> criteriaQuery = criteriaBuilder.createQuery(Navigation.class); Root<Navigation> root = criteriaQuery.from(Navigation.class); criteriaQuery.select(root);/* ww w. ja v a2 s.co m*/ if (position != null) { criteriaQuery.where(criteriaBuilder.equal(root.get("position"), position)); } criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order"))); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:org.sloth.persistence.impl.ReportDaoImpl.java
@Override public Collection<Report> getByObservation(Observation o) throws NullPointerException, IllegalArgumentException { if (o == null) { throw new NullPointerException(); }//from ww w. j av a2s. c o m if (o.isNew()) { throw new IllegalArgumentException(); } CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<Report> cq = cb.createQuery(Report.class); Root<Report> r = cq.from(Report.class); cq.select(r).where(cb.equal(r.get(Report_.observation), o)); Collection<Report> result = getEntityManager().createQuery(cq).getResultList(); logger.info("{} Reports for Observation {}.", result.size(), o); return result; }
From source file:com.greendot.db.jpa.core.AbstractSearchDao.java
@Transactional(readOnly = true) public Optional<E> findByCharacterType(final String key, final String value) { notNull(key, "Mandatory argument 'key' is missing."); notNull(value, "Mandatory argument 'value' is missing."); final CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); final CriteriaQuery<E> query = builder.createQuery(getEntityType()); final Root<E> root = query.from(getEntityType()); query.select(root).where(builder.and(builder.equal(root.get(key), value))).distinct(true); final List<E> results = getEntityManager().createQuery(query).getResultList(); if ((results != null) && (results.size() == 1)) return Optional.of(results.get(0)); return Optional.empty(); }
From source file:com.moderndrummer.data.MemberDaoImpl.java
@Override public Member findByEmail(String email) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = builder.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); criteria.select(member).where(builder.equal(member.get("email"), email)); return em.createQuery(criteria).getSingleResult(); }
From source file:com.ims.service.ProductStockInfoService.java
public List<ProductStockInfo> findProdStockInfoListFrom(final ProdStockSearchCriteria stockSearchCriteria) { Specification<ProductStockInfo> speci = new Specification<ProductStockInfo>() { @Override//w w w.j ava 2 s.c o m public Predicate toPredicate(Root<ProductStockInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(cb.equal(root.get("stockType"), stockSearchCriteria.getStockType())); if (StringUtils.isNotEmpty(stockSearchCriteria.getProdCategoryCode())) { predicates.add(cb.equal(root.get("categoryCode"), stockSearchCriteria.getProdCategoryCode())); } if (StringUtils.isNotEmpty(stockSearchCriteria.getProdCode())) { predicates.add(cb.like(root.<String>get("productCode"), "%" + stockSearchCriteria.getProdCode() + "%")); } String compareCode = stockSearchCriteria.getCompareCode(); if (StringUtils.isNotEmpty(compareCode) && stockSearchCriteria.isIncludeComparedValue()) { Path<ProductAmount> productAmount = root.<ProductAmount>get("productAmount"); if (CompareCode.isEqual(compareCode)) { predicates.add( cb.equal(productAmount.get("totalAmount"), stockSearchCriteria.getStockAmount())); } else if (CompareCode.isGreater(compareCode)) { predicates.add(cb.greaterThan(productAmount.<Integer>get("totalAmount"), stockSearchCriteria.getStockAmount())); } else if (CompareCode.isLess(compareCode)) { predicates.add(cb.lessThan(productAmount.<Integer>get("totalAmount"), stockSearchCriteria.getStockAmount())); } else if (CompareCode.isGreaterOrEqual(compareCode)) { predicates.add(cb.greaterThanOrEqualTo(productAmount.<Integer>get("totalAmount"), stockSearchCriteria.getStockAmount())); } else if (CompareCode.isLessOrEqual(compareCode)) { predicates.add(cb.lessThanOrEqualTo(productAmount.<Integer>get("totalAmount"), stockSearchCriteria.getStockAmount())); } else if (CompareCode.isEqualAlertAmount(compareCode)) { predicates.add(cb.equal(productAmount.get("totalAmount"), root.get("alertStockAmount"))); } else if (CompareCode.isGreaterThanAlertAmount(compareCode)) { predicates.add(cb.greaterThan(productAmount.<String>get("totalAmount"), root.<String>get("alertStockAmount"))); } else if (CompareCode.isLessThanAlertAmount(compareCode)) { predicates.add(cb.lessThan(productAmount.<String>get("totalAmount"), root.<String>get("alertStockAmount"))); } if (stockSearchCriteria.isTransformAction() && ((CompareCode.isLess(compareCode) || CompareCode.isLessOrEqual(compareCode)))) { predicates.add(cb.greaterThan(productAmount.<Integer>get("totalAmount"), 0)); } } query.where(cb.and(predicates.toArray(new Predicate[predicates.size()]))) .orderBy(cb.desc(root.get("categoryCode")), cb.asc(root.get("productCode"))); return null; } }; return productStockInfoRepository.findAll(speci); }
From source file:org.wallride.repository.CustomFieldRepositoryImpl.java
@Override public void lock(long id) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = cb.createQuery(Long.class); Root<CustomField> root = query.from(CustomField.class); query.select(root.get(CustomField_.id)); query.where(cb.equal(root.get(CustomField_.id), id)); entityManager.createQuery(query).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult(); }
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) {//w w w . ja va2 s . c o 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:com.moderndrummer.data.MemberDaoImpl.java
@Override public boolean isValidUser(String userName, String password) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = builder.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); criteria.select(member).where(builder.equal(member.get("name"), userName)) .where(builder.equal(member.get("password"), password)); try {//from www .j av a 2 s. co m Member validMember = em.createQuery(criteria).setMaxResults(1).getSingleResult(); return ObjectUtil.verifyMemberExists(validMember); } catch (NoResultException e) { return false; } }
From source file:com.expressui.core.dao.security.query.RelatedRolesQuery.java
@Override public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Role> query, Root<Role> role) { List<Predicate> predicates = new ArrayList<Predicate>(); if (hasValue(user)) { ParameterExpression<User> userExp = builder.parameter(User.class, "user"); predicates.add(builder.equal(role.join("userRoles").get("user"), userExp)); }//from w w w .jav a 2s . c o m return predicates; }
From source file:com.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java
@Override public List<ApplicationBuilt> getApplications(User owner) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class); Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class); return em//from ww w .ja va 2 s. c o m .createQuery(cq.select(from) .where(cb.equal(from.get(ApplicationBuilt_.application).get(Application_.owner), owner))) .getResultList(); }