Example usage for javax.persistence.criteria CriteriaBuilder not

List of usage examples for javax.persistence.criteria CriteriaBuilder not

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder not.

Prototype

Predicate not(Expression<Boolean> restriction);

Source Link

Document

Create a negation of the given restriction.

Usage

From source file:edu.pitt.dbmi.ccd.db.specification.GroupSpecification.java

private static List<Predicate> notInNameOrDescription(Root<Group> root, CriteriaBuilder cb, Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.not(cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t))))
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.db.specification.VocabularySpecification.java

private static List<Predicate> notInNameOrDescription(Root<Vocabulary> root, CriteriaBuilder cb,
        Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.not(cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t))))
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationTargetSpecification.java

private static List<Predicate> notInTitleOrAddressOrName(Root<AnnotationTarget> root, CriteriaBuilder cb,
        Set<String> terms) {
    return terms/*  w  ww . j  ava  2 s . c om*/
            .stream().map(
                    t -> containsLike(t))
            .map(t -> cb.not(
                    cb.or(titleContains(root, cb, t), (root.get(ADDRESS) != null) ? addressContains(root, cb, t)
                            : fileNameContains(root, cb, t))))
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java

private static Predicate doesNotExistInData(Root<Annotation> root, CriteriaQuery query, CriteriaBuilder cb,
        String term) {//from   ww  w  .  j a  v a  2s  . c  om
    return cb.not(existsInData(root, query, cb, term));
}

From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java

/**
 * Creates a JPA2 predicate based on a Filter
 * //  www  .j  av a2  s.  c  o m
 * @param filter
 *            the filter
 * @param builder
 *            the criteria builder
 * @param root
 *            the entity root
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Predicate createPredicate(Filter filter, CriteriaBuilder builder, Root<?> root) {
    if (filter == null) {
        return null;
    }

    if (filter instanceof And) {
        return createAndPredicate(builder, root, filter);
    } else if (filter instanceof Or) {
        return createOrPredicate(builder, root, filter);
    } else if (filter instanceof Not) {
        Not not = (Not) filter;
        return builder.not(createPredicate(not.getFilter(), builder, root));
    } else if (filter instanceof Between) {
        Between between = (Between) filter;
        Expression property = getPropertyPath(root, between.getPropertyId());
        return builder.between(property, (Comparable) between.getStartValue(),
                (Comparable) between.getEndValue());
    } else if (filter instanceof Compare) {
        return createComparePredicate(builder, root, filter);
    } else if (filter instanceof IsNull) {
        IsNull isNull = (IsNull) filter;
        return builder.isNull(getPropertyPath(root, isNull.getPropertyId()));
    } else if (filter instanceof Like) {
        return createLikePredicate(builder, root, filter);
    } else if (filter instanceof Contains) {
        Contains contains = (Contains) filter;
        return builder.isMember(contains.getValue(),
                (Expression) getPropertyPath(root, contains.getPropertyId()));
    } else if (filter instanceof In) {
        In in = (In) filter;
        if (in.getValues() != null && !in.getValues().isEmpty()) {
            Expression exp = getPropertyPath(root, in.getPropertyId());
            return exp.in(in.getValues());
        } else {
            Expression exp = getPropertyPath(root, in.getPropertyId());
            return exp.in(Lists.newArrayList(-1));
        }
    } else if (filter instanceof Modulo) {
        return createModuloPredicate(builder, root, filter);
    }

    throw new UnsupportedOperationException("Filter: " + filter.getClass().getName() + " not recognized");
}

From source file:eu.uqasar.service.AbstractService.java

public <T extends Persistable> List<T> getAllExcept(Class<T> clazz, Collection<T> toExclude) {
    if (toExclude == null || toExclude.isEmpty()) {
        return getAll(clazz);
    }//w ww  .  jav  a  2s . c o  m
    logger.infof("loading all %s except %s ...", getReadableClassName(clazz), toExclude);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<T> query = cb.createQuery(clazz);
    Root<T> root = query.from(clazz);
    query.where(cb.not(root.in(toExclude)));
    return em.createQuery(query).getResultList();
}

From source file:eu.uqasar.service.AbstractService.java

public List<T> getAllExcept(Collection<T> toExclude) {
    if (toExclude == null || toExclude.isEmpty()) {
        return this.getAll();
    }//from   w w  w  .ja v a2 s.c  om
    logger.infof("loading all %s except %s ...", readableClassName, toExclude);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<T> query = cb.createQuery(this.clazz);
    Root<T> root = query.from(this.clazz);
    query.where(cb.not(root.in(toExclude)));
    return em.createQuery(query).getResultList();
}

From source file:eu.uqasar.service.AbstractService.java

protected <T extends Persistable> List<T> getAllOrderedExcept(Class<T> clazz, Collection<T> toExclude,
        Order... orders) {/*from   ww w .ja v a  2s  .  co  m*/
    if (toExclude == null || toExclude.isEmpty()) {
        return getAll(clazz);
    }
    logger.infof("loading all %s except %s ...", getReadableClassName(clazz), toExclude);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<T> query = cb.createQuery(clazz);
    Root<T> root = query.from(clazz);
    if (orders != null && orders.length > 0) {
        query.orderBy(orders);
    }
    query.where(cb.not(root.in(toExclude)));
    return em.createQuery(query).getResultList();
}

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);// ww  w .j a v a  2 s .  co m
    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:com.dbs.sdwt.jpa.ByPropertySelectorUtil.java

private <E> void byStringSelector(Root<E> root, CriteriaBuilder builder, List<Predicate> predicates,
        SearchParameters sp, PropertySelector<? super E, String> selector) {
    if (selector.isNotEmpty()) {
        List<Predicate> selectorPredicates = newArrayList();
        if (SearchMode.IN == selector.getSearchMode()) {
            Path<String> path = jpaUtil.getPath(root, selector.getAttributes());
            predicates.add(path.in(selector.getSelected()));
        } else if (SearchMode.NOT_IN == selector.getSearchMode()) {
            Path<String> path = jpaUtil.getPath(root, selector.getAttributes());
            predicates.add(builder.not(path.in(selector.getSelected())));
        } else {//from  w w  w .  ja  v a 2s . com
            for (String selection : selector.getSelected()) {
                Path<String> path = jpaUtil.getPath(root, selector.getAttributes());
                selectorPredicates
                        .add(jpaUtil.stringPredicate(path, selection, selector.getSearchMode(), sp, builder));
                if (selector.isOrMode()) {
                    predicates.add(jpaUtil.orPredicate(builder, selectorPredicates));
                } else {
                    predicates.add(jpaUtil.andPredicate(builder, selectorPredicates));
                }
            }
        }

    }
}