openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r919657 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: enhance/ManagedClassSubclasser.java kernel/BrokerImpl.java kernel/DetachManagerLite.java
Date Fri, 05 Mar 2010 22:38:59 GMT
Author: curtisr7
Date: Fri Mar  5 22:38:59 2010
New Revision: 919657

URL: http://svn.apache.org/viewvc?rev=919657&view=rev
Log:
OPENJPA-1545: Refectored code. Fixed bug where unloaded fields were being loaded due to detach.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManagerLite.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java?rev=919657&r1=919656&r2=919657&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
Fri Mar  5 22:38:59 2010
@@ -289,7 +289,7 @@
         }
     }
 
-    private static void debugBytecodes(BCClass bc) throws IOException {
+    public static void debugBytecodes(BCClass bc) throws IOException {
         // Write the bytecodes to disk for debugging purposes.
         if ("true".equals(System.getProperty(
             ManagedClassSubclasser.class.getName() + ".dumpBytecodes")))

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=919657&r1=919656&r2=919657&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Fri
Mar  5 22:38:59 2010
@@ -3348,10 +3348,12 @@
     }
 
     private void detachAllInternalLite() {
-        Collection<StateManagerImpl> states = getManagedStates();
-        // TODO : should I call clear on old cache first? perhaps a memory leak?
-        // Clear out all persistence context caches.
+        ManagedCache old = _cache;
         _cache = new ManagedCache(this);
+        // TODO : should I call clear on old cache first? perhaps a memory leak?
+        Collection<StateManagerImpl> states = old.copy();
+        
+        // Clear out all persistence context caches.        
         if (_transCache != null) {
             _transCache.clear();
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManagerLite.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManagerLite.java?rev=919657&r1=919656&r2=919657&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManagerLite.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManagerLite.java
Fri Mar  5 22:38:59 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.kernel;
 
+import java.util.BitSet;
 import java.util.Collection;
 
 import org.apache.openjpa.enhance.PersistenceCapable;
@@ -30,10 +31,7 @@
  *
  */
 public class DetachManagerLite {
-    final TransferFieldManager _fm;
-
     public DetachManagerLite() {
-        _fm = new TransferFieldManager();
     }
 
     /**
@@ -43,13 +41,17 @@
      *            The StateManagers to be detached.
      */
     public void detachAll(Collection<StateManagerImpl> states) {
+        TransferFieldManager fm = new TransferFieldManager();
         for (StateManagerImpl sm : states) {
             ClassMetaData cmd = sm.getMetaData();
             if (sm.isPersistent() && cmd.isDetachable()) {
                 PersistenceCapable pc = sm.getPersistenceCapable();
                 // Detach proxy fields.
+                BitSet loaded = sm.getLoaded();
                 for (FieldMetaData fmd : cmd.getProxyFields()) {
-                    detachProxyField(fmd, pc, sm);
+                    if (loaded.get(fmd.getIndex())) {
+                        detachProxyField(fmd, pc, sm, fm);
+                    }
                 }
                 pc.pcReplaceStateManager(null);
             }
@@ -66,20 +68,20 @@
      * @param sm
      *            The StateManagerImpl that the PersistenceCapable belongs to.
      */
-    private void detachProxyField(FieldMetaData fmd, PersistenceCapable pc, StateManagerImpl
sm) {
+    private void detachProxyField(FieldMetaData fmd, PersistenceCapable pc, StateManagerImpl
sm, TransferFieldManager fm) {
         int fieldIndex = fmd.getIndex();
         if (fmd.isLRS() == true) {
             // need to null out LRS fields.
-            nullField(fieldIndex, pc, sm);
+            nullField(fieldIndex, pc, sm, fm);
         } else {
             Object o = sm.fetchObject(fieldIndex);
             if (o instanceof Proxy) {
                 // Get unproxied object and replace
                 Proxy proxy = (Proxy) o;
                 Object unproxied = proxy.copy(proxy);
-                _fm.storeObjectField(fieldIndex, unproxied);
-                sm.replaceField(pc, _fm, fieldIndex);
-                _fm.clear();
+                fm.storeObjectField(fieldIndex, unproxied);
+                sm.replaceField(pc, fm, fieldIndex);
+                fm.clear();
                 // clean up old proxy
                 proxy.setOwner(null, -1);
                 if (proxy.getChangeTracker() != null) {
@@ -99,9 +101,9 @@
      * @param sm
      *            The StateManagerImpl that the PersistenceCapable belongs to.
      */
-    private void nullField(int fieldIndex, PersistenceCapable pc, StateManagerImpl sm) {
-        _fm.storeObjectField(fieldIndex, null);
-        sm.replaceField(pc, _fm, fieldIndex);
-        _fm.clear();
+    private void nullField(int fieldIndex, PersistenceCapable pc, StateManagerImpl sm, TransferFieldManager
fm) {
+        fm.storeObjectField(fieldIndex, null);
+        sm.replaceField(pc, fm, fieldIndex);
+        fm.clear();
     }
 }



Mime
View raw message