Package org.apache.openjpa.persistence.query

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


                      " where c.lastName = 'Smith' and c.firstName = 'John'";
        compare(jpql, c);
    }
   
    public void testSize() {
        DomainObject d = qb.createQueryDefinition(Department.class);
        d.where(d.get("name").equal("Sales"))
         .select(d.get("employees").size());
       
        String jpql = "select SIZE(d.employees)" +
                      " from Department d " +
                      " where d.name = 'Sales'";
        compare(jpql, d);
View Full Code Here


                      " where d.name = 'Sales'";
        compare(jpql, d);
    }
   
    public void testGeneralCase() {
        DomainObject e = qb.createQueryDefinition(Employee.class);
        e.where(e.get("department").get("name").equal("Engineering"));
        e.select(e.get("name"),
        e.generalCase()
        .when(e.get("rating").equal(1))
        .then(e.get("salary").times(1.1))
        .when(e.get("rating").equal(2))
        .then(e.get("salary").times(1.2))
        .elseCase(e.get("salary").times(1.01)));
       
        String jpql = "SELECT e.name,"
                    + " CASE WHEN e.rating = 1 THEN e.salary * 1.1"
                    + " WHEN e.rating = 2 THEN e.salary * 1.2"
                    + " ELSE e.salary * 1.01"
 
View Full Code Here

       
        compare(jpql, e);
    }
   
    public void testMemberOf() {
        DomainObject p = qb.createQueryDefinition(Person.class);
        p.where(p.literal("Joe").member(p.get("nicknames")));
       
        String jpql = "select p from Person p " +
                      " where 'Joe' MEMBER OF p.nicknames";
        compare(jpql, p);
    }
View Full Code Here

        compare(jpql, p);
    }
   
    public void testParamater() {
        QueryDefinition qdef = qb.createQueryDefinition();
        DomainObject customer = qdef.addRoot(Customer.class);
        qdef.where(customer.get("status").equal(qdef.param("status")));
       
        String jpql = "select c from Customer c " +
                      " where c.status = :status";
        compare(jpql, qdef, "status", 1);
    }
View Full Code Here

                      " where c.status = :status";
        compare(jpql, qdef, "status", 1);
    }
   
    public void testBetween() {
        DomainObject c = qb.createQueryDefinition(CreditCard.class);
        DomainObject t = c.join("transactionHistory");
        c.select(t).where(c.get("holder").get("name").equal("John Doe")
                .and(t.index().between(0, 9)));
       
       
        String jpql = "select t from CreditCard c JOIN c.transactionHistory t" +
                      " where c.holder.name = 'John Doe' AND INDEX(t) " +
                      " BETWEEN 0 AND 9";
View Full Code Here

       
        compare(jpql, c);
    }
   
    public void testIsEmpty() {
        DomainObject o = qb.createQueryDefinition(Order.class);
        o.where(o.get("lineItems").isEmpty());
       
       
        String jpql = "select o from Order o " +
                      " where o.lineItems IS EMPTY";
        compare(jpql, o);
View Full Code Here

        compare(jpql, o);
    }

    public void testNonCorrelatedSubQuery() {
        QueryDefinition q1 = qb.createQueryDefinition();
        DomainObject goodCustomer = q1.addRoot(Customer.class);
       
        QueryDefinition q2 = qb.createQueryDefinition();
        DomainObject customer = q2.addRoot(Customer.class);
       
        q1.where(goodCustomer.get("balanceOwned")
                .lessThan(q2.select(customer.get("balanceOwned").avg())));
       
        String jpql = "select c from Customer c "
                    + " where c.balanceOwned < "
                    + "(select AVG(c2.balanceOwned) from Customer c2)";
        compare(jpql, q1);
View Full Code Here

        compare(jpql, q1);
    }

    public void testNew() {
        QueryDefinition q = qb.createQueryDefinition();
        DomainObject customer = q.addRoot(Customer.class);
        DomainObject order = customer.join("orders");
        q.where(order.get("count").greaterThan(100))
         .select(q.newInstance(Customer.class, customer.get("id"),
                                               customer.get("status"),
                                               order.get("count")));
       
       
        String jpql =
            "SELECT NEW org.apache.openjpa.persistence.criteria.Customer"
                + "(c.id, c.status, o.count)"
View Full Code Here

        compare(jpql, q);
    }
   
    public void testKeyValueOperatorPath() {
        QueryDefinition q = qb.createQueryDefinition();
        DomainObject v = q.addRoot(VideoStore.class);
        DomainObject i = v.join("videoInventory");
        q.where(v.get("location").get("zipCode").equal("94301").and(
            i.value().greaterThan(0)));
        q.select(v.get("location").get("street"), i.key().get("title"), i
            .value());
       
        String jpql = "SELECT v.location.street, KEY(v2).title, VALUE(v2)"
                    + " FROM VideoStore v JOIN v.videoInventory v2"
                    + " WHERE v.location.zipCode = '94301' AND VALUE(v2) > 0";
View Full Code Here

        compare(jpql, q);
    }
   
    public void testGroupByHaving() {
        QueryDefinition q = qb.createQueryDefinition();
        DomainObject customer = q.addRoot(Customer.class);
        q.select(customer.get("status"), customer.get("filledOrderCount").avg(),
                 customer.count())
         .groupBy(customer.get("status"))
         .having(customer.get("status").in(1, 2));
       
        String jpql = "SELECT c.status, AVG(c.filledOrderCount), COUNT(c)"
                    + " FROM Customer c"
                    + " GROUP BY c.status"
                    + " HAVING c.status IN (1, 2)";
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.