openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1516464 - in /openjpa/branches/2.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
Date Thu, 22 Aug 2013 14:39:44 GMT
Author: jgrassel
Date: Thu Aug 22 14:39:43 2013
New Revision: 1516464

URL: http://svn.apache.org/r1516464
Log:
OPENJPA-2414: FinderCache does not consider active Fetch Groups/FetchPlan added Fields

Modified:
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java?rev=1516464&r1=1516463&r2=1516464&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
Thu Aug 22 14:39:43 2013
@@ -483,6 +483,8 @@ public class FetchConfigurationImpl
             if (_state.fields == null)
                 _state.fields = new HashSet<String>();
             _state.fields.add(field);
+            
+            _state.fetchGroupIsPUDefault = false;
         } finally {
             unlock();
         }
@@ -507,8 +509,13 @@ public class FetchConfigurationImpl
     public FetchConfiguration removeField(String field) {
         lock();
         try {
-            if (_state.fields != null)
+            if (_state.fields != null) {
                 _state.fields.remove(field);
+                
+                if (_state.fields.size() == 0) {
+                    verifyDefaultPUFetchGroups();
+                }               
+            }
         } finally {
             unlock();
         }

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java?rev=1516464&r1=1516463&r2=1516464&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
Thu Aug 22 14:39:43 2013
@@ -21,6 +21,7 @@ package org.apache.openjpa.persistence.f
 
 import java.util.HashSet;
 
+import org.apache.openjpa.kernel.FetchConfiguration;
 import org.apache.openjpa.persistence.FetchPlan;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
@@ -35,6 +36,9 @@ public class TestFetchGroups extends Sin
     private HashSet<FGEmployee> employeeSet = new HashSet<FGEmployee>();
     private HashSet<FGManager> managerSet = new HashSet<FGManager>();
     
+    private static final String empDescriptionFieldStr =
+            "org.apache.openjpa.persistence.fetchgroups.FGEmployee.description";
+    
     public void setUp() {
         super.setUp(CLEAR_TABLES, 
             FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class);
@@ -52,6 +56,12 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
+        
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
         
@@ -79,6 +89,11 @@ public class TestFetchGroups extends Sin
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
         
@@ -92,6 +107,39 @@ public class TestFetchGroups extends Sin
     }
     
     /**
+     * Verify that adding a field to the fetch plan makes a normally JPA determined lazy
loaded
+     * field to behave as an eagerly loaded field.
+     */
+    public void testDefaultFetchPlan003() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        FetchPlan fp = em.getFetchPlan();
+        assertNotNull(fp);
+        
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
+        FGManager mgr = managerSet.iterator().next();
+        assertNotNull(mgr);
+        
+        FGManager findMgr = em.find(FGManager.class, mgr.getId());
+        em.close();
+        
+        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
+    }
+    
+    
+    /**
      * Verify the use of the "openjpa.FetchGroups" property when used to add a fetch group
      * to the default fetch plan.  Note when overriding that "default" must be included in
the list.
      */
@@ -108,6 +156,11 @@ public class TestFetchGroups extends Sin
         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);
         
@@ -141,6 +194,11 @@ public class TestFetchGroups extends Sin
         assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "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);
         
@@ -174,9 +232,15 @@ public class TestFetchGroups extends Sin
         assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
         assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         fp.clearFetchGroups();
         assertNotNull(fp.getFetchGroups());
         assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
         
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
@@ -208,10 +272,17 @@ public class TestFetchGroups extends Sin
         assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
         assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
+        
         // Remember, OPENJPA-2413 sets the list to be empty instead of containing "default"
         fp.clearFetchGroups();
         assertNotNull(fp.getFetchGroups());
         assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
         
         // Reset to the PCtx default Fetch Plan
         fp.resetFetchGroups();
@@ -220,6 +291,7 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
         assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
         
         // Verify that the PCtx default fetch plan was properly restored.  "default" should
not be enabled
         // since it was not listed by openjpa.FetchGroups.
@@ -248,6 +320,11 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
         
@@ -294,6 +371,11 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
         
@@ -325,6 +407,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -342,6 +426,8 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -358,6 +444,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -375,6 +463,7 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -391,6 +480,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -410,6 +501,8 @@ public class TestFetchGroups extends Sin
         assertEquals(0, fp.getFetchGroups().size());
         assertFalse(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -444,6 +537,12 @@ public class TestFetchGroups extends Sin
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
         
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
+        
         FGManager mgr = managerSet.iterator().next();
         assertNotNull(mgr);
         
@@ -463,6 +562,8 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -479,6 +580,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -496,6 +599,8 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -512,6 +617,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -529,6 +636,8 @@ public class TestFetchGroups extends Sin
         assertEquals(1, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -545,6 +654,8 @@ public class TestFetchGroups extends Sin
         assertEquals(2, fp.getFetchGroups().size());
         assertTrue(fp.getFetchGroups().contains("default"));
         assertTrue(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());
@@ -564,6 +675,8 @@ public class TestFetchGroups extends Sin
         assertEquals(0, fp.getFetchGroups().size());
         assertFalse(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -596,6 +709,11 @@ public class TestFetchGroups extends Sin
         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);
         
@@ -627,6 +745,8 @@ public class TestFetchGroups extends Sin
         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());
@@ -644,6 +764,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -660,6 +782,8 @@ public class TestFetchGroups extends Sin
         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());
