Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaQuery


   
    public void testAggregateExpressionInProjection() {
        String jpql = "SELECT SUM(i.price) "
             + "FROM Order o JOIN o.lineItems i JOIN o.customer c "
             + "WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
        CriteriaQuery q = cb.createQuery();
        Root<Order> o = q.from(Order.class);
        Join<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        Join<Order, Customer> c = o.join(order_.getSingularAttribute("customer",
                Customer.class));
        q.where(cb.equal(c.get(customer_.getSingularAttribute("lastName", String.class)), "Smith"),
                cb.equal(c.get(customer_.getSingularAttribute("firstName", String.class)), "John"));
        q.select(cb.sum(i.get(lineItem_.getSingularAttribute("price", Double.class))));

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


   
    public void testSizeExpressionInProjection() {
        String jpql = "SELECT SIZE(d.employees) FROM Department d "
         + "WHERE d.name = 'Sales'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        q.where(cb.equal(
                d.get(department_.getSingularAttribute("name", String.class)),
                "Sales"));
        SetAttribute<Department, Employee> employees =
            department_.getDeclaredSet("employees", Employee.class);
        q.select(cb.size(d.get(employees)));
       
        assertEquivalence(q, jpql);
       
    }
View Full Code Here

    }

    public void testEqualWithAttributeAndLiteral() {
        String jpql = "select a from Account a where a.balance=100";

        CriteriaQuery c = cb.createQuery();
        Root<Account> account = c.from(Account.class);
        c.select(account).where(cb.equal(account.get(Account_.balance), 100));

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

                cb.isTrue(cb.disjunction())));
        em.createQuery(c).getResultList();
    }
   
    public void testDefaultProjectionWithUntypedResult() {
        CriteriaQuery cquery = cb.createQuery();
        Root<Customer> customer = cquery.from(Customer.class);

        //Get Metamodel from Root
        EntityType<Customer> Customer_ = customer.getModel();

        cquery.where(cb.equal(
                customer.get(Customer_.getSingularAttribute("name", String.class)),
                cb.nullLiteral(String.class)));

        Query q = em.createQuery(cquery);
    }
View Full Code Here

    public void testStringEqualExpression() {
        String jpql = "select c from Customer c "
                    + "where c.name='Autowest Toyota'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Customer> customer = q.from(Customer.class);
        q.select(customer)
         .where(cb.equal(
                customer.get(customer_.getSingularAttribute("name", String.class)),
                "Autowest Toyota"));

        assertEquivalence(q, jpql);
View Full Code Here

    public void testSetAndListJoins() {
        String jpql = "SELECT c.name FROM Customer c "
                    + "JOIN c.orders o JOIN o.lineItems i "
                    + "WHERE i.product.productType = 'printer'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Customer> c = q.from(Customer.class);
        SetJoin<Customer, Order> o = c.join(customer_.getSet("orders",
                Order.class));
        ListJoin<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        q.select(c.get(Customer_.name)).where(
                cb.equal(i.get(lineItem_.getSingularAttribute("product", Product.class))
                    .get(product_.getSingularAttribute("productType", String.class)),
                    "printer"));

        assertEquivalence(q, jpql);
View Full Code Here

    }

    public void testFetchJoins() {
        String jpql = "SELECT d FROM Department d LEFT JOIN FETCH d.employees "
                + "WHERE d.deptNo = 1";
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT);
        q.where(
                cb.equal(d.get(department_
                        .getSingularAttribute("deptNo", Integer.class)), 1)).select(d);

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

        assertEquivalence(q, jpql);
    }
   
    public void testTypeExpression() {
        String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
        CriteriaQuery q = cb.createQuery();
        Root<Employee> emp = q.from(Employee.class);
        q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));

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

   
    public void testAggregateExpressionInProjection() {
        String jpql = "SELECT SUM(i.price) "
             + "FROM Order o JOIN o.lineItems i JOIN o.customer c "
             + "WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
        CriteriaQuery q = cb.createQuery();
        Root<Order> o = q.from(Order.class);
        Join<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        Join<Order, Customer> c = o.join(order_.getSingularAttribute("customer",
                Customer.class));
        q.where(cb.equal(c.get(customer_.getSingularAttribute("lastName", String.class)), "Smith"),
                cb.equal(c.get(customer_.getSingularAttribute("firstName", String.class)), "John"));
        q.select(cb.sum(i.get(lineItem_.getSingularAttribute("price", Double.class))));

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

   
    public void testSizeExpressionInProjection() {
        String jpql = "SELECT SIZE(d.employees) FROM Department d "
         + "WHERE d.name = 'Sales'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        q.where(cb.equal(
                d.get(department_.getSingularAttribute("name", String.class)),
                "Sales"));
        SetAttribute<Department, Employee> employees =
            department_.getDeclaredSet("employees", Employee.class);
        q.select(cb.size(d.get(employees)));
       
        assertEquivalence(q, jpql);
       
    }
View Full Code Here

TOP

Related Classes of javax.persistence.criteria.CriteriaQuery

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.