openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r428120 - in /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: kernel/StateManagerImpl.java meta/FieldMetaData.java
Date Wed, 02 Aug 2006 19:53:42 GMT
Author: ppoddar
Date: Wed Aug  2 12:53:42 2006
New Revision: 428120

URL: http://svn.apache.org/viewvc?rev=428120&view=rev
Log:
Added load-fetch-group to FieldMetaData and StateManager loading

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=428120&r1=428119&r2=428120&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Wed Aug  2 12:53:42 2006
@@ -2751,13 +2751,20 @@
         return ret;
     }
 
+    protected void loadField(int field, int lockLevel, boolean forWrite,
+            boolean fgs) {
+    	loadField (field, lockLevel, forWrite, fgs, null);
+    }
+    
     /**
      * Load the given field's fetch group; the field itself may already be
      * loaded if it is being set by the user.
      */
     protected void loadField(int field, int lockLevel, boolean forWrite,
-        boolean fgs) {
-    	FetchConfiguration fetch = _broker.getFetchConfiguration();
+        boolean fgs, FetchConfiguration fetch) {
+    	if (fetch == null) 
+    		fetch = _broker.getFetchConfiguration();
+    	boolean isLoadFetchGroupAdded = false;
         FieldMetaData fmd = _meta.getField(field);
         BitSet fields = null;
         // if this is a dfg field or we need to load our dfg, do so
@@ -2768,17 +2775,23 @@
         // if not a dfg field, use first custom fetch group as load group
         //### need to use metadata load-fetch-group
         if (!fmd.isInDefaultFetchGroup()) {
-            if (fmd.getCustomFetchGroups().length > 0) {  
-                String fg = fmd.getCustomFetchGroups()[0];
+            String lfg = fmd.getLoadFetchGroup();
+            if (lfg != null) {  
                 FieldMetaData[] fmds = _meta.getFields();
                 for (int i = 0; i < fmds.length; i++) {
                     if (!_loaded.get(i) && (i == field
-                        || fmds[i].isInFetchGroup(fg))) {
+                        || fmds[i].isInFetchGroup(lfg))) {
                         if (fields == null)
                             fields = new BitSet(fmds.length);
                         fields.set(i);
                     }
                 }
+                // relation field is loaded with the load-fetch-group
+                // but this addition must be reverted once the load is over
+                if (isRelation(fmd) && !fetch.hasFetchGroup(lfg)) {
+                	fetch.addFetchGroup(fmd.getLoadFetchGroup());
+                	isLoadFetchGroupAdded = true;
+                }
             } else if (!_loaded.get(fmd.getIndex())) {
                 if (fields == null)
                     fields = new BitSet();
@@ -2790,6 +2803,16 @@
         // takes care of things like loading version info and setting PC
         // flags
         loadFields(fields, fetch, lockLevel, null, forWrite);
+        
+        // remove the load fetch group 
+        if (isLoadFetchGroupAdded)
+        	fetch.removeFetchGroup(fmd.getLoadFetchGroup());
+    }
+    
+    private static boolean isRelation(FieldMetaData fm) {
+    	return fm.isDeclaredTypePC() 
+    	    || fm.getElement().isDeclaredTypePC()
+    	    || fm.getKey().isDeclaredTypePC();
     }
 
     /**
@@ -2863,19 +2886,22 @@
         if (field != -1) {
             FieldMetaData fmd = _meta.getField (field);
             if (fmd.isInDefaultFetchGroup() 
-                && postLoad(_meta.getFetchGroup(FetchGroup.NAME_DEFAULT)))
-                return;
+               && postLoad(_meta.getFetchGroup(FetchGroup.NAME_DEFAULT), fetch))
+               return;
             String[] fgs = fmd.getCustomFetchGroups();
             for (int i = 0; i < fgs.length; i++)
-                if (postLoad(_meta.getFetchGroup(fgs[i])))
+                if (postLoad(_meta.getFetchGroup(fgs[i]), fetch))
                     return;
         } else {
-            if (postLoad(_meta.getFetchGroup(FetchGroup.NAME_DEFAULT)))
+            if (postLoad(_meta.getFetchGroup(FetchGroup.NAME_DEFAULT), fetch))
                 return;
-            FetchGroup[] fgs = _meta.getCustomFetchGroups();
-            for (int i = 0; i < fgs.length; i++)
-                if (postLoad(fgs[i]))
+            
+            Iterator fgs = fetch.getFetchGroups().iterator();
+            for (;fgs.hasNext();) {
+            	FetchGroup fg = _meta.getFetchGroup(fgs.next().toString());
+                if (fg != null && postLoad(fg, fetch))
                     return; 
+            }
         }
     }
 
@@ -2883,16 +2909,18 @@
      * Perform post-load actions if the given fetch group is a post-load group
      * and is fully loaded.
      */
-    private boolean postLoad(FetchGroup fg) {
+    private boolean postLoad(FetchGroup fg, FetchConfiguration fetch) {
         if (!fg.isPostLoad())
             return false;
         FieldMetaData[] fmds = _meta.getFields();
         for (int i = 0; i < fmds.length; i++)
-            if (!_loaded.get(i) && fmds[i].isInFetchGroup(fg.getName()))
-                return false;
+        	if (fmds[i].isInFetchGroup(fg.getName()))
+        		if (!_loaded.get(i))
+        			return false;
 
         _flags |= FLAG_LOADED;
-        fireLifecycleEvent(LifecycleEvent.AFTER_LOAD);
+        _broker.fireLifecycleEvent(getManagedInstance(), fetch, _meta, 
+        	LifecycleEvent.AFTER_LOAD);
         return true;
     }
 

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=428120&r1=428119&r2=428120&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Wed Aug  2 12:53:42 2006
@@ -152,6 +152,7 @@
     private int _dfg = 0;
     private Set _fgSet = null;
     private String[] _fgs = null;
+    private String   _lfg = null;
     private Boolean _lrs = null;
     private String _extName = null;
     private Method _extMethod = DEFAULT_METHOD;
@@ -574,6 +575,16 @@
     }
 
     /**
+     * Gets the fetch group that is to be loaded when this receiver is loaded.
+     *  
+     * @return name of the load fetch group. Can be null, if not explicitly 
+     * set.
+     */
+    public String getLoadFetchGroup () {
+    	return _lfg;
+    }
+    
+    /**
      * Whether this field is in the given fetch group.
      */
     public boolean isInFetchGroup(String fg) {
@@ -610,6 +621,12 @@
             _fgs = null;
     }
 
+    public void setLoadFetchGroup (String lfg) {
+    	if (StringUtils.isEmpty(lfg))
+    		throw new MetaDataException(_loc.get("empty-fg-name"),this);
+    	_lfg = lfg;
+    }
+    
     /**
      * How the data store should treat null values for this field:
      * <ul>



Mime
View raw message