You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by st...@apache.org on 2004/08/18 15:16:28 UTC

cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core HierarchyManager.java HierarchyManagerImpl.java ItemImpl.java Path.java

stefan      2004/08/18 06:16:28

  Modified:    proposals/jcrri/src/org/apache/slide/jcr/core
                        HierarchyManager.java HierarchyManagerImpl.java
                        ItemImpl.java Path.java
  Log:
  #0000 fixed performance issues when saving on root
  
  Revision  Changes    Path
  1.11      +12 -1     jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManager.java
  
  Index: HierarchyManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HierarchyManager.java	2 Aug 2004 16:21:04 -0000	1.10
  +++ HierarchyManager.java	18 Aug 2004 13:16:27 -0000	1.11
  @@ -60,6 +60,17 @@
       public Path[] getAllPaths(ItemId id) throws ItemNotFoundException, RepositoryException;
   
       /**
  +     *
  +     * @param id
  +     * @param includeZombies
  +     * @return
  +     * @throws ItemNotFoundException
  +     * @throws RepositoryException
  +     */
  +    public Path[] getAllPaths(ItemId id, boolean includeZombies)
  +	    throws ItemNotFoundException, RepositoryException;
  +
  +    /**
        * @param id
        * @return
        * @throws ItemNotFoundException
  
  
  
  1.8       +74 -38    jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManagerImpl.java
  
  Index: HierarchyManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/HierarchyManagerImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HierarchyManagerImpl.java	2 Aug 2004 16:21:04 -0000	1.7
  +++ HierarchyManagerImpl.java	18 Aug 2004 13:16:27 -0000	1.8
  @@ -87,13 +87,13 @@
   	ArrayList list = new ArrayList();
   	try {
   	    if (id.denotesNode()) {
  -		NodeState state = (NodeState) provider.getItemState(id);
  +		NodeState state = (NodeState) getItemState(id, false);
   		Iterator iter = state.getParentUUIDs().iterator();
   		while (iter.hasNext()) {
   		    list.add(new NodeId((String) iter.next()));
   		}
   	    } else {
  -		PropertyState state = (PropertyState) provider.getItemState(id);
  +		PropertyState state = (PropertyState) getItemState(id, false);
   		list.add(new NodeId(state.getParentUUID()));
   	    }
   	} catch (NoSuchItemStateException e) {
  @@ -114,7 +114,7 @@
       public ItemId[] listChildren(NodeId id) throws ItemNotFoundException, RepositoryException {
   	NodeState parentState;
   	try {
  -	    parentState = (NodeState) provider.getItemState(id);
  +	    parentState = (NodeState) getItemState(id, false);
   	} catch (NoSuchItemStateException e) {
   	    String msg = "failed to retrieve state of parent node " + id;
   	    log.error(msg, e);
  @@ -143,29 +143,20 @@
       /**
        * @see HierarchyManager#listZombieChildren(NodeId)
        */
  -    public ItemId[] listZombieChildren(NodeId id) throws ItemNotFoundException, RepositoryException {
  +    public ItemId[] listZombieChildren(NodeId id)
  +	    throws ItemNotFoundException, RepositoryException {
   	// FIXME messy code
   	NodeState parentState;
   	try {
  -	    // get transient/persistent state
  -	    parentState = (NodeState) provider.getItemState(id);
  -	} catch (NoSuchItemStateException e) {
  -	    // try attic
  -	    try {
  -		parentState = (NodeState) provider.getItemStateInAttic(id);
  -	    } catch (NoSuchItemStateException nsise) {
  -		String msg = "failed to retrieve state of parent node " + id;
  -		log.error(msg, nsise);
  -		throw new ItemNotFoundException(msg, nsise);
  -	    } catch (ItemStateException ise) {
  -		String msg = "failed to retrieve state of parent node " + id;
  -		log.error(msg, ise);
  -		throw new RepositoryException(msg, ise);
  -	    }
  -	} catch (ItemStateException e) {
  +	    parentState = (NodeState) getItemState(id, true);
  +	} catch (NoSuchItemStateException nsise) {
   	    String msg = "failed to retrieve state of parent node " + id;
  -	    log.error(msg, e);
  -	    throw new RepositoryException(msg, e);
  +	    log.error(msg, nsise);
  +	    throw new ItemNotFoundException(msg, nsise);
  +	} catch (ItemStateException ise) {
  +	    String msg = "failed to retrieve state of parent node " + id;
  +	    log.error(msg, ise);
  +	    throw new RepositoryException(msg, ise);
   	}
   
   	ArrayList list = new ArrayList();
  @@ -202,7 +193,7 @@
   
   	NodeState parentState;
   	try {
  -	    parentState = (NodeState) provider.getItemState(rootNodeId);
  +	    parentState = (NodeState) getItemState(rootNodeId, false);
   	} catch (ItemStateException e) {
   	    String msg = "failed to retrieve state of root node";
   	    log.error(msg, e);
  @@ -222,7 +213,7 @@
   		    return new NodeId(nodeEntry.getUUID());
   		}
   		try {
  -		    parentState = (NodeState) provider.getItemState(new NodeId(nodeEntry.getUUID()));
  +		    parentState = (NodeState) getItemState(new NodeId(nodeEntry.getUUID()), false);
   		} catch (ItemStateException e) {
   		    String msg = "failed to retrieve state of intermediary node";
   		    log.error(msg, e);
  @@ -257,7 +248,7 @@
   	try {
   	    Path.PathBuilder builder = new Path.PathBuilder();
   
  -	    ItemState state = provider.getItemState(id);
  +	    ItemState state = getItemState(id, false);
   	    String parentUUID = state.getParentUUID();
   	    if (parentUUID == null) {
   		// specified id denotes the root node
  @@ -265,7 +256,7 @@
   		return builder.getPath();
   	    }
   
  -	    NodeState parent = (NodeState) provider.getItemState(new NodeId(parentUUID));
  +	    NodeState parent = (NodeState) getItemState(new NodeId(parentUUID), false);
   	    do {
   		if (state.isNode()) {
   		    NodeState nodeState = (NodeState) state;
  @@ -291,7 +282,7 @@
   		parentUUID = parent.getParentUUID();
   		if (parentUUID != null) {
   		    state = parent;
  -		    parent = (NodeState) provider.getItemState(new NodeId(parentUUID));
  +		    parent = (NodeState) getItemState(new NodeId(parentUUID), false);
   		} else {
   		    parent = null;
   		    state = null;
  @@ -329,14 +320,14 @@
   		throw new ItemNotFoundException(nodeId.toString());
   	    }
   	    try {
  -		NodeState nodeState = (NodeState) provider.getItemState(nodeId);
  +		NodeState nodeState = (NodeState) getItemState(nodeId, false);
   		String parentUUID = nodeState.getParentUUID();
   		if (parentUUID == null) {
   		    // this is the root or an orphaned node
   		    // FIXME
   		    return new QName(NamespaceRegistryImpl.NS_DEFAULT_URI, "");
   		}
  -		parentState = (NodeState) provider.getItemState(new NodeId(parentUUID));
  +		parentState = (NodeState) getItemState(new NodeId(parentUUID), true);
   	    } catch (ItemStateException ise) {
   		String msg = "failed to resolve name of " + nodeId;
   		log.error(msg, ise);
  @@ -361,6 +352,14 @@
        * @see HierarchyManager#getAllPaths(ItemId)
        */
       public synchronized Path[] getAllPaths(ItemId id) throws ItemNotFoundException, RepositoryException {
  +	return getAllPaths(id, false);
  +    }
  +
  +    /**
  +     * @see HierarchyManager#getAllPaths(ItemId, boolean)
  +     */
  +    public synchronized Path[] getAllPaths(ItemId id, boolean includeZombies)
  +	    throws ItemNotFoundException, RepositoryException {
   	Path.PathBuilder builder = new Path.PathBuilder();
   	ArrayList list = new ArrayList();
   	list.add(builder);
  @@ -368,7 +367,7 @@
   	NodeId nodeId = null;
   	if (!id.denotesNode()) {
   	    try {
  -		PropertyState propState = (PropertyState) provider.getItemState(id);
  +		PropertyState propState = (PropertyState) getItemState(id, includeZombies);
   		QName name = propState.getName();
   		// add to path
   		builder.addFirst(name.getNamespaceURI(), name.getLocalName());
  @@ -387,7 +386,7 @@
   	}
   
   	// recursively traverse parent nodes
  -	recursiveBuildPaths(nodeId, builder, list);
  +	recursiveBuildPaths(nodeId, builder, list, includeZombies);
   
   	Path[] paths = new Path[list.size()];
   	int i = 0;
  @@ -406,16 +405,42 @@
       }
   
       /**
  +     *
  +     * @param id
  +     * @param includeZombies
  +     * @return
  +     * @throws NoSuchItemStateException
  +     * @throws ItemStateException
  +     */
  +    private ItemState getItemState(ItemId id, boolean includeZombies)
  +	    throws NoSuchItemStateException, ItemStateException {
  +	if (!includeZombies) {
  +	    // get transient/persistent state
  +	    return provider.getItemState(id);
  +	}
  +
  +	try {
  +	    // try attic first
  +	    return provider.getItemStateInAttic(id);
  +	} catch (NoSuchItemStateException e) {
  +	    // fallback: get transient/persistent state
  +	    return provider.getItemState(id);
  +	}
  +    }
  +
  +    /**
        * @param nodeId
        * @param builder
        * @param builders
  +     * @param includeZombies
        * @throws ItemNotFoundException
        * @throws RepositoryException
        */
  -    private void recursiveBuildPaths(NodeId nodeId, Path.PathBuilder builder, List builders)
  +    private void recursiveBuildPaths(NodeId nodeId, Path.PathBuilder builder,
  +				     List builders, boolean includeZombies)
   	    throws ItemNotFoundException, RepositoryException {
   	try {
  -	    NodeState nodeState = (NodeState) provider.getItemState(nodeId);
  +	    NodeState nodeState = (NodeState) getItemState(nodeId, includeZombies);
   
   	    String uuid = nodeState.getUUID();
   	    /**
  @@ -426,6 +451,9 @@
   	     * entries in the parent uuid list, we put them into a set.
   	     */
   	    HashSet parentUUIDs = new HashSet(nodeState.getParentUUIDs());
  +	    if (includeZombies) {
  +		parentUUIDs.addAll(nodeState.getRemovedParentUUIDs());
  +	    }
   	    if (parentUUIDs.size() == 0) {
   		// nodeId denotes the root node
   		builder.addRoot();
  @@ -444,12 +472,20 @@
   		builders.add(clone);
   	    }
   
  -
   	    Iterator iter = parentUUIDs.iterator();
   	    while (iter.hasNext()) {
   		String parentUUID = (String) iter.next();
  -		NodeState parent = (NodeState) provider.getItemState(new NodeId(parentUUID));
  -		List entries = parent.getChildNodeEntries(uuid);
  +		NodeState parent = (NodeState) getItemState(new NodeId(parentUUID), includeZombies);
  +		ArrayList entries = new ArrayList(parent.getChildNodeEntries(uuid));
  +		if (includeZombies) {
  +		    Iterator riter = parent.getRemovedChildNodeEntries().iterator();
  +		    while (riter.hasNext()) {
  +			NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) riter.next();
  +			if (entry.getUUID().equals(uuid)) {
  +			    entries.add(entry);
  +			}
  +		    }
  +		}
   		if (entries.isEmpty()) {
   		    String msg = "failed to build path of " + nodeId + ": " + parent.getUUID() + " has no child entry for " + uuid;
   		    log.error(msg);
  @@ -478,7 +514,7 @@
   		    pb.addFirst(name.getNamespaceURI(), name.getLocalName(), entry.getIndex());
   
   		    // recurse
  -		    recursiveBuildPaths(new NodeId(parentUUID), pb, builders);
  +		    recursiveBuildPaths(new NodeId(parentUUID), pb, builders, includeZombies);
   		}
   	    }
   	} catch (NoSuchItemStateException nsise) {
  
  
  
  1.19      +12 -4     jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemImpl.java
  
  Index: ItemImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ItemImpl.java	2 Aug 2004 16:21:04 -0000	1.18
  +++ ItemImpl.java	18 Aug 2004 13:16:27 -0000	1.19
  @@ -36,7 +36,10 @@
   import javax.jcr.nodetype.NodeType;
   import javax.jcr.nodetype.PropertyDef;
   import javax.jcr.version.VersionHistory;
  -import java.util.*;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * <code>ItemImpl</code> implements the <code>Item</code> interface.
  @@ -62,6 +65,9 @@
       // jcr:created
       protected static final QName PROPNAME_CREATED =
   	    new QName(NamespaceRegistryImpl.NS_JCR_URI, "created");
  +    // jcr:lastModified
  +    protected static final QName PROPNAME_LAST_MODIFIED =
  +	    new QName(NamespaceRegistryImpl.NS_JCR_URI, "lastModified");
   
       protected static final int STATUS_NORMAL = 0;
       protected static final int STATUS_MODIFIED = 1;
  @@ -133,7 +139,9 @@
       }
   
       protected void finalize() throws Throwable {
  -	state.removeListener(this);
  +	if (state != null) {
  +	    state.removeListener(this);
  +	}
       }
   
       protected void checkItemState() throws InvalidItemStateException {
  @@ -509,7 +517,7 @@
   		    node.internalSetProperty(VersionImpl.PROPNAME_VERSION_HISTORY, InternalValue.create(new UUID(hist.getUUID())));
   		    node.internalSetProperty(VersionImpl.PROPNAME_BASE_VERSION, InternalValue.create(new UUID(hist.getRootVersion().getUUID())));
   		    node.internalSetProperty(VersionImpl.PROPNAME_IS_CHECKED_OUT, InternalValue.create(true));
  -		    node.internalSetProperty(VersionImpl.PROPNAME_PREDESESSORS, new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))});
  +		    node.internalSetProperty(VersionImpl.PROPNAME_PREDECESSORS, new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))});
   		}
   	    }
   	}
  
  
  
  1.11      +48 -1     jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Path.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Path.java	2 Aug 2004 16:21:04 -0000	1.10
  +++ Path.java	18 Aug 2004 13:16:27 -0000	1.11
  @@ -284,6 +284,53 @@
       }
   
       /**
  +     * Determines if <i>this</i> path is an ancestor of the specified path.
  +     *
  +     * @return <code>true</code> if <code>other</code> is a descendant;
  +     *         otherwise <code>false</code>
  +     * @throws MalformedPathException if either the specified path or this path
  +     *                                is a relative path.
  +     */
  +    public boolean isAncestorOf(Path other) throws MalformedPathException {
  +	if (equals(other)) {
  +	    return false;
  +	}
  +	if (other == null) {
  +	    throw new IllegalArgumentException("null argument");
  +	}
  +	// make sure we're comparing canonical paths
  +	Path p0 = getCanonicalPath();
  +	Path p1 = other.getCanonicalPath();
  +	if (p0.elements.length >= p1.elements.length) {
  +	    return false;
  +	}
  +	for (int i = 0; i < p0.elements.length; i++) {
  +	    if (!p0.elements[i].equals(p1.elements[i])) {
  +		 return false;
  +	    }
  +	}
  +	return true;
  +    }
  +
  +    /**
  +     * Determines if <i>this</i> path is a descendant of the specified path.
  +     *
  +     * @return <code>true</code> if <code>other</code> is an ancestor;
  +     *         otherwise <code>false</code>
  +     * @throws MalformedPathException if either the specified path or this path
  +     *                                is a relative path.
  +     */
  +    public boolean isDescendantOf(Path other) throws MalformedPathException {
  +	if (equals(other)) {
  +	    return false;
  +	}
  +	if (other == null) {
  +	    throw new IllegalArgumentException("null argument");
  +	}
  +	return other.isAncestorOf(this);
  +    }
  +
  +    /**
        * Returns the name element (i.e. the last element) of this path.
        *
        * @return the name element of this path
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org