Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.FetchPlan


     * The fetch depth is kept infinite, so what would be fetched is essentially
     * controlled by the fetch groups.
     */
    public void testRelationTraversal() {
        OpenJPAEntityManager pm = getPM();
        FetchPlan plan = pm.getFetchPlan();
        pm.getFetchPlan().setMaxFetchDepth(-1);
        plan.addFetchGroup("employee.department");
        plan.addFetchGroup("department.company");
        plan.addFetchGroup("company.address");
        plan.addFetchGroup("address.country");

        Iterator employees = pm.createExtent(PCEmployee.class, true).iterator();
        while (employees.hasNext()) {
            PCEmployee emp = (PCEmployee) employees.next();

View Full Code Here


     * The fetch depth is kept infinite, so what would be fetched is essentially
     * controlled by the fetch groups.
     */
    public void testRelationTraversalTruncated() {
        OpenJPAEntityManager pm = getPM();
        FetchPlan plan = pm.getFetchPlan();
        pm.getFetchPlan().setMaxFetchDepth(-1);
        plan.addFetchGroup("employee.department");
        plan.addFetchGroup("department.company");
        plan.addFetchGroup("company.address");

        Iterator employees = pm.createExtent(PCEmployee.class, true).iterator();
        while (employees.hasNext()) {
            PCEmployee emp = (PCEmployee) employees.next();

View Full Code Here

     * Hence the company's address->country should be loaded but not the
     * employee's.
     */
    public void testRelationTraversalWithCompanyAsRoot() {
        OpenJPAEntityManager pm = getPM();
        FetchPlan plan = pm.getFetchPlan();

        plan.setMaxFetchDepth(2);
        plan.addFetchGroup("company.departments");
        plan.addFetchGroup("company.address");
        plan.addFetchGroup("department.employees");
        plan.addFetchGroup("person.address");
        plan.addFetchGroup("address.country");

        PCCompany company =
            (PCCompany) pm.find(PCCompany.class, _rootCompanyId);
        Set departments = (Set) PCCompany.reflect(company, "departments");
        assertNotNull("department is null", departments);
View Full Code Here

   
    private void oneManyCollectionByIdTest(boolean empty) {
        Object oid = insertOneManyCollection((empty) ? 1 : 0);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "oneManyCollection");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        if (empty)
            assertEquals(0, pc.getOneManyCollection().size());
        else
View Full Code Here

   
    private void oneManyCollectionByQueryTest(int empty) {
        insertOneManyCollection(empty);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "oneManyCollection");
        fetch.setFetchBatchSize(-1);
        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
        //FIXME jthomas
        //q.setOrdering("name ascending");
        Collection results = (Collection) q.getResultList();
       
View Full Code Here

   
    public void testManyManyCollectionById() {
        Object oid = insertManyManyCollection();
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "manyManyCollection");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        assertEquals(2, pc.getManyManyCollection().size());
        pm.close();
    }
View Full Code Here

   
    public void testManyManyCollectionByQuery() {
        insertManyManyCollection();
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "manyManyCollection");
        fetch.setFetchBatchSize(-1);
        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
        //FIXME jthomas
        //q.setOrdering("name ascending");
        Collection results = (Collection) q.getResultList();
       
View Full Code Here

   
    private void manyManyListByIdTest(boolean empty) {
        Object oid = insertManyManyList((empty) ? 1 : 0);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        if (empty)
            assertEquals(0, pc.getManyManyList().size());
        else {
View Full Code Here

   
    private void manyManyListByQueryTest(int empty) {
        insertManyManyList(empty);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
        fetch.setFetchBatchSize(-1);
        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
        //FIXME jthomas
        //q.setOrdering("name ascending");
        Collection results = (Collection) q.getResultList();
       
View Full Code Here

   
    public void testTwoCollectionsInFetchGroupsById() {
        Object oid = insertTwoCollections();
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        assertEquals(2, pc.getStringCollection().size());
        assertTrue(pc.getStringCollection().contains("1.1"));
        assertTrue(pc.getStringCollection().contains("1.2"));
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.FetchPlan

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.