@@ -677,6 +801,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -695,6 +821,8 @@ public class TestFetchGroups extends Sin
         assertEquals(0, fp.getFetchGroups().size());
         assertFalse(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -730,6 +858,11 @@ public class TestFetchGroups extends Sin
         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);
         
@@ -737,6 +870,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -753,6 +888,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -769,6 +906,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -785,6 +924,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -801,6 +942,8 @@ public class TestFetchGroups extends Sin
         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();
@@ -819,6 +962,8 @@ public class TestFetchGroups extends Sin
         assertEquals(0, fp.getFetchGroups().size());
         assertFalse(fp.getFetchGroups().contains("default"));
         assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
         {
             FGManager findMgr = em.find(FGManager.class, mgr.getId());
             em.clear();
@@ -833,6 +978,342 @@ public class TestFetchGroups extends Sin
         emf2.close();
     }
     
+    /**
+     * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
+     * as it currently lacks the ability to distinguish fetch plan configuration in its key
value.
+     * The PCtx's default fetch plan is the normal plan not modified by the "openjpa.FetchGroups"
+     * property.
+     * 
+     * In this variant, a find using the default fetch plan is first executed to prime the
finder cache.
+     * Finds operating under a modified fetch plan should not utilize sql stored in the finder
cache.
+     */
+    public void testFinderCache006() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        
+        FetchPlan fp = em.getFetchPlan();
+        assertNotNull(fp);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        
+        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());
+            assertNull(findMgr.getDescription()); // Should 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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        }
+        
+        // Add a field to the fetch plan and verify expected behavior
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        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());
+            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be
lazy-loaded
+        }
+        
+        // Remove the field previously added, and verify expected behavior
+        fp.removeField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertFalse(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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        }   
+        
+        // Add a field to the fetch plan and verify expected behavior
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        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());
+            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be
lazy-loaded
+        }
+        
+        // Reset the fetch groups, and verify expected behavior (note the reset doesn't remove
added fields!)
+        fp.resetFetchGroups();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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 (note the reset doesn't remove
added fields!)
+        // Note, due to OPENJPA-2413 even though it behaves as if the "default" fetch group
is enabled,
+        // it will not show up in the list of active fetch groups.
+        fp.clearFetchGroups();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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 fields, and verify expected behavior
+        fp.clearFields();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fp.getFetchGroups().contains("default"));
+        assertFalse(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        }
+        
+        em.close();
+    }
+    
+    /**
+     * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
+     * as it currently lacks the ability to distinguish fetch plan configuration in its key
value.
+     * The PCtx's default fetch plan is the normal plan not modified by the "openjpa.FetchGroups"
+     * property.
+     * 
+     * In this variant, a find using a modified fetch plan is first executed, which should
not be added
+     * to the finder cache.  
+     */
+    public void testFinderCache007() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        
+        FetchPlan fp = em.getFetchPlan();
+        assertNotNull(fp);
+        
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        
+        FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl)
em)
+                .getBroker()
+                .getFetchConfiguration();
+        assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
+        
+        
+        FGManager mgr = managerSet.iterator().next();
+        assertNotNull(mgr);
+        
+        {
+            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 the field, and verify expected behavior
+        fp.removeField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertFalse(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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        }   
+        
+        // Restore the field to the fetch plan and verify expected behavior
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        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());
+            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be
lazy-loaded
+        }
+        
+        // Remove the "DescFetchGroup" fetch group, and verify expected behavior
+        fp.removeField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertFalse(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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        } 
+        
+        // Restore the field to the fetch plan and verify expected behavior
+        fp.addField(empDescriptionFieldStr);
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        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());
+            assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be
lazy-loaded
+        }
+        
+        // Reset the fetch plan, and verify expected behavior (should not affect fields)
+        fp.resetFetchGroups();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(1, fp.getFetchGroups().size());
+        assertTrue(fp.getFetchGroups().contains("default"));
+        assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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 (should not affect fields)
+        // Note, due to OPENJPA-2413 even though it behaves as if the "default" fetch group
is enabled,
+        // it will not show up in the list of active fetch groups.
+        fp.clearFetchGroups();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fp.getFetchGroups().contains("default"));
+        assertTrue(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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 fields, and verify expected behavior
+        fp.clearFields();
+        assertNotNull(fp.getFetchGroups());
+        assertEquals(0, fp.getFetchGroups().size());
+        assertFalse(fp.getFetchGroups().contains("default"));
+        assertFalse(fp.getFields().contains(empDescriptionFieldStr));
+        assertFalse(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());
+            assertNull(findMgr.getDescription()); // Should be lazy-loaded
+        }
+        
+        em.close();
+    }
+    
     private void createEmployeeData() {
         OpenJPAEntityManager em = emf.createEntityManager();
         



Mime
View raw message