openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r747909 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java
Date Wed, 25 Feb 2009 20:18:53 GMT
Author: ppoddar
Date: Wed Feb 25 20:18:53 2009
New Revision: 747909

URL: http://svn.apache.org/viewvc?rev=747909&view=rev
Log:
OPENJPA-703: Reinstate performance optimization for DEFAULT and ALL fetch group lookup that
was inadvertently rolled back.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.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=747909&r1=747908&r2=747909&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 Feb 25 20:18:53 2009
@@ -83,6 +83,8 @@
         public Set rootClasses;
         public Set rootInstances;
         public Map hints = null;
+        public boolean fetchGroupContainsDefault = false;
+        public boolean fetchGroupContainsAll = false;
     }
 
     private final ConfigurationState _state;
@@ -241,6 +243,16 @@
             || _state.fetchGroups.contains(FetchGroup.NAME_ALL));
     }
 
+     public boolean hasFetchGroupDefault() {
+         // Fetch group All includes fetch group Default by definition
+         return _state.fetchGroupContainsDefault || 
+             _state.fetchGroupContainsAll;
+     }
+     
+     public boolean hasFetchGroupAll() {
+         return _state.fetchGroupContainsAll;
+     }
+     
     public FetchConfiguration addFetchGroup(String name) {
         if (StringUtils.isEmpty(name))
             throw new UserException(_loc.get("null-fg"));
@@ -250,6 +262,10 @@
             if (_state.fetchGroups == null)
                 _state.fetchGroups = new HashSet();
             _state.fetchGroups.add(name);
+            if (FetchGroup.NAME_ALL.equals(name))
+                _state.fetchGroupContainsAll = true;
+            else if (FetchGroup.NAME_DEFAULT.equals(name))
+                _state.fetchGroupContainsDefault = true;
         } finally {
             unlock();
         }
@@ -267,8 +283,13 @@
     public FetchConfiguration removeFetchGroup(String group) {
         lock();
         try {
-            if (_state.fetchGroups != null)
+            if (_state.fetchGroups != null) {
                 _state.fetchGroups.remove(group);
+                if (FetchGroup.NAME_ALL.equals(group))
+                    _state.fetchGroupContainsAll = false;
+                else if (FetchGroup.NAME_DEFAULT.equals(group))
+                    _state.fetchGroupContainsDefault = false;
+            }
         } finally {
             unlock();
         }
@@ -278,8 +299,9 @@
     public FetchConfiguration removeFetchGroups(Collection groups) {
         lock();
         try {
-            if (_state.fetchGroups != null)
-                _state.fetchGroups.removeAll(groups);
+            if (_state.fetchGroups != null && groups != null)
+                for (Object group : groups)
+                    removeFetchGroup(group.toString());
         } finally {
             unlock();
         }
@@ -289,8 +311,11 @@
     public FetchConfiguration clearFetchGroups() {
         lock();
         try {
-            if (_state.fetchGroups != null)
+            if (_state.fetchGroups != null) {
                 _state.fetchGroups.clear();
+                _state.fetchGroupContainsAll = false;
+                _state.fetchGroupContainsDefault = true;
+            }
         } finally {
             unlock();
         }
@@ -588,13 +613,11 @@
      * Whether our configuration state includes the given field.
      */
     private boolean includes(FieldMetaData fmd) {
-        if ((fmd.isInDefaultFetchGroup() 
-            && hasFetchGroup(FetchGroup.NAME_DEFAULT))
-            || hasFetchGroup(FetchGroup.NAME_ALL)
-            || hasField(fmd.getFullName(false))
-            || hasField(fmd.getRealName()) // OPENJPA-704
-            || (_fromField != null 
-            	&& hasField(_fromField + "." + fmd.getName())))
+        if (hasFetchGroupAll() 
+        || (hasFetchGroupDefault() && fmd.isInDefaultFetchGroup())
+        || hasField(fmd.getFullName(false))
+        || hasField(fmd.getRealName())
+        || (_fromField != null && hasField(_fromField + "." + fmd.getName())))
             return true;
         String[] fgs = fmd.getCustomFetchGroups();
         for (int i = 0; i < fgs.length; i++)



Mime
View raw message