Package org.apache.openjpa.persistence.query

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


        qb = (QueryBuilderImpl)emf.getDynamicQueryBuilder();
        emf.createEntityManager();
    }
   
    public void testLogicalPredicateAssociativity() {
        DomainObject e = qb.createQueryDefinition(Employee.class);
        Predicate p1 = e.get("salary").greaterThan(100);
        Predicate p2 = e.get("rating").equal(5);
        Predicate p3 = e.get("name").like("John");
        Predicate w1 = p1.and(p2.or(p3));
        Predicate w2 = (p1.and(p2)).or(p3);
        QueryDefinition q1 = e.select(e).where(w1);
        String jpql1 = qb.toJPQL(q1);
        emf.createEntityManager().createDynamicQuery(q1).getResultList();
       
        QueryDefinition q2 = e.select(e).where(w2);
        String jpql2 = qb.toJPQL(q2);
        System.err.println(jpql1);
        System.err.println(jpql2);
        assertNotEquals(jpql1, jpql2);
        emf.createEntityManager().createDynamicQuery(q2).getResultList();
View Full Code Here


        assertNotEquals(jpql1, jpql2);
        emf.createEntityManager().createDynamicQuery(q2).getResultList();
    }
   
    public void testMultipleDomainOfSameClass() {
        DomainObject o1 = qb.createQueryDefinition(Order.class);
        DomainObject o2 = o1.addRoot(Order.class);
        o1.select(o1)
          .where(o1.get("quantity").greaterThan(o2.get("quantity"))
            .and(o2.get("customer").get("lastName").equal("Smith"))
            .and(o2.get("customer").get("firstName").equal("John")));
       
        String jpql = "select o from Order o, Order o2" +
                      " where o.quantity > o2.quantity" +
                      " and o2.customer.lastName = 'Smith'" +
                      " and o2.customer.firstName = 'John'";
View Full Code Here

                      " and o2.customer.firstName = 'John'";
        compare(jpql, o1);
    }

    public void testFetchJoin() {
        DomainObject d = qb.createQueryDefinition(Department.class);
        d.leftJoinFetch("employees");
        d.where(d.get("deptNo").equal(1));
       
       
        String jpql = "select d from Department d" +
                      " LEFT JOIN FETCH d.employees" +
                      " where d.deptNo = 1";
View Full Code Here

                      " where d.deptNo = 1";
        compare(jpql, d);
    }
   
    public void testMultipartNavigation() {
        DomainObject e = qb.createQueryDefinition(Employee.class);
        DomainObject p = e.join("contactInfo").join("phones");
        e.where(e.get("contactInfo").get("address").get("zipCode")
                .equal("95094")).select(p.get("vendor"));
               
       
        String jpql = "select p.vendor from Employee e" +
                      " JOIN e.contactInfo c JOIN c.phones p" +
                      " where e.contactInfo.address.zipCode = '95094'";
View Full Code Here

        compare(jpql, e);
    }
   
    public void testOperatorPath() {
        QueryDefinition qdef = qb.createQueryDefinition();
        DomainObject item = qdef.addRoot(Item.class);
        DomainObject photo = item.join("photos");
        qdef.select(item.get("name"), photo.value())
            .where(photo.key().like("egret"));
       
       
        String jpql = "select i.name, VALUE(p)"
                    + " from Item i join i.photos p"
                    + " where KEY(p) like 'egret'";
View Full Code Here

                    + " where KEY(p) like 'egret'";
        compare(jpql, qdef);
    }
   
    public void testLiteral() {
        DomainObject c = qb.createQueryDefinition(Customer.class);
        DomainObject o = c.join("orders");
        DomainObject a = c.join("address");
        o.where(a.get("state").equal("CA").and(
            a.get("county").equal("Santa Clara")));
        o
            .select(o.get("quantity"), o.get("cost").times(1.08), a
                .get("zipCode"));
       
        String jpql = "select o.quantity, o.cost*1.08, a.zipCode" +
                      " from Customer c join c.orders o join c.address a" +
                      " where a.state = 'CA' and a.county = 'Santa Clara'";
View Full Code Here

                      " where a.state = 'CA' and a.county = 'Santa Clara'";
        compare(jpql, c);
    }
   
    public void testTypeExpression() {
        DomainObject e = qb.createQueryDefinition(Employee.class);
        e.select(e.type())
         .where(e.type().equal(Exempt.class).not());
       
        String jpql = "select TYPE(e)" +
                      " from Employee e" +
                      " where TYPE(e) <> Exempt";
        compare(jpql, e);
View Full Code Here

                      " where TYPE(e) <> Exempt";
        compare(jpql, e);
    }

    public void testIndex() {
        DomainObject c = qb.createQueryDefinition(Course.class);
        DomainObject w = c.join("studentWaitList");
        c.where(c.get("name").equal("Calculus").and(w.index().equal(0)))
         .select(w.get("name"));
       
        String jpql = "select s.name" +
                      " from Course c join c.studentWaitList s" +
                      " where c.name = 'Calculus' and INDEX(s) = 0";
        compare(jpql, c);
View Full Code Here

                      " where c.name = 'Calculus' and INDEX(s) = 0";
        compare(jpql, c);
    }
   
    public void testSum() {
        DomainObject o = qb.createQueryDefinition(Order.class);
        DomainObject l = o.join("lineItems");
        DomainObject c = o.join("customer");
        c.where(c.get("lastName").equal("Smith").and(c.get("firstName").
            equal("John"))).select(l.get("price").sum());
       
        String jpql = "select SUM(l.price)" +
                      " from Order o join o.lineItems l JOIN o.customer c" +
                      " where c.lastName = 'Smith' and c.firstName = 'John'";
View Full Code Here

                      " 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

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.