openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1509031 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
Date Wed, 31 Jul 2013 21:05:38 GMT
Author: jgrassel
Date: Wed Jul 31 21:05:37 2013
New Revision: 1509031

URL: http://svn.apache.org/r1509031
Log:
OPENJPA-2413: FetchPlan.clearFetchGroups() does not retain default entry in list of active
Fetch Groups.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java?rev=1509031&r1=1509030&r2=1509031&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
Wed Jul 31 21:05:37 2013
@@ -224,7 +224,7 @@ public class FetchConfigurationImpl
         setLockTimeout(fetch.getLockTimeout());
         setQueryTimeout(fetch.getQueryTimeout());
         setLockScope(fetch.getLockScope());
-        clearFetchGroups();
+        clearFetchGroups(false);
         addFetchGroups(fetch.getFetchGroups());
         clearFields();
         copyHints(fetch);
@@ -394,12 +394,23 @@ public class FetchConfigurationImpl
     }
 
     public FetchConfiguration clearFetchGroups() {
+        return clearFetchGroups(true);
+    }
+    
+    private FetchConfiguration clearFetchGroups(boolean restoresDefault) {
         lock();
         try {
             if (_state.fetchGroups != null) {
                 _state.fetchGroups.clear();
-                _state.fetchGroupContainsAll = false;
+            } else {
+                _state.fetchGroups = new HashSet<String>();
+            }
+            
+            _state.fetchGroupContainsAll = false;
+            
+            if (restoresDefault) {
                 _state.fetchGroupContainsDefault = true;
+                _state.fetchGroups.add(FetchGroup.NAME_DEFAULT); // OPENJPA-2413
             }
         } finally {
             unlock();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java?rev=1509031&r1=1509030&r2=1509031&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
Wed Jul 31 21:05:37 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.openjpa.persistence.kernel;
 
+import java.util.Collection;
+
+import org.apache.openjpa.meta.FetchGroup;
 import org.apache.openjpa.persistence.FetchPlan;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.kernel.common.apps.FetchA;
@@ -60,7 +63,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
 		fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class, "b");
 		fp.addField(FetchB.class, "text");
@@ -78,7 +81,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
         fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class, "b");
 		fp.addField(FetchA.class, "text");
@@ -96,7 +99,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
         fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class, "b");
 		fp.addField(FetchBase.class, "text");
@@ -114,7 +117,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
         fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class.getName() + ".b");
 		fp.addField(FetchB.class.getName() + ".text");
@@ -132,7 +135,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
         fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class.getName() + ".b");
 		fp.addField(FetchA.class.getName() + ".text");
@@ -150,7 +153,7 @@ public class TestDynamicFetchPlan extend
 		OpenJPAEntityManager em = emf.createEntityManager();
 		FetchPlan fp = em.getFetchPlan();
         fp.setExtendedPathLookup(true);
-		fp.clearFetchGroups();
+		fp.clearFetchGroups().removeFetchGroup(FetchGroup.NAME_DEFAULT);
 		fp.clearFields();
 		fp.addField(FetchA.class.getName() + ".b");
 		fp.addField(FetchBase.class.getName() + ".text");
@@ -163,4 +166,27 @@ public class TestDynamicFetchPlan extend
 		assertEquals("a1", a.getText());
 		assertEquals("b1", b.getText());
 	}
+	
+	// OPENJPA-2413: FetchPlan.clearFetchGroups() does not retain "default" in list of active
Fetch Groups.
+	public void testClearFetchPlan() {
+	    OpenJPAEntityManager em = emf.createEntityManager();
+	    FetchPlan fp = em.getFetchPlan();
+
+	    // Make sure "default" is present in the list of active FetchGroups
+	    Collection<String> fetchGroups = fp.getFetchGroups();
+	    assertNotNull(fetchGroups);
+	    assertTrue(fetchGroups.contains(FetchGroup.NAME_DEFAULT));
+
+	    // Clear all active FetchGroups, only "default" should remain.
+	    fp.clearFetchGroups();
+	    Collection<String> fetchGroupsAfterClear = fp.getFetchGroups();
+	    assertNotNull(fetchGroupsAfterClear);
+	    assertTrue(fetchGroupsAfterClear.contains(FetchGroup.NAME_DEFAULT));    
+
+	    // Should still be able to remove the "default" FetchGroup
+	    fp.removeFetchGroup(FetchGroup.NAME_DEFAULT);
+	    Collection<String> fetchGroupsAfterRemove = fp.getFetchGroups();
+	    assertNotNull(fetchGroupsAfterClear);
+	    assertTrue(fetchGroupsAfterClear.isEmpty());    
+	}
 }



Mime
View raw message