Package org.apache.openjpa.persistence

Examples of org.apache.openjpa.persistence.FetchPlan


        OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
            FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
            "openjpa.FetchGroups", "default,DescFetchGroup");
       
        OpenJPAEntityManager em = emf2.createEntityManager();
        FetchPlan fp = em.getFetchPlan();
        assertNotNull(fp);
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
       
        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
                .getBroker()
                .getFetchConfiguration();
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        FGManager mgr = managerSet.iterator().next();
        assertNotNull(mgr);
       
        {
            // First find, to prime the Finder Cache
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        // Remove a fetch group to the fetch plan and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Restore the fetch group previously removed, and verify expected behavior
        fp.addFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }  
       
        // Remove a fetch group to the fetch plan and verify expected behavior
        fp.removeFetchGroup("DescFetchGroup");
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            // Second find, should rely on the finder cache to reuse generated SQL.
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertNull(findMgr.getDescription()); // Should be lazy-loaded
        }
       
        // Reset the fetch plan, and verify expected behavior
        fp.resetFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(2, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
           
            assertEquals(mgr.getId(), findMgr.getId());
            assertEquals(mgr.getFirstName(), findMgr.getFirstName());
            assertEquals(mgr.getLastName(), findMgr.getLastName());
            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
        }
       
        // Clear all fetch groups, and verify expected behavior
        // OPENJPA-2413: now places "default" in the list of active fetch groups.
        fp.clearFetchGroups();
        assertNotNull(fp.getFetchGroups());
        assertEquals(1, fp.getFetchGroups().size());
        assertTrue(fp.getFetchGroups().contains("default"));
        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
       
        {
            FGManager findMgr = em.find(FGManager.class, mgr.getId());
            em.clear();
View Full Code Here


    public void testQueryRange() {
        insertManyStringList();

        OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) em.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringList");
        fetch.setFetchBatchSize(3);
        OpenJPAQuery q = em.createQuery(JPQLParser.LANG_JPQL,
                "select x from EagerOuterJoinPC x order by x.name asc");
        q.setFirstResult(5).setMaxResults(15);

        List results = (List) q.getResultList();
View Full Code Here

   
    private void stringCollectionByIdTest(boolean empty) {
        Object oid = insertStringCollection((empty) ? 1 : 0);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        if (empty)
            assertEquals(pc.getStringCollection().toString(),
                    0, pc.getStringCollection().size());
View Full Code Here

   
    private void stringCollectionByQueryTest(int empty) {
        insertStringCollection(empty);
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
        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 testStringListById() {
        Object oid = insertStringList();
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
       
       
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringList");
        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
        assertEquals("1", pc.getName());
        assertEquals(2, pc.getStringList().size());
        assertEquals("1.1", pc.getStringList().get(0));
        assertEquals("1.2", pc.getStringList().get(1));
View Full Code Here

   
    public void testStringListByQuery() {
        insertStringList();
       
        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
        fetch.addField(EagerOuterJoinPC.class, "stringList");
        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 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

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.