List of usage examples for javax.persistence.criteria CriteriaBuilder greaterThanOrEqualTo
<Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(Expression<? extends Y> x, Y y);
From source file:com.wms.studio.service.LoginIpServiceImpl.java
@Override @org.springframework.transaction.annotation.Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) public PageDto<LoginIpInfoDto> findBy(final String userId, final Date start, final Date end, PageSize pageSize) {/*from www. j av a 2 s. com*/ if (pageSize == null) { pageSize = new PageSize(); } return loginIpConvert.covertToDto(loginIpRepository.findAll(new Specification<LoginIp>() { @Override public Predicate toPredicate(Root<LoginIp> root, CriteriaQuery<?> query, CriteriaBuilder cb) { List<Predicate> pres = new ArrayList<>(3); if (start != null) { pres.add(cb.greaterThanOrEqualTo(root.get("loginTime").as(Date.class), start)); } if (end != null) { pres.add(cb.lessThanOrEqualTo(root.get("loginTime").as(Date.class), end)); } if (!StringUtils.isBlank(userId)) { pres.add(cb.equal(root.get("user").as(User.class), new User(userId))); } Predicate[] p = new Predicate[pres.size()]; return cb.and(pres.toArray(p)); } }, new PageRequest(pageSize.getPage() - 1, pageSize.getLimit()))); }
From source file:br.nom.abdon.gastoso.dal.FatosDao.java
protected static void buildQuery(final CriteriaBuilder cb, final FiltroFatos filtroFatos, final Path<Fato> fatoPath, final List<Predicate> where, final Map<String, Object> params) { final Fato fato = filtroFatos.getFato(); if (fato != null) { final ParameterExpression<Fato> fatoParameter = cb.parameter(Fato.class, "fato"); where.add(cb.equal(fatoParameter, fatoPath)); params.put("fato", fato); }//from ww w. j a v a2 s . co m final LocalDate dataMaxima = filtroFatos.getDataMaxima(); if (dataMaxima != null) { final Path<LocalDate> diaPath = fatoPath.get("dia"); final ParameterExpression<LocalDate> dataMaximaParameter = cb.parameter(LocalDate.class, "dataMaxima"); final Predicate menorOuIgualDataMaxima = cb.lessThanOrEqualTo(diaPath, dataMaximaParameter); where.add(menorOuIgualDataMaxima); params.put("dataMaxima", dataMaxima); } final LocalDate dataMinima = filtroFatos.getDataMinima(); if (dataMinima != null) { final Path<LocalDate> diaPath = fatoPath.get("dia"); final ParameterExpression<LocalDate> dataMinimaParameter = cb.parameter(LocalDate.class, "dataMinima"); final Predicate maiorOuIgualQueDataMinima = cb.greaterThanOrEqualTo(diaPath, dataMinimaParameter); where.add(maiorOuIgualQueDataMinima); params.put("dataMinima", dataMinima); } }
From source file:dtu.ds.warnme.dao.impl.EventsDaoImpl.java
@Override public List<EventEntity> getNearestEvents(Float nLat, Float sLat, Float eLng, Float wLng, EventType... eventTypes) {//from w ww . j av a2 s. c o m CriteriaBuilder criteriaBuilder = getCriteriaBuilder(); CriteriaQuery<EventEntity> criteriaQuery = criteriaBuilder.createQuery(EventEntity.class); Root<EventEntity> root = criteriaQuery.from(EventEntity.class); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get(EventEntity_.latitude), nLat)); predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get(EventEntity_.latitude), sLat)); predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get(EventEntity_.longitude), eLng)); predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get(EventEntity_.longitude), wLng)); if (ArrayUtils.isNotEmpty(eventTypes)) { List<Predicate> eventTypePredicates = new ArrayList<Predicate>(); for (EventType et : eventTypes) { eventTypePredicates.add(criteriaBuilder.equal(root.get(EventEntity_.eventType), et)); } predicates.add(criteriaBuilder.and( criteriaBuilder.or(eventTypePredicates.toArray(new Predicate[eventTypePredicates.size()])))); } criteriaQuery.where(predicates.toArray(new Predicate[predicates.size()])); return getAllByCriteria(criteriaQuery); }
From source file:com.moderndrummer.data.MemberDaoImpl.java
@Override public List<Member> findAllCreatedMembersByFromAndToDate(Date fromDate, Date toDate) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Member> criteria = cb.createQuery(Member.class); Root<Member> member = criteria.from(Member.class); Path<Date> dateCreatedPath = member.get("createdDate"); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(cb.lessThanOrEqualTo(dateCreatedPath, toDate)); predicates.add(cb.greaterThanOrEqualTo(dateCreatedPath, fromDate)); criteria.where(predicates.toArray(new Predicate[predicates.size()])); criteria.select(member).orderBy(cb.asc(member.get("name"))); return em.createQuery(criteria).getResultList(); }
From source file:com.wms.studio.service.WallpaperServiveImpl.java
@Override @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) public PageDto<WallpaperDto> findBy(final WallpaperEnum wallpaperType, final Date startDate, final Date endDate, PageSize pageSize) {//from w w w.j a v a 2 s . c o m if (pageSize == null) { pageSize = new PageSize(); } Page<Wallpaper> pageWallpaper = this.wallpaperRepository.findAll(new Specification<Wallpaper>() { @Override public Predicate toPredicate(Root<Wallpaper> root, CriteriaQuery<?> query, CriteriaBuilder cb) { List<Predicate> pres = new ArrayList<Predicate>(); if (wallpaperType != null) { pres.add(cb.equal(root.get("wallpaperType").as(WallpaperEnum.class), wallpaperType)); } if (startDate != null) { pres.add(cb.greaterThanOrEqualTo(root.get("addDate").as(Date.class), startDate)); } if (endDate != null) { pres.add(cb.lessThanOrEqualTo(root.get("addDate").as(Date.class), endDate)); } Predicate[] p = new Predicate[pres.size()]; return cb.and(pres.toArray(p)); } }, new PageRequest(pageSize.getPage() - 1, pageSize.getLimit())); return this.wallpaperCovert.covertToDto(pageWallpaper); }
From source file:com.atschx.summer.core.persistence.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override//from w ww .j a v a 2 s.c o m public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (Collections3.isNotEmpty(filters)) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; } } // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }
From source file:com.the3.base.repository.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override//ww w.ja v a 2s . c o m public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (filters != null && !filters.isEmpty()) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; } } // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }
From source file:org.echoice.modules.persistence.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override/*from w w w . j av a 2s.c o m*/ public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (filters != null && filters.size() > 0) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; } } // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }
From source file:net.shopxx.dao.impl.MemberDaoImpl.java
public Long registerMemberCount(Date beginDate, Date endDate) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Member> criteriaQuery = criteriaBuilder.createQuery(Member.class); Root<Member> root = criteriaQuery.from(Member.class); criteriaQuery.select(root);/*from w w w . j av a2 s . com*/ Predicate restrictions = criteriaBuilder.conjunction(); if (beginDate != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("createDate"), beginDate)); } if (endDate != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date>get("createDate"), endDate)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:com.i5le.framwork.core.persistence.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override/* www .j a va 2 s. c om*/ public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (Collections3.isNotEmpty(filters)) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; case NEQ: predicates.add(builder.notEqual(expression, filter.value)); break; } } // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }