Package javax.persistence.criteria

Examples of javax.persistence.criteria.Predicate


            public void decorate(Query q) {
                q.setParameter("p1", "XYZ");
            }
        }, c, jpql);
       
        Predicate where = c.getRestriction();
        c.where(cb.and(where, cb.equal(p.get(Person_.name), cb.parameter(String.class, "p2"))));
       
        assertEquivalence(new QueryDecorator() {
            public void decorate(Query q) {
                q.setParameter("p1", "MNO");
View Full Code Here


        em.getTransaction().commit();
       
        CriteriaQuery<Person> c = cb.createQuery(Person.class);
        Root<Person> p = c.from(Person.class);
        c.select(p);
        Predicate like = cb.like(p.get(Person_.name), cb.parameter(String.class, "pattern"));
        c.where(like);
        TypedQuery<Person> q1 = em.createQuery(c).setParameter("pattern", "P%");
        List<Person> r1 = q1.getResultList();
        assertEquals(2, r1.size());
       
        Predicate exact = cb.equal(p.get(Person_.name), cb.parameter(String.class, "exact"));
        c.where(like, exact);
        TypedQuery<Person> q2 = em.createQuery(c).setParameter("pattern", "P%").setParameter("exact","Pinaki");
        OpenJPAPersistence.cast(q2).setCandidateCollection(r1);
        auditor.clear();
        List<Person> r2 = q2.getResultList();
View Full Code Here

       
        CriteriaQuery<TransactionHistory> cq = cb.createQuery(TransactionHistory.class);
        Root<CreditCard> c = cq.from(CreditCard.class);
        ListJoin<CreditCard, TransactionHistory> t = c.join(creditCard_.getList("transactionHistory",
                TransactionHistory.class));
        Predicate p1 = cb.equal(
                c.get(creditCard_.getSingularAttribute("customer", Customer.class))
                 .get(customer_.getSingularAttribute("accountNum", long.class)), 321987);
        Predicate p2 = cb.between(t.index(), 0, 9);
        cq.select(t).where(p1,p2);

        assertEquivalence(cq, jpql);
    }
View Full Code Here

    }
   
    @Override
    org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
        if (_exps.isEmpty()) {
            Predicate nil = _op == BooleanOperator.AND ? TRUE() : FALSE();
            return ((PredicateImpl)nil).toKernelExpression(factory, q);
        }
        if (_exps.size() == 1) {
            Predicate e0 = _exps.get(0);
            if (isNegated())
                e0 = e0.not();
            return ((PredicateImpl)e0).toKernelExpression(factory, q);
        }
       
        ExpressionImpl<?> e1 = (ExpressionImpl<?>)_exps.get(0);
        ExpressionImpl<?> e2 = (ExpressionImpl<?>)_exps.get(1);
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

       
        CriteriaQuery<TransactionHistory> cq = cb.createQuery(TransactionHistory.class);
        Root<CreditCard> c = cq.from(CreditCard.class);
        ListJoin<CreditCard, TransactionHistory> t = c.join(creditCard_.getList("transactionHistory",
                TransactionHistory.class));
        Predicate p1 = cb.equal(
                c.get(creditCard_.getSingularAttribute("customer", Customer.class))
                 .get(customer_.getSingularAttribute("accountNum", long.class)), 321987);
        Predicate p2 = cb.between(t.index(), 0, 9);
        cq.select(t).where(p1,p2);

        assertEquivalence(cq, jpql);
    }
View Full Code Here

        q.select(book);
       
        // Builds the predicates conditionally for the filled-in input fields
        List<Predicate> predicates = new ArrayList<Predicate>();
        if (!isEmpty(title)) {
            Predicate matchTitle = cb.like(book.get(Book_.title), title);
            predicates.add(matchTitle);
        }
        if (!isEmpty(author)) {
            Predicate matchAuthor = cb.like(book.join(Book_.authors).get(Author_.name), "%"+author+"%");
            predicates.add(matchAuthor);
        }
        // for price fields, also the comparison operation changes based on whether
        // minimum or maximum price or both have been filled.
        if (minPrice != null && maxPrice != null) {
            Predicate matchPrice = cb.between(book.get(Book_.price), minPrice, maxPrice);
            predicates.add(matchPrice);
        } else if (minPrice != null && maxPrice == null) {
            Predicate matchPrice = cb.ge(book.get(Book_.price), minPrice);
            predicates.add(matchPrice);
        } else if (minPrice == null && maxPrice != null) {
            Predicate matchPrice = cb.le(book.get(Book_.price), maxPrice);
            predicates.add(matchPrice);
        }
        // Sets the evaluation criteria    
        if (!predicates.isEmpty())
            q.where(predicates.toArray(new Predicate[predicates.size()]));
View Full Code Here

        // get all users
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<User> cq = cb.createQuery(User.class);
        Root<User> c = cq.from(User.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

      return null;
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> c = cq.from(User.class);
    Predicate condition = cb.equal(c.get("deleted"), false);
    Predicate subCondition = cb.equal(c.get("user_id"), id);
    cq.where(condition, subCondition);
    TypedQuery<User> q = em.createQuery(cq);
    User u = null;
    try {
      u = q.getSingleResult();
View Full Code Here

    log.debug("Usermanagement.getUserById");

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> c = cq.from(User.class);
    Predicate condition = cb.equal(c.get("user_id"), id);
    cq.where(condition);
    TypedQuery<User> q = em.createQuery(cq);
    User u = null;
    try {
      u = q.getSingleResult();
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.