List of usage examples for javax.persistence.criteria CriteriaBuilder isNull
Predicate isNull(Expression<?> x);
From source file:th.co.geniustree.dental.spec.DetailHealSpec.java
public static Specification<DetailHeal> doctorLikeForBill(final String keyword) { return new Specification<DetailHeal>() { @Override/* w w w . j ava 2s. co m*/ public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { return cb.and(cb.like(cb.upper(root.get(DetailHeal_.doctor).get(Doctor_.nameTh)), keyword), cb.isNull(root.get(DetailHeal_.status))); } }; }
From source file:th.co.geniustree.dental.spec.PriceAndExpireProductSpec.java
public static Specification<PriceAndExpireProduct> lotInBetween(final Date keyword) { return new Specification<PriceAndExpireProduct>() { @Override//from w w w . j av a 2s. c o m public Predicate toPredicate(Root<PriceAndExpireProduct> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { return cb.and(cb.between(root.get(PriceAndExpireProduct_.lot).get(Lot_.dateIn), keyword, keyword), cb.isNull(root.get(PriceAndExpireProduct_.status))); } }; }
From source file:th.co.geniustree.dental.spec.PriceAndExpireProductSpec.java
public static Specification<PriceAndExpireProduct> productLike(final String keyword) { return new Specification<PriceAndExpireProduct>() { @Override/* w ww .ja v a2 s .co m*/ public Predicate toPredicate(Root<PriceAndExpireProduct> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { return cb.and(cb.like(cb.upper(root.get(PriceAndExpireProduct_.product).get(Product_.name)), keyword.toUpperCase()), cb.isNull(root.get(PriceAndExpireProduct_.status))); } }; }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate parentless(Root<Annotation> root, CriteriaBuilder cb) { return cb.isNull(root.get(PARENT)); }
From source file:com.eryansky.common.orm.core.spring.data.jpa.restriction.support.EqRestriction.java
public Predicate build(Path<?> expression, Object value, CriteriaBuilder builder) { return value == null ? builder.isNull(expression) : builder.equal(expression, value); }
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/* w ww .j a v a 2 s . c om*/ 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:core.commonapp.server.dao.contact.PartyContactMechDaoHibernateImpl.java
@Override public Set<PartyContactMech> findByContactMechId(Integer contactMechId) { log.debug("PartyContactMechDaoHibernateImpl.findByContactMechId({0})", contactMechId); CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<PartyContactMech> query = builder.createQuery(PartyContactMech.class); Root<PartyContactMech> root = query.from(PartyContactMech.class); builder.equal(root.get("contactMechId"), contactMechId); builder.isNull(root.get("thruDate")); return (Set<PartyContactMech>) new HashSet(getEntityManager().createQuery(query).getResultList()); }
From source file:net.carinae.dev.async.dao.QueuedTaskHolderDaoJPA2.java
@Override public QueuedTaskHolder findRandomStalledTask() { Calendar TOO_LONG_AGO = Calendar.getInstance(); TOO_LONG_AGO.add(Calendar.SECOND, -7200); // select qth from QueuedTask where // qth.startedStamp != null AND // qth.startedStamp < TOO_LONG_AGO CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); CriteriaQuery<QueuedTaskHolder> cq = cb.createQuery(QueuedTaskHolder.class); Root<QueuedTaskHolder> qth = cq.from(QueuedTaskHolder.class); cq.select(qth).where(cb.and(cb.isNull(qth.get(QueuedTaskHolder_.completedStamp)), cb.lessThan(qth.get(QueuedTaskHolder_.startedStamp), TOO_LONG_AGO))); List<QueuedTaskHolder> stalledTasks = this.entityManager.createQuery(cq).getResultList(); if (stalledTasks.isEmpty()) { return null; } else {//from w w w. j a v a 2 s . co m Random rand = new Random(System.currentTimeMillis()); return stalledTasks.get(rand.nextInt(stalledTasks.size())); } }
From source file:net.carinae.dev.async.dao.QueuedTaskHolderDaoJPA2.java
@Override public QueuedTaskHolder findNextTaskForExecution() { Calendar NOW = Calendar.getInstance(); // select qt from QueuedTask where // qt.startedStamp == null AND // (qth.triggerStamp == null || qth.triggerStamp < NOW) // order by qth.version ASC, qt.creationStamp ASC CriteriaBuilder cb = this.entityManager.getCriteriaBuilder(); CriteriaQuery<QueuedTaskHolder> cq = cb.createQuery(QueuedTaskHolder.class); Root<QueuedTaskHolder> qth = cq.from(QueuedTaskHolder.class); cq.select(qth)/* w w w. j a v a2s.c o m*/ .where(cb.and(cb.isNull(qth.get(QueuedTaskHolder_.startedStamp)), cb.or(cb.isNull(qth.get(QueuedTaskHolder_.triggerStamp)), cb.lessThan(qth.get(QueuedTaskHolder_.triggerStamp), NOW)))) .orderBy(cb.asc(qth.get(QueuedTaskHolder_.version)), cb.asc(qth.get(QueuedTaskHolder_.creationStamp))); List<QueuedTaskHolder> results = this.entityManager.createQuery(cq).setMaxResults(1).getResultList(); if (results.isEmpty()) { return null; } else { return results.get(0); } }
From source file:core.commonapp.server.dao.security.PermissionSecurityGroupDaoHibernateImpl.java
@Override public List<PermissionSecurityGroup> findAllBySecurityGroup(SecurityGroup securityGroup, boolean includeOld) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<PermissionSecurityGroup> query = builder.createQuery(getPersistClass()); Root<PermissionSecurityGroup> root = query.from(getPersistClass()); query.where(builder.equal(root.get("securityGroup"), securityGroup)); if (!includeOld) { query.where(builder.isNull(root.get("thruDate"))); }//from w ww . j a v a2 s . c o m return (List<PermissionSecurityGroup>) getEntityManager().createQuery(query).getResultList(); }