You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2007/11/12 18:57:51 UTC

svn commit: r594234 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java

Author: pcl
Date: Mon Nov 12 09:57:50 2007
New Revision: 594234

URL: http://svn.apache.org/viewvc?rev=594234&view=rev
Log:
OPENJPA-439

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

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=594234&r1=594233&r2=594234&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 Mon Nov 12 09:57:50 2007
@@ -255,8 +255,8 @@
         _compat = _conf.getCompatibilityInstance();
         _factory = factory;
         _log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
-        _cache = new ManagedCache(newManagedObjectCache());
-        _operating = MapBackedSet.decorate(new IdentityMap());
+        _cache = new ManagedCache();
+        initializeOperatingSet();
         _connRetainMode = connMode;
         _managed = managed;
         if (managed)
@@ -295,6 +295,10 @@
             beginInternal();
     }
 
+    private void initializeOperatingSet() {
+        _operating = MapBackedSet.decorate(new IdentityMap());
+    }
+
     public Object clone()
         throws CloneNotSupportedException {
         if (_initializeWasInvoked)
@@ -1587,7 +1591,6 @@
                     sm.rollback();
                     removeFromTransaction(sm);
                 }
-                oldTransCache.clear();
                 _transCache = newTransCache;
             }
         }
@@ -1742,7 +1745,7 @@
         } finally {
             _operationCount--;
             if (_operationCount == 0)
-                _operating.clear();
+                initializeOperatingSet();
             unlock();
         }
     }
@@ -1943,7 +1946,7 @@
 
             // also clear derefed set; the deletes have been recorded
             if (_derefCache != null)
-                _derefCache.clear();
+                _derefCache = null;
         }
 
         // flush to store manager
@@ -2026,7 +2029,7 @@
         // copy the change set, then clear it for the next iteration
         StateManagerImpl[] states = (StateManagerImpl[]) _transAdditions.
             toArray(new StateManagerImpl[_transAdditions.size()]);
-        _transAdditions.clear();
+        _transAdditions = null;
 
         for (int i = 0; i < states.length; i++)
             states[i].beforeFlush(reason, _call);
@@ -2045,7 +2048,7 @@
 
         StateManagerImpl[] states = (StateManagerImpl[]) _derefAdditions.
             toArray(new StateManagerImpl[_derefAdditions.size()]);
-        _derefAdditions.clear();
+        _derefAdditions = null;
 
         for (int i = 0; i < states.length; i++)
             deleteDeref(states[i]);
@@ -2151,11 +2154,11 @@
         // reference to it below
         _transCache = null;
         if (_persistedClss != null)
-            _persistedClss.clear();
+            _persistedClss = null;
         if (_updatedClss != null)
-            _updatedClss.clear();
+            _updatedClss = null;
         if (_deletedClss != null)
-            _deletedClss.clear();
+            _deletedClss = null;
 
         // new cache would get cleared anyway during transitions, but doing so
         // immediately saves us some lookups
@@ -2168,7 +2171,7 @@
             for (Iterator itr = _derefCache.iterator(); itr.hasNext();)
                 ((StateManagerImpl) itr.next()).setDereferencedDependent
                     (false, false);
-            _derefCache.clear();
+            _derefCache = null;
         }
 
         // peform commit or rollback state transitions on each instance
@@ -4357,9 +4360,9 @@
     /**
      * Cache of managed objects.
      */
-    private static class ManagedCache {
+    private class ManagedCache {
 
-        private final Map _main; // oid -> sm
+        private Map _main; // oid -> sm
         private Map _conflicts = null; // conflict oid -> new sm
         private Map _news = null; // tmp id -> new sm
         private Collection _embeds = null; // embedded/non-persistent sms
@@ -4368,8 +4371,8 @@
         /**
          * Constructor; supply primary cache map.
          */
-        public ManagedCache(Map cache) {
-            _main = cache;
+        private ManagedCache() {
+            _main = newManagedObjectCache();
         }
 
         /**
@@ -4593,15 +4596,15 @@
          * Clear the cache.
          */
         public void clear() {
-            _main.clear();
+            _main = newManagedObjectCache();
             if (_conflicts != null)
-                _conflicts.clear();
+                _conflicts = null;
             if (_news != null)
-                _news.clear();
+                _news = null;
             if (_embeds != null)
-                _embeds.clear();
+                _embeds = null;
             if (_untracked != null)
-                _untracked.clear();
+                _untracked = null;
         }
 
         /**
@@ -4609,7 +4612,7 @@
          */
         public void clearNew() {
             if (_news != null)
-                _news.clear();
+                _news = null;
         }
 
         private void dirtyCheck() {
@@ -4735,9 +4738,9 @@
 
         public void clear() {
             if (_dirty != null)
-                _dirty.clear();
+                _dirty = null;
             if (_clean != null)
-                _clean.clear();
+                _clean = null;
         }
 
         public boolean isEmpty() {