jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r332056 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ItemManager.java state/SharedItemStateManager.java
Date Wed, 09 Nov 2005 14:56:34 GMT
Author: stefan
Date: Wed Nov  9 06:56:29 2005
New Revision: 332056

URL: http://svn.apache.org/viewcvs?rev=332056&view=rev
Log:
avoid to keep hard references to ItemImpl & ItemState instances

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=332056&r1=332055&r2=332056&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Wed Nov  9 06:56:29 2005
@@ -86,8 +86,6 @@
     private final ItemStateManager itemStateProvider;
     private final HierarchyManager hierMgr;
 
-    private NodeImpl root;
-
     /**
      * A cache for item instances created by this <code>ItemManager</code>
      */
@@ -115,29 +113,6 @@
     }
 
     /**
-     * Returns the root node instance of the repository.
-     *
-     * @return the root node.
-     * @throws RepositoryException
-     */
-    private synchronized NodeImpl getRoot() throws RepositoryException {
-        // lazy instantiation of root node
-        // to avoid chicken & egg kind of problems
-        if (root == null) {
-            try {
-                NodeState rootState = (NodeState) itemStateProvider.getItemState(rootNodeId);
-                // keep a hard reference to root node
-                root = createNodeInstance(rootState, rootNodeDef);
-            } catch (ItemStateException ise) {
-                String msg = "failed to retrieve state of root node";
-                log.debug(msg);
-                throw new RepositoryException(msg, ise);
-            }
-        }
-        return root;
-    }
-
-    /**
      * Disposes this <code>ItemManager</code> and frees resources.
      */
     void dispose() {
@@ -300,7 +275,7 @@
      * @throws RepositoryException
      */
     NodeImpl getRootNode() throws RepositoryException {
-        return getRoot();
+        return (NodeImpl) getItem(rootNodeId);
     }
 
     /**
@@ -340,13 +315,8 @@
         // check cache
         ItemImpl item = retrieveItem(id);
         if (item == null) {
-            // shortcut
-            if (id.denotesNode() && id.equals(rootNodeId)) {
-                item = getRoot();
-            } else {
-                // create instance of item using its state object
-                item = createItemInstance(id);
-            }
+            // create instance of item
+            item = createItemInstance(id);
         }
         return item;
     }
@@ -501,7 +471,10 @@
             throw new RepositoryException(msg, ise);
         }
 
-        if (state.isNode()) {
+        if (id.equals(rootNodeId)) {
+            // special handling required for root node
+            item = createNodeInstance((NodeState) state, rootNodeDef);
+        } else if (state.isNode()) {
             item = createNodeInstance((NodeState) state);
         } else {
             item = createPropertyInstance((PropertyState) state);

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=332056&r1=332055&r2=332056&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Wed Nov  9 06:56:29 2005
@@ -130,9 +130,9 @@
     private final NodeTypeRegistry ntReg;
 
     /**
-     * Keep a hard reference to the root node state
+     * uuid of root node
      */
-    private NodeState root;
+    private final String rootNodeUUID;
 
     /**
      * Virtual item state providers
@@ -160,12 +160,10 @@
         cache = new ItemStateReferenceCache();
         this.persistMgr = persistMgr;
         this.ntReg = ntReg;
-
-        try {
-            root = (NodeState) getNonVirtualItemState(new NodeId(rootNodeUUID));
-        } catch (NoSuchItemStateException e) {
-            // create root node
-            root = createRootNodeState(rootNodeUUID, ntReg);
+        this.rootNodeUUID = rootNodeUUID;
+        // create root node state if it doesn't yet exist
+        if (!hasNonVirtualItemState(new NodeId(rootNodeUUID))) {
+            createRootNodeState(rootNodeUUID, ntReg);
         }
     }
 
@@ -496,7 +494,7 @@
 
                 /* create event states */
                 if (events != null) {
-                    events.createEventStates(root.getUUID(), local, this);
+                    events.createEventStates(rootNodeUUID, local, this);
                 }
 
                 /* Push all changes from the local items to the shared items */



Mime
View raw message