List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java
public Page<Consultation> findPage(Member member, Product product, Boolean isShow, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class); Root<Consultation> root = criteriaQuery.from(Consultation.class); criteriaQuery.select(root);//from w w w . ja v a 2 s . c o m Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation"))); 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 (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.ConsultationDaoImpl.java
public Long count(Member member, Product product, Boolean isShow) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class); Root<Consultation> root = criteriaQuery.from(Consultation.class); criteriaQuery.select(root);//from w ww . j a v a 2 s . c o m Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation"))); 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 (isShow != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java
public List<Consultation> findList(Member member, Product product, Boolean isShow, Integer count, List<Filter> filters, List<Order> orders) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class); Root<Consultation> root = criteriaQuery.from(Consultation.class); criteriaQuery.select(root);/*from w w w . ja v a 2 s . co m*/ Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation"))); 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 (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:com.globalhackv.app.repository.CitationSpec.java
@Override public Predicate toPredicate(Root<Citation> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<Predicate>(); if (StringUtils.isNotBlank(example.getLastName())) { predicates.add(/*w ww. j a va2 s.co m*/ cb.like(cb.lower(root.get(Citation_.lastName)), example.getLastName().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getFirstName())) { predicates.add( cb.like(cb.lower(root.get(Citation_.firstName)), example.getFirstName().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getDateOfBirth())) { predicates.add(cb.like(cb.lower(root.get(Citation_.dateOfBirth)), example.getDateOfBirth().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getDriversLicense())) { predicates.add(cb.like(cb.lower(root.get(Citation_.driversLicense)), example.getDriversLicense().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getAddress())) { predicates .add(cb.like(cb.lower(root.get(Citation_.address)), example.getAddress().toLowerCase() + "%")); } if (example.getCitationNumber() != 0) { predicates.add(cb.equal(root.get(Citation_.citationNumber), example.getCitationNumber())); } return andTogether(predicates, cb); }
From source file:net.groupbuy.dao.impl.ParameterDaoImpl.java
public List<Parameter> findList(ParameterGroup parameterGroup, Set<Parameter> excludes) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Parameter> criteriaQuery = criteriaBuilder.createQuery(Parameter.class); Root<Parameter> root = criteriaQuery.from(Parameter.class); criteriaQuery.select(root);//from w w w .ja v a 2 s. c om Predicate restrictions = criteriaBuilder.conjunction(); if (parameterGroup != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("parameterGroup"), parameterGroup)); } if (excludes != null && !excludes.isEmpty()) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.not(root.in(excludes))); } criteriaQuery.where(restrictions); return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList(); }
From source file:de.hopmann.repositories.cran.service.CRANPackageListingService.java
@PackageListingUpdate public boolean isAvailable(String packageName, Version sourceVersion) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<CRANPackageEntity> query = cb.createQuery(CRANPackageEntity.class); Root<CRANPackageEntity> p = query.from(CRANPackageEntity.class); query.where(cb.and(/*from w w w . jav a 2 s. co m*/ // cb.equal(p.get(PackageEntity_.name), packageName), cb.equal(p.get(PackageEntity_.version).get(Version_.versionNumber), sourceVersion.getVersionNumber()))); List<CRANPackageEntity> resultList = entityManager.createQuery(query).getResultList(); return !resultList.isEmpty(); }
From source file:com.june.app.board.repository.jpa.BoardRepositoryImpl.java
@Override public Collection<Board> boardListWithPaging(Board vo) { int bbsId = vo.getBbsId(); int pageSize = vo.getPageSize(); int pageNumber = (int) vo.getPageIndex(); CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery<Board> criteriaQuery = criteriaBuilder.createQuery(Board.class); Root<Board> from = criteriaQuery.from(Board.class); CriteriaQuery<Board> select = criteriaQuery.select(from); if (bbsId > 0) { criteriaQuery.where(criteriaBuilder.equal(from.get("bbsId"), bbsId)); }// w ww.j a v a 2 s . co m /**list desc for date*/ criteriaQuery.orderBy(criteriaBuilder.desc(from.get("frstRegistPnttm"))); TypedQuery<Board> typedQuery = em.createQuery(select); typedQuery.setFirstResult((pageNumber - 1) * pageSize); typedQuery.setMaxResults(pageSize); Collection<Board> fooList = typedQuery.getResultList(); return fooList; }
From source file:org.osiam.resource_server.storage.dao.ResourceDao.java
public <T extends ResourceEntity, V> boolean isUniqueAttributeAlreadyTaken(String attributeValue, String id, SingularAttribute<? super T, V> attribute, Class<T> clazz) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<T> resource = cq.from(clazz); cq.select(cb.countDistinct(resource)); Predicate predicate = cb.equal(resource.get(attribute), attributeValue); if (id != null) { Predicate ignoreId = cb.notEqual(resource.get(ResourceEntity_.id), id); predicate = cb.and(predicate, ignoreId); }/*from w w w . j a va 2s .c o m*/ cq.where(predicate); TypedQuery<Long> countQuery = em.createQuery(cq); return countQuery.getSingleResult() > 0; }
From source file:net.groupbuy.dao.impl.CouponDaoImpl.java
public Page<Coupon> findPage(Boolean isEnabled, Boolean isExchange, Boolean hasExpired, Pageable pageable) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Coupon> criteriaQuery = criteriaBuilder.createQuery(Coupon.class); Root<Coupon> root = criteriaQuery.from(Coupon.class); criteriaQuery.select(root);//from w w w .j ava 2 s.c o m Predicate restrictions = criteriaBuilder.conjunction(); if (isEnabled != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isEnabled"), isEnabled)); } if (isExchange != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isExchange"), isExchange)); } if (hasExpired != null) { if (hasExpired) { restrictions = criteriaBuilder.and(restrictions, root.get("endDate").isNotNull(), criteriaBuilder.lessThan(root.<Date>get("endDate"), new Date())); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("endDate").isNull(), criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("endDate"), new Date()))); } } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }
From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java
public List<LdapConfig> getLdapConfigs(int start, int max, String orderby, boolean asc) { try {/*w w w . java2s .c o m*/ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<LdapConfig> cq = cb.createQuery(LdapConfig.class); Root<LdapConfig> c = cq.from(LdapConfig.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<LdapConfig> q = em.createQuery(cq); q.setFirstResult(start); q.setMaxResults(max); List<LdapConfig> ll = q.getResultList(); return ll; } catch (Exception ex2) { log.error("[getLdapConfigs]", ex2); } return null; }