List of usage examples for javax.persistence.criteria CriteriaBuilder isNotNull
Predicate isNotNull(Expression<?> x);
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationTargetSpecification.java
private static Predicate isURL(Root<AnnotationTarget> root, CriteriaBuilder cb) { return cb.isNotNull(root.get(ADDRESS)); }
From source file:com.alliander.osgp.adapter.ws.infra.specifications.JpaDeviceSpecifications.java
@Override public Specification<Device> hasTechnicalInstallationDate() throws ArgumentNullOrEmptyException { return new Specification<Device>() { @Override//from w w w .java2 s. c o m public Predicate toPredicate(final Root<Device> deviceRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) { return cb.isNotNull(deviceRoot.<Date>get("technicalInstallationDate")); } }; }
From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java
@Override public List<UserLoginSecurityGroup> findByUserLoginAndSecurityGroup(UserLogin userLogin, SecurityGroup securityGroup, boolean includeOld) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass()); Root<UserLoginSecurityGroup> root = query.from(getPersistClass()); query.where(builder.equal(root.get("securityGroup"), securityGroup), builder.equal(root.get("userLogin"), userLogin), (includeOld ? builder.isNotNull(root.get("thruDate")) : builder.isNull(root.get("thruDate")))); return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList(); }
From source file:com.dbs.sdwt.jpa.ByPropertySelectorUtil.java
private <E> void byObjectSelector(Root<E> root, CriteriaBuilder builder, List<Predicate> predicates, SearchParameters sp, PropertySelector<? super E, ?> selector) { if (selector.isNotEmpty()) { if (selector.isOrMode()) { byObjectOrModeSelector(root, builder, predicates, sp, selector); } else {/*from w ww . j a va2 s.c o m*/ byObjectAndModeSelector(root, builder, predicates, sp, selector); } } else if (selector.isNotIncludingNullSet()) { predicates.add(builder.isNotNull(jpaUtil.getPath(root, selector.getAttributes()))); } }
From source file:net.sf.gazpachoquest.qbe.RangeSpecification.java
public static <E, D extends Comparable<? super D>> Specification<E> toSpecification(final Range<E, D> range) { Validate.isTrue(range.isSet(), "You must pass an exploitable range"); return new Specification<E>() { @Override//from w w w. j av a 2 s . co m public Predicate toPredicate(final Root<E> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { Predicate rangePredicate = null; if (range.isBetween()) { rangePredicate = builder.between(root.get(range.getField()), range.getFrom(), range.getTo()); } else if (range.isFromSet()) { // rangePredicate = // builder.greaterThanOrEqualTo(root.get(range.getField()), // range.getFrom()); rangePredicate = builder.greaterThan(root.get(range.getField()), range.getFrom()); } else if (range.isToSet()) { // rangePredicate = // builder.lessThanOrEqualTo(root.get(range.getField()), // range.getTo()); rangePredicate = builder.lessThan(root.get(range.getField()), range.getTo()); } if (rangePredicate != null) { if (!range.isIncludeNullSet() || Boolean.FALSE.equals(range.getIncludeNull())) { return rangePredicate; } else { return builder.or(rangePredicate, builder.isNull(root.get(range.getField()))); } } // no range at all // take the opportunity to keep only null... if (Boolean.TRUE.equals(range.getIncludeNull())) { return builder.isNull(root.get(range.getField())); } // ... or non-null only... if (Boolean.FALSE.equals(range.getIncludeNull())) { return builder.isNotNull(root.get(range.getField())); } throw new IllegalStateException("You must pass an exploitable range (should not happen here)"); } }; }
From source file:com.bxf.hradmin.common.utils.QueryParameterTransformer.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Predicate generatePredicate(Root root, CriteriaBuilder builder, QueryParameter... queryParameters) { Predicate condition = builder.conjunction(); for (QueryParameter queryParameter : queryParameters) { Object value = queryParameter.getValue(); if (value == null || StringUtils.isBlank(value.toString())) { continue; }//from ww w. j a v a2 s . co m Path path = root.get(queryParameter.getKey()); switch (queryParameter.getMode()) { case BETWEEN: Object[] values = asArray(value); if (values != null) { condition = builder.and(builder.between((Path<Comparable>) path, asComparable(values[0]), asComparable(values[1]))); } break; case GREATER_THAN: condition = builder.and(condition, builder.greaterThan((Path<Comparable>) path, asComparable(value))); break; case GREATER_EQUALS: condition = builder.and(condition, builder.greaterThanOrEqualTo((Path<Comparable>) path, asComparable(value))); break; case LESS_THAN: condition = builder.and(condition, builder.lessThan((Path<Comparable>) path, asComparable(value))); break; case LESS_EQUALS: condition = builder.and(condition, builder.lessThanOrEqualTo((Path<Comparable>) path, asComparable(value))); break; case IS_NULL: condition = builder.and(condition, builder.isNull(path)); break; case IS_NOT_NULL: condition = builder.and(condition, builder.isNotNull(path)); break; case IN: condition = builder.and(condition, path.in(asArray(value))); break; case NOT_IN: condition = builder.and(condition, builder.not(path.in(asArray(value)))); break; case LIKE: condition = builder.and(condition, builder.like(path, "%" + String.valueOf(value) + "%")); break; case NOT_LIKE: condition = builder.and(condition, builder.notLike(path, "%" + String.valueOf(value) + "%")); break; case EQUALS: condition = builder.and(condition, builder.equal(path, value)); break; case NOT_EQUALS: condition = builder.and(condition, builder.notEqual(path, value)); break; default: break; } } return condition; }
From source file:net.groupbuy.dao.impl.ProductNotifyDaoImpl.java
public Long count(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root);/*from ww w . java 2 s. c o m*/ Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }
From source file:net.groupbuy.dao.impl.ProductNotifyDaoImpl.java
public Page<ProductNotify> findPage(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent, Pageable pageable) {//from www. j a v a2 s.c o m CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root); Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.findPage(criteriaQuery, pageable); }
From source file:org.oncoblocks.centromere.jpa.QueryCriteriaSpecification.java
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { String key = queryCriteria.getKey(); Object value = queryCriteria.getValue(); Evaluation eval = queryCriteria.getEvaluation(); Path path = null;/*from w ww. j a va2 s .c om*/ if (key.contains(".")) { String[] bits = key.split("\\."); path = root.join(bits[0]).get(bits[1]); } else { path = root.get(key); } logger.debug(String.format("[CENTROMERE] Converting QueryCriteria to JPA specification: %s", queryCriteria.toString())); switch (eval) { case EQUALS: return criteriaBuilder.equal(path, value); case NOT_EQUALS: return criteriaBuilder.notEqual(path, value); case IN: return path.in(value); case NOT_IN: return criteriaBuilder.not(path.in(value)); case IS_NULL: return criteriaBuilder.isNull(path); case NOT_NULL: return criteriaBuilder.isNotNull(path); case GREATER_THAN: return criteriaBuilder.greaterThan(path, value.toString()); case GREATER_THAN_EQUALS: return criteriaBuilder.greaterThanOrEqualTo(path, value.toString()); case LESS_THAN: return criteriaBuilder.lessThan(path, value.toString()); case LESS_THAN_EQUALS: return criteriaBuilder.lessThanOrEqualTo(path, value.toString()); case BETWEEN: return criteriaBuilder.and(criteriaBuilder.greaterThan(path, ((List<?>) value).get(0).toString()), criteriaBuilder.lessThan(path, ((List<?>) value).get(1).toString())); case OUTSIDE: return criteriaBuilder.or(criteriaBuilder.greaterThan(path, ((List<?>) value).get(1).toString()), criteriaBuilder.lessThan(path, ((List<?>) value).get(0).toString())); case BETWEEN_INCLUSIVE: return criteriaBuilder.and( criteriaBuilder.greaterThanOrEqualTo(path, ((List<?>) value).get(0).toString()), criteriaBuilder.lessThanOrEqualTo(path, ((List<?>) value).get(1).toString())); case OUTSIDE_INCLUSIVE: return criteriaBuilder.or( criteriaBuilder.greaterThanOrEqualTo(path, ((List<?>) value).get(1).toString()), criteriaBuilder.lessThanOrEqualTo(path, ((List<?>) value).get(0).toString())); case LIKE: return criteriaBuilder.like(path, "%" + value.toString() + "%"); case NOT_LIKE: return criteriaBuilder.notLike(path, "%" + value.toString() + "%"); case STARTS_WITH: return criteriaBuilder.like(path, value.toString() + "%"); case ENDS_WITH: return criteriaBuilder.like(path, "%" + value.toString()); default: return criteriaBuilder.equal(root.get(queryCriteria.getKey()), queryCriteria.getValue()); } }
From source file:net.shopxx.dao.impl.ProductNotifyDaoImpl.java
public Long count(Member member, Boolean isMarketable, Boolean isOutOfStock, Boolean hasSent) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<ProductNotify> criteriaQuery = criteriaBuilder.createQuery(ProductNotify.class); Root<ProductNotify> root = criteriaQuery.from(ProductNotify.class); criteriaQuery.select(root);//from ww w . j a va 2 s. c o m Predicate restrictions = criteriaBuilder.conjunction(); if (member != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member)); } if (isMarketable != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product").get("goods").get("isMarketable"), isMarketable)); } if (isOutOfStock != null) { Path<Integer> stock = root.get("product").get("stock"); Path<Integer> allocatedStock = root.get("product").get("allocatedStock"); if (isOutOfStock) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNotNull(stock), criteriaBuilder.lessThanOrEqualTo(stock, allocatedStock)); } else { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.isNull(stock), criteriaBuilder.greaterThan(stock, allocatedStock))); } } if (hasSent != null) { restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("hasSent"), hasSent)); } criteriaQuery.where(restrictions); return super.count(criteriaQuery, null); }