jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r160563 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: CachingHierarchyManager.java HierarchyManager.java HierarchyManagerImpl.java ItemImpl.java
Date Fri, 08 Apr 2005 17:10:42 GMT
Author: stefan
Date: Fri Apr  8 10:10:39 2005
New Revision: 160563

URL: http://svn.apache.org/viewcvs?view=rev&rev=160563
Log:
optimized Item.getDepth()

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?view=diff&r1=160562&r2=160563
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Fri Apr  8 10:10:39 2005
@@ -134,6 +134,18 @@
     /**
      * {@inheritDoc}
      */
+    public int getDepth(ItemId id)
+            throws ItemNotFoundException, RepositoryException {
+        if (pathCache.containsKey(id)) {
+            return getPath(id).getAncestorCount();
+        } else {
+            return delegatee.getDepth(id);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public synchronized Path[] getAllPaths(ItemId id)
             throws ItemNotFoundException, RepositoryException {
         return getAllPaths(id, false);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java?view=diff&r1=160562&r2=160563
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManager.java Fri
Apr  8 10:10:39 2005
@@ -50,6 +50,16 @@
     public QName getName(ItemId id) throws ItemNotFoundException, RepositoryException;
 
     /**
+     * Returns the depth of the specified item which is equivalent to
+     * <code>getPath(id).getAncestorCount()</code>.  
+     * @param id
+     * @return
+     * @throws ItemNotFoundException
+     * @throws RepositoryException
+     */
+    public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException;
+
+    /**
      * @param id
      * @return
      * @throws ItemNotFoundException

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java?view=diff&r1=160562&r2=160563
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
Fri Apr  8 10:10:39 2005
@@ -372,6 +372,31 @@
     /**
      * {@inheritDoc}
      */
+    public int getDepth(ItemId id)
+            throws ItemNotFoundException, RepositoryException {
+        try {
+            int depth = 0;
+            ItemState state = getItemState(id);
+            for (String parentUUID = state.getParentUUID(); parentUUID != null;) {
+                state = (NodeState) getItemState(new NodeId(parentUUID));
+                parentUUID = state.getParentUUID();
+                depth++;
+            }
+            return depth;
+        } catch (NoSuchItemStateException nsise) {
+            String msg = "failed to determine depth of " + id;
+            log.debug(msg);
+            throw new ItemNotFoundException(msg, nsise);
+        } catch (ItemStateException ise) {
+            String msg = "failed to determine depth of " + id;
+            log.debug(msg);
+            throw new RepositoryException(msg, ise);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public synchronized Path[] getAllPaths(ItemId id) throws ItemNotFoundException, RepositoryException
{
         return getAllPaths(id, false);
     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java?view=diff&r1=160562&r2=160563
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java Fri Apr 
8 10:10:39 2005
@@ -1438,7 +1438,11 @@
      * {@inheritDoc}
      */
     public int getDepth() throws RepositoryException {
-        return getPrimaryPath().getAncestorCount();
+        if (state.getParentUUID() == null) {
+            // shortcut
+            return 0;
+        }
+        return session.getHierarchyManager().getDepth(id);
     }
 
     /**



Mime
View raw message