jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r431348 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ state/
Date Mon, 14 Aug 2006 13:42:12 GMT
Author: mreutegg
Date: Mon Aug 14 06:42:11 2006
New Revision: 431348

URL: http://svn.apache.org/viewvc?rev=431348&view=rev
Log:
- Remove node id from NodeState
- Add node name and uuid to NodeState
- Remove unnecessary calls to getId()

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
Mon Aug 14 06:42:11 2006
@@ -192,7 +192,7 @@
     protected void buildPath(Path.PathBuilder builder, ItemState state)
             throws ItemStateException, RepositoryException {
         // shortcut
-        if (state.getId().equals(rootNodeId)) {
+        if (state.getParent() == null) {
             builder.addRoot();
             return;
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Mon Aug 14 06:42:11 2006
@@ -64,6 +64,11 @@
     public static final int STATUS_STALE_DESTROYED = 6;
 
     /**
+     * a new state was deleted and is now 'removed'
+     */
+    public static final int STATUS_REMOVED = 7;
+
+    /**
      * the internal status of this item state
      */
     protected int status = STATUS_UNDEFINED;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Mon Aug 14 06:42:11 2006
@@ -24,6 +24,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.PropertyId;
@@ -53,6 +54,22 @@
     private static Logger log = LoggerFactory.getLogger(NodeState.class);
 
     /**
+     * A current element Path instance.
+     */
+    private static final Path CURRENT_PATH;
+
+    static {
+        try {
+            Path.PathBuilder builder = new Path.PathBuilder();
+            builder.addFirst(Path.CURRENT_ELEMENT);
+            CURRENT_PATH = builder.getPath();
+        } catch (MalformedPathException e) {
+            // path is always valid
+            throw new InternalError("unable to create path from '.'");
+        }
+    }
+
+    /**
      * the name of this node's primary type
      */
     private QName nodeTypeName;
@@ -63,10 +80,15 @@
     private QName[] mixinTypeNames = new QName[0];
 
     /**
-     * TODO: id is not stable unless sole uuid.
-     * The id of this node state.
+     * The UUID of this node state or <code>null</code> if this node state
+     * cannot be identified with a uuid.
+     */
+    private String uuid;
+
+    /**
+     * The name of this node
      */
-    private NodeId id;
+    private QName name;
 
     /**
      * The parent <code>NodeState</code> or <code>null</code> if
this
@@ -109,7 +131,9 @@
     /**
      * Constructs a new node state that is not connected.
      *
-     * @param id            id of this NodeState
+     * @param name          the name of this NodeState
+     * @param uuid          the uuid of this NodeState or <code>null</code> if
+     *                      this node state cannot be identified with a UUID.
      * @param parent        the parent of this NodeState
      * @param nodeTypeName  node type of this node
      * @param initialStatus the initial status of the node state object
@@ -120,11 +144,12 @@
      * @param idFactory     the <code>IdFactory</code> to create new id
      *                      instance.
      */
-    public NodeState(NodeId id, NodeState parent, QName nodeTypeName,
-                     int initialStatus, boolean isTransient,
+    public NodeState(QName name, String uuid, NodeState parent,
+                     QName nodeTypeName, int initialStatus, boolean isTransient,
                      ItemStateFactory isf, IdFactory idFactory) {
         super(initialStatus, isTransient);
-        this.id = id;
+        this.name = name;
+        this.uuid = uuid;
         this.parent = parent;
         this.idFactory = idFactory;
         this.nodeTypeName = nodeTypeName;
@@ -159,7 +184,8 @@
     protected synchronized void copy(ItemState state) {
         synchronized (state) {
             NodeState nodeState = (NodeState) state;
-            id = nodeState.id;
+            name = nodeState.name;
+            uuid = nodeState.uuid;
             parent = nodeState.parent; // TODO: parent from wrong ism layer
             nodeTypeName = nodeState.nodeTypeName;
             mixinTypeNames = nodeState.mixinTypeNames;
@@ -214,15 +240,36 @@
      * {@inheritDoc}
      */
     public ItemId getId() {
-        return id;
+        return getNodeId();
     }
 
     /**
      * Returns the id of this node state.
+     *
      * @return the id of this node state.
      */
     public NodeId getNodeId() {
-        return id;
+        if (uuid != null) {
+            return idFactory.createNodeId(uuid);
+        } else if (parent != null) {
+            // find this in parent child node entries
+            for (Iterator it = parent.getChildNodeEntries(name).iterator(); it.hasNext();
) {
+                ChildNodeEntry cne = (ChildNodeEntry) it.next();
+                try {
+                    if (cne.getNodeState() == this) {
+                        Path relPath = Path.create(cne.getName(), cne.getIndex());
+                        return idFactory.createNodeId(parent.getNodeId(), relPath);
+                    }
+                } catch (ItemStateException e) {
+                    log.warn("Unable to access child node entry: " + cne.getId());
+                }
+            }
+        } else {
+            // root node
+            return idFactory.createNodeId((String) null, CURRENT_PATH);
+        }
+        // TODO: replace with ItemStateException instead of error.
+        throw new InternalError("Unable to retrieve NodeId for NodeState");
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Mon Aug 14 06:42:11 2006
@@ -315,7 +315,7 @@
      *                            to be canceled as well in another sub-tree.
      */
     public void undo(ItemState state) throws ItemStateException {
-        if (rootId.equals(state.getId())) {
+        if (state.getParent() == null) {
             // optimization for root
             transientStateMgr.disposeAllItemStates();
             return;
@@ -620,7 +620,7 @@
      */
     private ChangeLog getChangeLog(ItemState itemState) throws StaleItemStateException, ItemStateException
{
         ChangeLog changeLog = new TransientChangeLog(idFactory, workspaceItemStateMgr);
-        if (rootId.equals(itemState.getId())) {
+        if (itemState.getParent() == null) {
             // root state -> get all item states
             for (Iterator it = transientStateMgr.addedStates(); it.hasNext(); ) {
                 changeLog.added((ItemState) it.next());

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientChangeLog.java
Mon Aug 14 06:42:11 2006
@@ -18,7 +18,6 @@
 
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.PropertyId;
@@ -345,13 +344,7 @@
      * @see TransientItemStateFactory#createNewNodeState(QName, String, NodeState)
      */
     public NodeState createNewNodeState(QName name, String uuid, NodeState parent) {
-        NodeId id;
-        if (uuid == null) {
-            id = idFactory.createNodeId(parent.getNodeId(), Path.create(name, 0));
-        } else {
-            id = idFactory.createNodeId(uuid);
-        }
-        NodeState nodeState = new NodeState(id, parent, null,
+        NodeState nodeState = new NodeState(name, uuid, parent, null,
                 ItemState.STATUS_NEW, true, this, idFactory);
         // get a notification when this item state is saved or invalidated
         nodeState.addListener(this);
@@ -441,7 +434,7 @@
      * @see ItemStateListener#stateCreated(ItemState)
      */
     public void stateCreated(ItemState created) {
-        // TODO: remove from added set of change log
+        addedStates.remove(created);
     }
 
     /**
@@ -449,7 +442,7 @@
      * @see ItemStateListener#stateModified(ItemState)
      */
     public void stateModified(ItemState modified) {
-        // TODO: remove from modified set of change log
+        modifiedStates.remove(modified);
     }
 
     /**
@@ -457,7 +450,7 @@
      * @see ItemStateListener#stateDestroyed(ItemState)
      */
     public void stateDestroyed(ItemState destroyed) {
-        // TODO: remove from deleted set of change log
+        deletedStates.remove(destroyed);
     }
 
     /**
@@ -478,6 +471,51 @@
         // 'existing modified' to 'existing'.
         // a state which changes from 'existing' to 'existing modified' will
         // go into the modified set of the change log, etc.
+        switch (state.getStatus()) {
+            case ItemState.STATUS_EXISTING:
+                if (previousStatus == ItemState.STATUS_EXISTING_MODIFIED) {
+                    // was modified and is now refreshed
+                    modifiedStates.remove(state);
+                } else if (previousStatus == ItemState.STATUS_EXISTING_REMOVED) {
+                    // was removed and is now refreshed
+                    deletedStates.remove(state);
+                } else if (previousStatus == ItemState.STATUS_STALE_MODIFIED) {
+                    // was modified and state and is now refreshed
+                    modifiedStates.remove(state);
+                }
+                break;
+            case ItemState.STATUS_EXISTING_MODIFIED:
+                modifiedStates.add(state);
+                break;
+            case ItemState.STATUS_EXISTING_REMOVED:
+                // check if modified earlier
+                if (previousStatus == ItemState.STATUS_EXISTING_MODIFIED) {
+                    modifiedStates.remove(state);
+                }
+                deletedStates.add(state);
+                break;
+            case ItemState.STATUS_REMOVED:
+                // remove from added
+                addedStates.remove(state);
+                break;
+            case ItemState.STATUS_STALE_DESTROYED:
+                // state is now stale. keep in modified. wait until refreshed.
+                // TODO: how is a stale destroyed state refreshed?
+                break;
+            case ItemState.STATUS_STALE_MODIFIED:
+                // state is now stale. keep in modified. wait until refreshed
+                break;
+            case ItemState.STATUS_NEW:
+                // should never happen
+                log.warn("ItemState changed status to 'new'");
+                break;
+            case ItemState.STATUS_UNDEFINED:
+                // should never happen
+                log.warn("ItemState changed status to 'undefined'");
+                break;
+            default:
+                log.warn("ItemState has invalid status: " + state.getStatus());
+        }
     }
 
     //--------------------------------------------------------< inner classes >

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=431348&r1=431347&r2=431348&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Mon Aug 14 06:42:11 2006
@@ -108,7 +108,11 @@
             // build the node state
             // NOTE: unable to retrieve definitionId -> needs to be retrieved
             // by the itemManager upon Node creation.
-            NodeState state = new NodeState(info.getId(), parent, ntName,
+            String uuid = null;
+            if (info.getId().getRelativePath() == null) {
+                uuid = info.getId().getUUID();
+            }
+            NodeState state = new NodeState(info.getQName(), uuid, parent, ntName,
                     ItemState.STATUS_EXISTING, false, this, service.getIdFactory());
             // set mixin nodetypes
             state.setMixinTypeNames(info.getMixins());



Mime
View raw message