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/06/24 18:31:07 UTC

cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/state TransientItemStateManager.java

stefan      2004/06/24 09:31:07

  Modified:    proposals/jcrri ToDo.txt
               proposals/jcrri/src/org/apache/slide/jcr/core
                        HierarchyManager.java ItemImpl.java
                        ItemManager.java NodeImpl.java
               proposals/jcrri/src/org/apache/slide/jcr/core/nodetype
                        nodetypes.xml
               proposals/jcrri/src/org/apache/slide/jcr/core/state
                        TransientItemStateManager.java
  Log:
  jcrri
  
  Revision  Changes    Path
  1.3       +1 -0      jakarta-slide/proposals/jcrri/ToDo.txt
  
  Index: ToDo.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/ToDo.txt,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ToDo.txt	22 Jun 2004 18:04:00 -0000	1.2
  +++ ToDo.txt	24 Jun 2004 16:31:06 -0000	1.3
  @@ -60,6 +60,7 @@
     - trap JVM shutdown in RepositoryFactory? (Runtime#addShutdownHook)
   - ItemState: hide STATUS_* flags, use set* and is* methods instead
   - javaDoc, javaDoc, javaDoc
  +- logging: use commons logginh instead of log4j
   - logging: remove unnecessary output, check log categories/verbosity, 
     use 'debug' whenever possible
       
  
  
  
  1.5       +3 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HierarchyManager.java	22 Jun 2004 18:03:24 -0000	1.4
  +++ HierarchyManager.java	24 Jun 2004 16:31:06 -0000	1.5
  @@ -57,7 +57,7 @@
        * @throws ItemNotFoundException
        * @throws RepositoryException
        */
  -    public QName getName(NodeId id) throws ItemNotFoundException, RepositoryException;
  +    public QName getName(ItemId id) throws ItemNotFoundException, RepositoryException;
   
       /**
        * @param id
  
  
  
  1.5       +72 -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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ItemImpl.java	22 Jun 2004 18:03:24 -0000	1.4
  +++ ItemImpl.java	24 Jun 2004 16:31:06 -0000	1.5
  @@ -694,6 +694,74 @@
   	    return;
   	}
   
  +	// check that parent node is also included in the dirty items list
  +	// if dirty node was removed or added (adding/removing a parent/child
  +	// link requires that both parent and child are saved)
  +	Iterator iter = dirty.iterator();
  +	while (iter.hasNext()) {
  +	    transientState = (ItemState) iter.next();
  +	    if (transientState.isNode()) {
  +		// check if the parent list of the node
  +		// has been modified
  +		NodeState newState = (NodeState) transientState;
  +		NodeState oldState = (NodeState) transientState.getOverlayedState();
  +		if (oldState != null) {
  +		    List oldParentList = oldState.getParentUUIDs();
  +		    List newParentList = newState.getParentUUIDs();
  +		    if (!newParentList.equals(oldParentList)) {
  +			// the parent list of this node has been modified;
  +			// removed parents
  +			ArrayList diff = new ArrayList(oldParentList);
  +			if (diff.removeAll(newParentList)) {
  +			    for (int i = 0; i < diff.size(); i++) {
  +				NodeId id = new NodeId((String) diff.get(i));
  +				NodeState parentState = null;
  +				try {
  +				    parentState = (NodeState) itemMgr.getTransientStateMgr().getItemState(id);
  +				} catch (NoSuchItemStateException nsise) {
  +				    // should never get here...
  +				    String msg = "inconsistency: no transient state found for " + itemMgr.safeGetJCRPath(id);
  +				    log.error(msg);
  +				    throw new RepositoryException(msg);
  +				}
  +				// check if parent is also going to be saved
  +				if (!dirty.contains(parentState)) {
  +				    // need to save the parent too
  +				    String msg = itemMgr.safeGetJCRPath(id) + " needs to be saved also.";
  +				    log.error(msg);
  +				    throw new RepositoryException(msg);
  +				}
  +			    }
  +			}
  +			// added parents
  +			diff.clear();
  +			diff.addAll(newParentList);
  +			if (diff.removeAll(oldParentList)) {
  +			    for (int i = 0; i < diff.size(); i++) {
  +				NodeId id = new NodeId((String) diff.get(i));
  +				NodeState parentState = null;
  +				try {
  +				    parentState = (NodeState) itemMgr.getTransientStateMgr().getItemState(id);
  +				} catch (NoSuchItemStateException nsise) {
  +				    // should never get here...
  +				    String msg = "internal error: no transient state found for " + itemMgr.safeGetJCRPath(id);
  +				    log.error(msg);
  +				    throw new RepositoryException(msg);
  +				}
  +				// check if parent is also going to be saved
  +				if (!dirty.contains(parentState)) {
  +				    // need to save the parent too
  +				    String msg = itemMgr.safeGetJCRPath(id) + " needs to be saved also.";
  +				    log.error(msg);
  +				    throw new RepositoryException(msg);
  +				}
  +			    }
  +			}
  +		    }
  +		}
  +	    }
  +	}
  +
   	// validate access and node type constraints
   	// (this will also validate child removals)
   	validateTransientItems(dirty.iterator());
  @@ -702,7 +770,7 @@
   	    // build list of transient descendents in the attic
   	    // (i.e. those marked as 'removed')
   	    ArrayList removed = new ArrayList();
  -	    Iterator iter = itemMgr.getTransientStateMgr().getDescendantItemStatesInAttic(id);
  +	    iter = itemMgr.getTransientStateMgr().getDescendantItemStatesInAttic(id);
   	    while (iter.hasNext()) {
   		transientState = (ItemState) iter.next();
   		// check if stale
  @@ -737,7 +805,7 @@
   	persistTransientItems(dirty.iterator());
   
   	// now it is safe to dispose the transient states
  -	Iterator iter = dirty.iterator();
  +	iter = dirty.iterator();
   	while (iter.hasNext()) {
   	    transientState = (ItemState) iter.next();
   	    // dispose the transient state, it is no longer used
  
  
  
  1.5       +31 -25    jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemManager.java
  
  Index: ItemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ItemManager.java	22 Jun 2004 18:03:07 -0000	1.4
  +++ ItemManager.java	24 Jun 2004 16:31:06 -0000	1.5
  @@ -773,33 +773,39 @@
       }
   
       /**
  -     * @see HierarchyManager#getName(NodeId)
  +     * @see HierarchyManager#getName(ItemId)
        */
  -    public QName getName(NodeId id) throws ItemNotFoundException, RepositoryException {
  -	NodeState parentState;
  -	try {
  -	    NodeState nodeState = (NodeState) getItemState(id);
  -	    String parentUUID = nodeState.getParentUUID();
  -	    if (parentUUID == null) {
  -		// this is the root or an orphaned node
  -		// FIXME
  -		return new QName(NamespaceRegistryImpl.NS_DEFAULT_URI, "");
  +    public QName getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
  +	if (itemId.denotesNode()) {
  +	    NodeId nodeId = (NodeId) itemId;
  +	    NodeState parentState;
  +	    try {
  +		NodeState nodeState = (NodeState) getItemState(nodeId);
  +		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) getItemState(new NodeId(parentUUID));
  +	    } catch (NoSuchItemStateException nsise) {
  +		String msg = "failed to resolve name of " + nodeId;
  +		log.error(msg, nsise);
  +		throw new RepositoryException(msg, nsise);
   	    }
  -	    parentState = (NodeState) getItemState(new NodeId(parentUUID));
  -	} catch (NoSuchItemStateException nsise) {
  -	    String msg = "failed to resolve name of " + id;
  -	    log.error(msg, nsise);
  -	    throw new RepositoryException(msg, nsise);
  -	}
   
  -	List entries = parentState.getChildNodeEntries(id.getUUID());
  -	if (entries.size() == 0) {
  -	    String msg = "failed to resolve name of " + id;
  -	    log.error(msg);
  -	    throw new RepositoryException(msg);
  +	    List entries = parentState.getChildNodeEntries(nodeId.getUUID());
  +	    if (entries.size() == 0) {
  +		String msg = "failed to resolve name of " + nodeId;
  +		log.error(msg);
  +		throw new RepositoryException(msg);
  +	    }
  +	    NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  +	    return entry.getName();
  +	} else {
  +	    PropertyId propId = (PropertyId) itemId;
  +	    return propId.getName();
   	}
  -	NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) entries.get(0);
  -	return entry.getName();
       }
   
       /**
  
  
  
  1.15      +3 -3      jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- NodeImpl.java	22 Jun 2004 18:03:07 -0000	1.14
  +++ NodeImpl.java	24 Jun 2004 16:31:06 -0000	1.15
  @@ -469,7 +469,7 @@
   	}
   
   	//QName name = getPrimaryPath().getNameElement().getName();
  -	QName name = itemMgr.getName((NodeId) id);
  +	QName name = itemMgr.getName(id);
   	return name.toJCRName(ticket.getNamespaceResolver());
       }
   
  
  
  
  1.3       +2 -2      jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/nodetypes.xml
  
  Index: nodetypes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/nodetypes.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- nodetypes.xml	21 Jun 2004 09:37:41 -0000	1.2
  +++ nodetypes.xml	24 Jun 2004 16:31:07 -0000	1.3
  @@ -80,7 +80,7 @@
       </nodeType>
       <nodeType name="nt:childNodeDef" mixin="false" orderableChildNodes="false" supertypes="nt:base">
   	<propertyDef name="jcr:name" type="String" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="false"/>
  -	<propertyDef name="jcr:requiredPrimaryTypes" type="String" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="true"/>
  +	<propertyDef name="jcr:requiredPrimaryTypes" type="String" valueConstraint="" defaultValue="nt:base" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="true"/>
   	<propertyDef name="jcr:defaultPrimaryType" type="String" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="false"/>
   	<propertyDef name="jcr:autoCreate" type="Boolean" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="false"/>
   	<propertyDef name="jcr:mandatory" type="Boolean" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="COPY" protected="false" primaryItem="false" multiple="false"/>
  @@ -102,7 +102,7 @@
   	<propertyDef name="jcr:frozenMixinTypes" type="String" valueConstraint="" defaultValue="" autoCreate="false" mandatory="false" onParentVersion="ABORT" protected="true" primaryItem="false" multiple="true"/>
   	<propertyDef name="jcr:frozenUUID" type="String" valueConstraint="" defaultValue="" autoCreate="true" mandatory="true" onParentVersion="ABORT" protected="true" primaryItem="false" multiple="false"/>
   	<propertyDef name="" type="Undefined" valueConstraint="" defaultValue="" autoCreate="false" mandatory="false" onParentVersion="ABORT" protected="true" primaryItem="false" multiple="true"/>
  -	<childNodeDef name="" requiredPrimaryTypes="" defaultPrimaryType="" autoCreate="false" mandatory="false" onParentVersion="ABORT" protected="false" primaryItem="false" sameNameSibs="true"/>
  +	<childNodeDef name="" requiredPrimaryTypes="nt:base" defaultPrimaryType="" autoCreate="false" mandatory="false" onParentVersion="ABORT" protected="false" primaryItem="false" sameNameSibs="true"/>
       </nodeType>
       <nodeType name="nt:query" mixin="false" orderableChildNodes="false" supertypes="nt:base">
   	<propertyDef name="jcr:statement" type="String" valueConstraint="" defaultValue="" autoCreate="false" mandatory="false" onParentVersion="COPY" protected="false" primaryItem="false" multiple="false"/>
  
  
  
  1.6       +17 -2     jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/state/TransientItemStateManager.java
  
  Index: TransientItemStateManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/state/TransientItemStateManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TransientItemStateManager.java	22 Jun 2004 18:02:33 -0000	1.5
  +++ TransientItemStateManager.java	24 Jun 2004 16:31:07 -0000	1.6
  @@ -72,6 +72,21 @@
   		    // recurse
   		    collectDescendantItemStates(childId, descendents);
   		}
  +		// also add transient child nodes that have been unlinked from
  +		// the specified parent node but are not orphaned yet (i.e.
  +		// they are still linked to at least one other parent node)
  +		if (isCached(parentId)) {
  +		    NodeState parentState = (NodeState) retrieve(parentId);
  +		    Iterator iter = parentState.getRemovedChildNodeEntries().iterator();
  +		    while (iter.hasNext()) {
  +			// removed child nodes
  +			NodeState.ChildNodeEntry cne = (NodeState.ChildNodeEntry) iter.next();
  +			NodeId removedChildId = new NodeId(cne.getUUID());
  +			if (isCached(removedChildId)) {
  +			    descendents.add(retrieve(removedChildId));
  +			}
  +		    }
  +		}
   	    }
   	} catch (RepositoryException re) {
   	    log.warn("inconsistent hierarchy state", re);
  
  
  

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