Package javax.persistence.criteria

Examples of javax.persistence.criteria.Predicate


        CriteriaQuery<Movie> cq = qb.createQuery(Movie.class);
        Root<Movie> root = cq.from(Movie.class);
        EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
        if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
            Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
            Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
            cq.where(condition);
        }
        TypedQuery<Movie> q = entityManager.createQuery(cq);
        if (maxResults != null) {
            q.setMaxResults(maxResults);
View Full Code Here


        Root<Movie> root = cq.from(Movie.class);
        EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
        cq.select(qb.count(root));
        if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
            Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
            Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
            cq.where(condition);
        }
        return entityManager.createQuery(cq).getSingleResult().intValue();
    }
View Full Code Here

            for (SearchCondition<T> condition : sc.getSearchConditions()) {
                condition.accept(this);
            }
            List<Predicate> predsList = predStack.pop();
            Predicate[] preds = predsList.toArray(new Predicate[predsList.size()]);
            Predicate newPred;
            if (sc instanceof OrSearchCondition) {
                newPred = builder.or(preds);
            } else {
                newPred = builder.and(preds);
            }
View Full Code Here

                                               ps.getValueType(),
                                               propertyValue);
        CollectionCheckInfo collInfo = cv.getCollectionCheckInfo();
        Path<?> path = getPath(root, name, cv, collInfo);
       
        Predicate pred = collInfo == null
            ? doBuildPredicate(ps.getCondition(), path, cv.getCls(), cv.getValue())
            : doBuildCollectionPredicate(ps.getCondition(), path, collInfo);
       
        return pred;
    }
View Full Code Here

    private Predicate doBuildPredicate(ConditionType ct, Path<?> path, Class<?> valueClazz, Object value) {
       
        Class<? extends Comparable> clazz = (Class<? extends Comparable>)valueClazz;
        Expression<? extends Comparable> exp = path.as(clazz);
       
        Predicate pred = null;
        switch (ct) {
        case GREATER_THAN:
            pred = builder.greaterThan(exp, clazz.cast(value));
            break;
        case EQUALS:
View Full Code Here

        return pred;
    }
   
    @SuppressWarnings({ "unchecked", "rawtypes" })
    private Predicate doBuildCollectionPredicate(ConditionType ct, Path<?> path, CollectionCheckInfo collInfo) {
        Predicate pred = null;
       
        Expression<Integer> exp = builder.size((Expression<? extends Collection>)path);
        Integer value = Integer.valueOf(collInfo.getCollectionCheckValue().toString());
       
        switch (ct) {
View Full Code Here

            predStack.push(new ArrayList<Predicate>());
            for (SearchCondition<T> condition : sc.getSearchConditions()) {
                condition.accept(this);
            }
            Predicate[] preds = predStack.pop().toArray(new Predicate[0]);
            Predicate newPred;
            if (sc instanceof OrSearchCondition) {
                newPred = builder.or(preds);
            } else {
                newPred = builder.and(preds);
            }
View Full Code Here

       
        name = super.getRealPropertyName(name);
       
        Path<?> path = getPath(root, name);
       
        Predicate pred = null;
        switch (ct) {
        case GREATER_THAN:
            pred = builder.greaterThan(path.as(clazz), clazz.cast(value));
            break;
        case EQUALS:
View Full Code Here

            CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
            CriteriaQuery<? extends IBean> criteriaQuery = criteriaBuilder.createQuery(beanClass);
            Root<? extends IBean> beanRoot = criteriaQuery.from(beanClass);
            if ((values != null) && !values.isEmpty())
            {
                Predicate predicate = null;
                for (Map.Entry<String,Object> value : values.entrySet())
                {
                    Predicate valuePredicate = ((value.getValue() != null) ? criteriaBuilder.equal(beanRoot.get(value.getKey()), value.getValue()) : criteriaBuilder.isNull(beanRoot.get(value.getKey())));
                    predicate = ((predicate != null) ? criteriaBuilder.and(predicate, valuePredicate) : valuePredicate);
                }
                criteriaQuery.where(predicate);
            }
            if (orderBy != null)
View Full Code Here

      boolean asc) {
    try {
      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 {
View Full Code Here

TOP

Related Classes of javax.persistence.criteria.Predicate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.