jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r432523 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: SessionItemStateManager.java TransientItemStateManager.java
Date Fri, 18 Aug 2006 08:47:19 GMT
Author: mreutegg
Date: Fri Aug 18 01:47:16 2006
New Revision: 432523

URL: http://svn.apache.org/viewvc?rev=432523&view=rev
Log:
- Implement SessionItemStateManager.getRootState()
- Use ItemState from TransientItemStateManager and check status in methods SessionItemStateManager.getItemState()
and SessionItemStateManager.hasItemState()
- Rename some methods in TransientItemStateManager to clarify their use.
- Remove unused metho TransientItemStateManager.moveItemStateToAttic().

Modified:
    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/TransientItemStateManager.java

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=432523&r1=432522&r2=432523&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
Fri Aug 18 01:47:16 2006
@@ -112,11 +112,6 @@
     private final ItemStateValidator validator;
 
     /**
-     * The root node state or <code>null</code> if it hasn't been retrieved yet.
-     */
-    private NodeState rootNodeState;
-
-    /**
      * Creates a new <code>SessionItemStateManager</code> instance.
      *
      * @param workspaceItemStateMgr
@@ -154,8 +149,8 @@
      * @see ItemStateManager#getRootState()
      */
     public NodeState getRootState() throws ItemStateException {
-        // TODO
-        return null;
+        // always retrieve from transientStateMgr
+        return transientStateMgr.getRootState();
     }
 
     /**
@@ -165,29 +160,13 @@
     public ItemState getItemState(ItemId id)
             throws NoSuchItemStateException, ItemStateException {
 
-        // first check if the specified item has been transiently removed
-        if (transientStateMgr.getAttic().hasItemState(id)) {
-            /**
-             * check if there's new transient state for the specified item
-             * (e.g. if a property with name 'x' has been removed and a new
-             * property with same name has been created);
-             * this will throw a NoSuchItemStateException if there's no new
-             * transient state
-             */
-            return transientStateMgr.getItemState(id);
-        }
-
-        // check if there's transient state for the specified item
-        if (transientStateMgr.hasItemState(id)) {
-            return transientStateMgr.getItemState(id);
-        }
-
-        // check if there's persistent state for the specified item
-        if (workspaceItemStateMgr.hasItemState(id)) {
-            return workspaceItemStateMgr.getItemState(id);
+        ItemState itemState = transientStateMgr.getItemState(id);
+        // check status of ItemState. Transient ISM also returns removed ItemStates
+        if (itemState.isValid()) {
+            return itemState;
+        } else {
+            throw new NoSuchItemStateException(id.toString());
         }
-
-        throw new NoSuchItemStateException(id.toString());
     }
 
     /**
@@ -195,21 +174,19 @@
      * @see ItemStateManager#hasItemState(ItemId)
      */
     public boolean hasItemState(ItemId id) {
-        // first check if the specified item has been transiently removed
-        if (transientStateMgr.getAttic().hasItemState(id)) {
-            /**
-             * check if there's new transient state for the specified item
-             * (e.g. if a property with name 'x' has been removed and a new
-             * property with same name has been created);
-             */
-            return transientStateMgr.hasItemState(id);
-        }
-        // check if there's transient state for the specified item
+        // first check if the specified item exists at all in the transient ISM
         if (transientStateMgr.hasItemState(id)) {
-            return true;
+            // retrieve item and check state
+            try {
+                ItemState itemState = transientStateMgr.getItemState(id);
+                if (itemState.isValid()) {
+                    return true;
+                }
+            } catch (ItemStateException e) {
+                // has been removed in the meantime
+            }
         }
-        // check if there's persistent state for the specified item
-        return workspaceItemStateMgr.hasItemState(id);
+        return false;
     }
 
     /**
@@ -267,8 +244,7 @@
      *         <code>false</code> otherwise.
      */
     public boolean hasPendingChanges() {
-        // DIFF JACKRABBIT: return transientStateMgr.hasAnyItemStates();
-        return transientStateMgr.getEntriesCount() > 0;
+        return transientStateMgr.hasPendingChanges();
     }
 
     /**
@@ -469,8 +445,7 @@
      * @return an iterator over descendant transient item state instances
      */
     private Iterator getDescendantTransientItemStates(NodeState parent) {
-        // DIFF JACKRABBIT: if (!transientStateMgr.hasAnyItemStates()) {
-        if (transientStateMgr.getEntriesCount() == 0) {
+        if (!transientStateMgr.hasPendingChanges()) {
             return Collections.EMPTY_LIST.iterator();
         }
 
@@ -481,7 +456,7 @@
         // the depth is used as array index
         List[] la = new List[10];
         try {
-            Iterator iter = transientStateMgr.getEntries();
+            Iterator iter = transientStateMgr.getModifiedOrAddedItemStates();
             while (iter.hasNext()) {
                 ItemState state = (ItemState) iter.next();
                 // determine relative depth: > 0 means it's a descendant
@@ -560,7 +535,7 @@
      */
     private Iterator getDescendantTransientItemStatesInAttic(NodeState parent) {
         // DIFF JACKRABBIT: if (!transientStateMgr.hasAnyItemStatesInAttic()) {
-        if (!transientStateMgr.hasEntriesInAttic()) {
+        if (!transientStateMgr.hasDeletedItemStates()) {
             return Collections.EMPTY_LIST.iterator();
         }
 
@@ -575,7 +550,7 @@
         // the depth is used as array index
         List[] la = new List[10];
         try {
-            Iterator iter = transientStateMgr.getEntriesInAttic();
+            Iterator iter = transientStateMgr.getDeletedItemStates();
             while (iter.hasNext()) {
                 ItemState state = (ItemState) iter.next();
                 // determine relative depth: > 0 means it's a descendant

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=432523&r1=432522&r2=432523&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
Fri Aug 18 01:47:16 2006
@@ -180,23 +180,23 @@
     }
 
     /**
-     * @return the number of entries
+     * @return <code>true</code> if this transient ISM has pending changes.
      */
-    public int getEntriesCount() {
-        return changeLog.addedStates.size() + changeLog.modifiedStates.size();
+    public boolean hasPendingChanges() {
+        return !changeLog.isEmpty();
     }
 
     /**
-     * @return <code>true</code> if there are any entries in attic.
+     * @return <code>true</code> if there are any deleted item states.
      */
-    public boolean hasEntriesInAttic() {
-        return changeLog.deletedStates.size() > 0;
+    public boolean hasDeletedItemStates() {
+        return !changeLog.deletedStates.isEmpty();
     }
 
     /**
-     * @return an iterator over all entries
+     * @return an iterator over all modified or added item states.
      */
-    public Iterator getEntries() {
+    public Iterator getModifiedOrAddedItemStates() {
         IteratorChain it = new IteratorChain();
         it.addIterator(changeLog.modifiedStates());
         it.addIterator(changeLog.addedStates());
@@ -204,9 +204,9 @@
     }
 
     /**
-     * @return an iterator over all entries in attic
+     * @return an iterator over all deleted item states.
      */
-    public Iterator getEntriesInAttic() {
+    public Iterator getDeletedItemStates() {
         return changeLog.deletedStates();
     }
 
@@ -268,21 +268,6 @@
             changeLog.modifiedStates.remove(state);
         }
         state.onDisposed();
-    }
-
-    /**
-     * A state has been deleted. If the state is not a new state
-     * (not in the collection of added ones), then remove
-     * it from the modified states collection.
-     * The state is added to the deleted states collection in any case.
-     *
-     * @param state state that has been deleted
-     */
-    public void moveItemStateToAttic(ItemState state) {
-        if (changeLog.addedStates.remove(state)) {
-            changeLog.modifiedStates.remove(state);
-        }
-        changeLog.deleted(state);
     }
 
     /**



Mime
View raw message