jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r535830 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ItemManager.java persistence/bundle/BundleDbPersistenceManager.java
Date Mon, 07 May 2007 10:12:21 GMT
Author: stefan
Date: Mon May  7 03:12:16 2007
New Revision: 535830

URL: http://svn.apache.org/viewvc?view=rev&rev=535830
Log:
JCR-862: unsynchronized access on 'itemCache' map in ItemManager 

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?view=diff&rev=535830&r1=535829&r2=535830
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Mon May  7 03:12:16 2007
@@ -33,9 +33,7 @@
 import org.apache.jackrabbit.core.util.Dumpable;
 import org.apache.jackrabbit.core.version.VersionHistoryImpl;
 import org.apache.jackrabbit.core.version.VersionImpl;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.name.QName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -92,13 +90,14 @@
     /**
      * A cache for item instances created by this <code>ItemManager</code>
      */
-    private Map itemCache;
+    private final Map itemCache;
 
     /**
      * Creates a new per-session instance <code>ItemManager</code> instance.
      *
      * @param itemStateProvider the item state provider associated with
      *                          the new instance
+     * @param hierMgr           the hierarchy manager
      * @param session           the session associated with the new instance
      * @param rootNodeDef       the definition of the root node
      * @param rootNodeId        the id of the root node
@@ -120,8 +119,10 @@
     /**
      * Disposes this <code>ItemManager</code> and frees resources.
      */
-    synchronized void dispose() {
-        itemCache.clear();
+    void dispose() {
+        synchronized (itemCache) {
+            itemCache.clear();
+        }
     }
 
     private NodeDefinition getDefinition(NodeState state)
@@ -596,8 +597,10 @@
      * @return the item reference stored in the corresponding cache entry
      *         or <code>null</code> if there's no corresponding cache entry.
      */
-    private synchronized ItemImpl retrieveItem(ItemId id) {
-        return (ItemImpl) itemCache.get(id);
+    private ItemImpl retrieveItem(ItemId id) {
+        synchronized (itemCache) {
+            return (ItemImpl) itemCache.get(id);
+        }
     }
 
     /**
@@ -606,15 +609,17 @@
      *
      * @param item the item to cache
      */
-    private synchronized void cacheItem(ItemImpl item) {
-        ItemId id = item.getId();
-        if (itemCache.containsKey(id)) {
-            log.warn("overwriting cached item " + id);
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("caching item " + id);
+    private void cacheItem(ItemImpl item) {
+        synchronized (itemCache) {
+            ItemId id = item.getId();
+            if (itemCache.containsKey(id)) {
+                log.warn("overwriting cached item " + id);
+            }
+            if (log.isDebugEnabled()) {
+                log.debug("caching item " + id);
+            }
+            itemCache.put(id, item);
         }
-        itemCache.put(id, item);
     }
 
     /**
@@ -622,11 +627,13 @@
      *
      * @param id id of the item to remove from the cache
      */
-    private synchronized void evictItem(ItemId id) {
+    private void evictItem(ItemId id) {
         if (log.isDebugEnabled()) {
             log.debug("removing item " + id + " from cache");
         }
-        itemCache.remove(id);
+        synchronized (itemCache) {
+            itemCache.remove(id);
+        }
     }
 
     //-------------------------------------------------< misc. helper methods >
@@ -709,21 +716,23 @@
         ps.println();
         ps.println("Items in cache:");
         ps.println();
-        Iterator iter = itemCache.keySet().iterator();
-        while (iter.hasNext()) {
-            ItemId id = (ItemId) iter.next();
-            ItemImpl item = (ItemImpl) itemCache.get(id);
-            if (item.isNode()) {
-                ps.print("Node: ");
-            } else {
-                ps.print("Property: ");
-            }
-            if (item.isTransient()) {
-                ps.print("transient ");
-            } else {
-                ps.print("          ");
+        synchronized (itemCache) {
+            Iterator iter = itemCache.keySet().iterator();
+            while (iter.hasNext()) {
+                ItemId id = (ItemId) iter.next();
+                ItemImpl item = (ItemImpl) itemCache.get(id);
+                if (item.isNode()) {
+                    ps.print("Node: ");
+                } else {
+                    ps.print("Property: ");
+                }
+                if (item.isTransient()) {
+                    ps.print("transient ");
+                } else {
+                    ps.print("          ");
+                }
+                ps.println(id + "\t" + item.safeGetJCRPath() + " (" + item + ")");
             }
-            ps.println(id + "\t" + item.safeGetJCRPath() + " (" + item + ")");
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?view=diff&rev=535830&r1=535829&r2=535830
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
Mon May  7 03:12:16 2007
@@ -538,7 +538,7 @@
         Driver drv = (Driver) Class.forName(driver).newInstance();
         log.info("JDBC driver created: {}", drv);
         con = DriverManager.getConnection(url, user, password);
-        con.setAutoCommit(true);
+        //con.setAutoCommit(true);
 
         // make sure schemaObjectPrefix consists of legal name characters only
         prepareSchemaObjectPrefix();



Mime
View raw message