Package org.apache.openjpa.persistence.query

Examples of org.apache.openjpa.persistence.query.DomainObject


        compare(jpql, q);
    }
   
    public void testOrderBy() {
        QueryDefinition q = qb.createQueryDefinition();
        DomainObject customer = q.addRoot(Customer.class);
        DomainObject order = customer.join("orders");
        DomainObject address = customer.join("address");
        q.where(address.get("state").equal("CA"))
        .select(order)
        .orderBy(order.get("quantity").desc(), order.get("totalcost"));
        String jpql = "SELECT o"
                    + " FROM Customer c JOIN c.orders o JOIN c.address a"
                    + " WHERE a.state = 'CA'"
View Full Code Here


        compare(jpql, q);
    }
   
    public void testOrderBy2() {
        QueryDefinition q = qb.createQueryDefinition();
        DomainObject customer = q.addRoot(Customer.class);
        DomainObject order = customer.join("orders");
        DomainObject address = customer.join("address");
        q.where(address.get("state").equal("CA"))
        .select(order.get("quantity"), address.get("zipCode"))
        .orderBy(order.get("quantity").desc(), address.get("zipCode"));
        String jpql = "SELECT o.quantity, a.zipCode"
                    + " FROM Customer c JOIN c.orders o JOIN c.address a"
                    + " WHERE a.state = 'CA'"
                    + " ORDER BY o.quantity DESC, a.zipCode";
        compare(jpql, q);
View Full Code Here

                    + " ORDER BY o.quantity DESC, a.zipCode";
        compare(jpql, q);
    }
   
    public void testOrderByExpression() {
        DomainObject o = qb.createQueryDefinition(Order.class);
        DomainObject a = o.join("customer").join("address");
        SelectItem taxedCost = o.get("cost").times(1.08);
        o.select(o.get("quantity"), taxedCost, a.get("zipCode"))
        .where(a.get("state").equal("CA")
        .and(a.get("county").equal("Santa Clara")))
        .orderBy(o.get("quantity"), taxedCost, a.get("zipCode"));
       
        String jpql = "SELECT o.quantity, o.cost*1.08 as o2, a.zipCode"
                    + " FROM Order o JOIN o.customer c JOIN c.address a"
                    + " WHERE a.state = 'CA' AND a.county = 'Santa Clara'"
                    + " ORDER BY o.quantity, o2, a.zipCode";
View Full Code Here

        compare(jpql, o);
    }
   
    public void testCorrelatedSubquery() {
        QueryDefinition q1 = qb.createQueryDefinition();
        DomainObject emp = q1.addRoot(Employee.class);
       
        QueryDefinition q2 = qb.createQueryDefinition();
        DomainObject spouseEmp = q2.addRoot(Employee.class);
       
        q2.where(spouseEmp.equal(emp.get("spouse"))).select(spouseEmp);
        q1.selectDistinct(emp).where(q2.exists());
       
        String jpql = "SELECT DISTINCT e "
                    + " FROM Employee e"
                    + " WHERE EXISTS ("
View Full Code Here

       
        compare(jpql, q1);
    }
   
    public void testCreateSubquery() {
        DomainObject customer = qb.createQueryDefinition(Customer.class);
        DomainObject order =
            qb.createSubqueryDefinition(customer.get("orders"));
        customer.where(order.select(order.get("cost").avg()).greaterThan(100));
       
        String jpql = "SELECT c "
                    + " FROM Customer c"
                    + " WHERE (SELECT AVG(o.cost) FROM c.orders o) > 100";
       
View Full Code Here

       
        compare(jpql, customer);
    }
   
    public void testTypeList() {
        DomainObject q = qb.createQueryDefinition(Employee.class);
        q.where(q.type().in(Exempt.class, Contractor.class));
       
        String jpql = "SELECT e "
            + " FROM Employee e"
            + " WHERE TYPE(e) IN (Exempt, Contractor)";
       
View Full Code Here

       
        compare(jpql, q);
    }
   
    public void testStringList() {
        DomainObject q = qb.createQueryDefinition(Customer.class);
        q.where(q.get("country").in("USA", "UK", "France"));
       
        String jpql = "SELECT c "
            + " FROM Customer c"
            + " WHERE c.country IN ('USA', 'UK', 'France')";
        compare(jpql, q);
View Full Code Here

            + " WHERE c.country IN ('USA', 'UK', 'France')";
        compare(jpql, q);
    }
   
    public void testConcat() {
        DomainObject e = qb.createQueryDefinition(Employee.class);
        DomainObject f = e.join("frequentFlierPlan");
        Expression c =
        e.generalCase().when(f.get("annualMiles").greaterThan(50000)).then(
                "Platinum").when(f.get("annualMiles").greaterThan(25000)).then(
                "Gold").elseCase("XYZ");
        e.select(e.get("name"), f.get("name"), e.concat(c, e
            .literal("Frequent Flyer")));
       
        String jpql = "SELECT e.name, f.name, CONCAT("
            + " CASE WHEN f.annualMiles > 50000 THEN 'Platinum'"
            + " WHEN f.annualMiles > 25000 THEN 'Gold'"
View Full Code Here

           
        compare(jpql, e);
    }
   
    public void testCorrelatedSubquerySpecialCase1() {
        DomainObject o = qb.createQueryDefinition(Order.class);
        DomainObject a = qb.createSubqueryDefinition(o.get("customer").
            get("accounts"));
        o.select(o)
         .where(o.literal(10000).lessThan(a.select(a.get("balance")).all()));
       
        String jpql =
            "select o from Order o" + " where 10000 < ALL "
                + " (select a.balance from o.customer c "
                + "join o.customer.accounts a)";
View Full Code Here

       
        compare(jpql, o);
    }
   
    public void testCorrelatedSubquerySpecialCase2() {
        DomainObject o = qb.createQueryDefinition(Order.class);
        DomainObject c = o.join("customer");
        DomainObject a = qb.createSubqueryDefinition(c.get("accounts"));
        o.select(o)
         .where(o.literal(10000).lessThan(a.select(a.get("balance")).all()));
       
        String jpql = "select o from Order o JOIN o.customer c"
                    + " where 10000 < ALL "
                    + " (select a.balance from c.accounts a)";
       
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.query.DomainObject

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.