openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r644627 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
Date Fri, 04 Apr 2008 06:55:21 GMT
Author: pcl
Date: Thu Apr  3 23:55:13 2008
New Revision: 644627

URL: http://svn.apache.org/viewvc?rev=644627&view=rev
Log:
OPENJPA-556. This implementation does some extra copying to accomodate DataCache.getAll(),
which takes a List instead of a Collection.

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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?rev=644627&r1=644626&r2=644627&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
Thu Apr  3 23:55:13 2008
@@ -26,8 +26,8 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.apache.openjpa.enhance.PCDataGenerator;
 import org.apache.openjpa.kernel.DelegatingStoreManager;
@@ -260,16 +260,26 @@
      */
     private void transformToVersionSafePCDatas(DataCache cache,
         List holders) {
-        PCDataHolder holder;
-        DataCachePCData oldpc;
-        for (ListIterator iter = holders.listIterator(); iter.hasNext();) {
-            holder = (PCDataHolder) iter.next();
-            oldpc = cache.get(holder.sm.getObjectId());
+
+        Map<Object,Integer> ids = new HashMap<Object,Integer>(holders.size());
+        // this list could be removed if DataCache.getAll() took a Collection
+        List idList = new ArrayList(holders.size());
+        int i = 0;
+        for (PCDataHolder holder : (List<PCDataHolder>) holders) {
+            ids.put(holder.sm.getObjectId(), i++);
+            idList.add(holder.sm.getObjectId());
+        }
+
+        Map<Object,DataCachePCData> pcdatas = cache.getAll(idList);
+        for (Entry<Object,DataCachePCData> entry : pcdatas.entrySet()) {
+            Integer index = ids.get(entry.getKey());
+            DataCachePCData oldpc = entry.getValue();
+            PCDataHolder holder = (PCDataHolder) holders.get(index);
             if (oldpc != null && compareVersion(holder.sm,
                 holder.sm.getVersion(), oldpc.getVersion()) == VERSION_EARLIER)
-                iter.remove();
+                holders.remove(index);
             else
-                iter.set(holder.pcdata);
+                holders.set(index, holder.pcdata);
         }
     }
 



Mime
View raw message