You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2009/12/08 17:43:01 UTC

svn commit: r888477 - in /openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa: conf/Compatibility.java kernel/DetachManager.java

Author: curtisr7
Date: Tue Dec  8 16:43:01 2009
New Revision: 888477

URL: http://svn.apache.org/viewvc?rev=888477&view=rev
Log:
OPENJPA-1414: Performance improvements for detach processing. Patch contributed by Dianne Richards.

Modified:
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=888477&r1=888476&r2=888477&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java (original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java Tue Dec  8 16:43:01 2009
@@ -56,6 +56,7 @@
     private int _jpql = JPQL_WARN;
     private boolean _storeMapCollectionInEntityAsBlob = false;
     private boolean _flushBeforeDetach = true; 
+    private boolean _reloadOnDetach = true;
 
     /**
      * Whether to require exact identity value types when creating object
@@ -269,4 +270,29 @@
         _flushBeforeDetach = beforeDetach;
     }
 
+    /**
+     * Whether OpenJPA should attempt to load fields when the DetachState
+     * option is set to loaded. This also determines whether a
+     * redundant copy of the version field is made. Defaults to true.
+     * 
+     * @return the _reloadOnDetach
+     * 
+     * @since 1.2.2
+     */
+    public boolean getReloadOnDetach() {
+        return _reloadOnDetach;
+    }
+
+    /**
+     * Whether OpenJPA should attempt to load fields when the DetachState
+     * option is set to loaded. This also determines whether a
+     * redundant copy of the version field is made. Defaults to true.
+     * 
+     * @param reloadOnDetach the _reloadOnDetach to set
+     * 
+     * @since 1.2.2
+     */
+    public void setReloadOnDetach(boolean reloadOnDetach) {
+        _reloadOnDetach = reloadOnDetach;
+    }   
 }

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java?rev=888477&r1=888476&r2=888477&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java (original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java Tue Dec  8 16:43:01 2009
@@ -34,6 +34,7 @@
 import java.util.Map;
 
 import org.apache.commons.collections.map.IdentityMap;
+import org.apache.openjpa.conf.Compatibility;
 import org.apache.openjpa.conf.DetachOptions;
 import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.event.CallbackModes;
@@ -68,6 +69,7 @@
     private final boolean _failFast;
     private boolean _flushed = false;
     private boolean _flushBeforeDetach;
+    private boolean _reloadOnDetach;
 
     // if we're not detaching full, we need to track all detached objects;
     // if we are, then we use a special field manager for more efficient
@@ -92,7 +94,7 @@
         boolean setState = meta.getDetachedState() != null
             && !ClassMetaData.SYNTHETIC.equals(meta.getDetachedState());
         BitSet idxs = (setState) ? new BitSet(meta.getFields().length) : null;
-        preDetach(sm.getBroker(), sm, idxs);
+        preDetach(sm.getBroker(), sm, idxs, false, true);
 
         if (setState) {
             sm.getPersistenceCapable().pcSetDetachedState(getDetachedState
@@ -120,7 +122,7 @@
         flushDirty(sm);
 
         Broker broker = sm.getBroker();
-        preDetach(broker, sm, idxs);
+        preDetach(broker, sm, idxs, false, true);
 
         // write detached state object and state manager
         DetachOptions opts = broker.getConfiguration().
@@ -145,7 +147,8 @@
      * effect of this method
      */
     private static void preDetach(Broker broker, StateManagerImpl sm,
-        BitSet idxs) {
+        BitSet idxs, boolean full, 
+        boolean reloadOnDetach) {
         // make sure the existing object has the right fields fetched; call
         // even if using currently-loaded fields for detach to make sure
         // version is set
@@ -157,8 +160,12 @@
         else if (detachMode == DETACH_ALL)
             loadMode = StateManagerImpl.LOAD_ALL;
         try {
-            sm.load(broker.getFetchConfiguration(), loadMode, exclude, null, 
-                false);
+            if (detachMode != DETACH_LOADED || 
+                    reloadOnDetach ||
+                    (!reloadOnDetach && !full)) {
+                sm.load(broker.getFetchConfiguration(), loadMode, exclude,
+                    null, false);
+            }
         } catch (ObjectNotFoundException onfe) {
             // consume the exception
         }
@@ -274,9 +281,10 @@
             _detached = new IdentityMap();
             _fullFM = null;
         }
-        _flushBeforeDetach =
-                broker.getConfiguration().getCompatibilityInstance()
-                        .getFlushBeforeDetach();
+        Compatibility compatibility = 
+            broker.getConfiguration().getCompatibilityInstance();
+        _flushBeforeDetach = compatibility.getFlushBeforeDetach();
+        _reloadOnDetach = compatibility.getReloadOnDetach();
     }
 
     /**
@@ -431,7 +439,8 @@
         }
         
         BitSet fields = new BitSet();
-        preDetach(_broker, sm, fields);
+        preDetach(_broker, sm, fields, _full, 
+            _reloadOnDetach);
 
         // create and store new object before copy to avoid endless recursion
         PersistenceCapable pc = sm.getPersistenceCapable();
@@ -452,7 +461,9 @@
                 _opts.getAccessUnloaded(), _broker.getMultithreaded());
         if (_full) {
             _fullFM.setStateManager(sm);
-            _fullFM.detachVersion();
+            if (_copy || _reloadOnDetach) {
+                _fullFM.detachVersion();
+            }
             _fullFM.reproxy(detSM);
             _fullFM.setStateManager(null);
         } else {