jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r481293 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: ChangeLog.java ItemState.java NodeState.java SessionItemStateManager.java TransientItemStateManager.java
Date Fri, 01 Dec 2006 16:53:19 GMT
Author: angela
Date: Fri Dec  1 08:53:18 2006
New Revision: 481293

URL: http://svn.apache.org/viewvc?view=rev&rev=481293
Log:
work in progress

- cleaning changeLog upon status changes (resolve TODO)
- ChangeLog: make state-sets private

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.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/TransientItemStateManager.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?view=diff&rev=481293&r1=481292&r2=481293
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
Fri Dec  1 08:53:18 2006
@@ -35,17 +35,17 @@
     /**
      * Added states
      */
-    final Set addedStates = new LinkedHashSet();
+    private final Set addedStates = new LinkedHashSet();
 
     /**
      * Modified states
      */
-    final Set modifiedStates = new LinkedHashSet();
+    private final Set modifiedStates = new LinkedHashSet();
 
     /**
      * Deleted states
      */
-    final Set deletedStates = new LinkedHashSet();
+    private final Set deletedStates = new LinkedHashSet();
 
     /**
      * Type of operation this changelog is collection state modifications for.
@@ -170,6 +170,17 @@
     }
 
     /**
+     * Returns true, if this change log contains the given <code>ItemState</code>
+     * in the set of transiently removed states.
+     *
+     * @param state
+     * @return
+     */
+    public boolean containsDeletedState(ItemState state) {
+        return deletedStates.contains(state);
+    }
+
+    /**
      * Removes the subset of this changelog represented by the given
      * <code>ChangeLog</code> from this changelog.
      *
@@ -182,6 +193,72 @@
         deletedStates.removeAll(subChangeLog.deletedStates);
 
         operations.removeAll(subChangeLog.operations);
+    }
+
+    /**
+     * Remove all entries and operation related to the given ItemState, that
+     * are not used any more (respecting the status change).
+     *
+     * @param state
+     */
+    public void removeAffected(ItemState state, int previousStatus) {
+        switch (state.getStatus()) {
+            case (Status.EXISTING):
+                switch (previousStatus) {
+                    case Status.EXISTING_MODIFIED:
+                        // was modified and is now refreshed
+                        modifiedStates.remove(state);
+                        break;
+                    case Status.EXISTING_REMOVED:
+                        // was removed and is now refreshed
+                        deletedStates.remove(state);
+                        break;
+                    case Status.STALE_MODIFIED:
+                        // was modified and state and is now refreshed
+                        modifiedStates.remove(state);
+                        break;
+                    case Status.NEW:
+                        // was new and has been saved now
+                        addedStates.remove(state);
+                        break;
+                }
+                // TODO: check if correct: changelog gets cleared any way -> no need to
remove operations
+                break;
+            case Status.EXISTING_MODIFIED:
+                modified(state);
+                break;
+            case (Status.REMOVED):
+                if (previousStatus == Status.NEW) {
+                    // was new and now removed again
+                    addedStates.remove(state);
+                    // TODO: remove 'addNode' or 'setProperty' operation
+                    deletedStates.remove(state);
+                    removeAffectedOperations(state);
+                } else if (previousStatus == Status.EXISTING_REMOVED) {
+                    // was removed and is now saved
+                    deletedStates.remove(state);
+                    removeAffectedOperations(state);
+                }
+                break;
+            case (Status.EXISTING_REMOVED):
+                deleted(state);
+                removeAffectedOperations(state);
+                break;
+            case Status.STALE_DESTROYED:
+                // state is now stale. remove from modified
+                modifiedStates.remove(state);
+                removeAffectedOperations(state);
+                break;
+        }
+    }
+
+    private void removeAffectedOperations(ItemState state) {
+        for (Iterator it = operations.iterator(); it.hasNext();) {
+            Operation op = (Operation) it.next();
+            if (op.getAffectedItemStates().contains(state)) {
+                it.remove();
+            }
+        }
     }
 
     /**

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?view=diff&rev=481293&r1=481292&r2=481293
==============================================================================
--- 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
Fri Dec  1 08:53:18 2006
@@ -286,7 +286,6 @@
             force the overlaying state to synchronize as well as to inform
             other listeners about changes.
             */
-            // TODO: improve...
             status = Status.EXISTING;
         }
     }

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?view=diff&rev=481293&r1=481292&r2=481293
==============================================================================
--- 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
Fri Dec  1 08:53:18 2006
@@ -876,7 +876,7 @@
 
             // adjust parent states unless the parent is removed as well
             NodeState parent = state.getParent();
-            if (!changeLog.deletedStates.contains(parent)) {
+            if (!changeLog.containsDeletedState(parent)) {
                 NodeState overlayedParent = (NodeState) parent.overlayedState;
                 if (state.isNode()) {
                     overlayedParent.childNodeEntries.remove((NodeState)state.overlayedState);

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?view=diff&rev=481293&r1=481292&r2=481293
==============================================================================
--- 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 Dec  1 08:53:18 2006
@@ -482,8 +482,10 @@
             | ItemStateValidator.CHECK_VERSIONING
             | ItemStateValidator.CHECK_CONSTRAINTS;
         removeItemState(state, options);
-        // remember operation
-        transientStateMgr.addOperation(operation);
+        // remember operation unless new state got removed
+        if (!Status.isTerminal(state.getStatus())) {
+            transientStateMgr.addOperation(operation);
+        }
     }
 
     /**

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?view=diff&rev=481293&r1=481292&r2=481293
==============================================================================
--- 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 Dec  1 08:53:18 2006
@@ -236,61 +236,21 @@
 
     //-----------------------------------------< ItemStateLifeCycleListener >---
     /**
-     * @inheritDoc
+     * Depending on status of the given state adapt change log.
+     * E.g. a revert on states will reset the status from 'existing modified' to
+     * 'existing'. A state which changes from 'existing' to 'existing modified'
+     * will go into the modified set of the change log, etc.
+     *
      * @see ItemStateLifeCycleListener#statusChanged(ItemState, int)
      */
     public void statusChanged(ItemState state, int previousStatus) {
-        // TODO: depending on status of state adapt change log
-        // e.g. a revert on states will reset the status from
-        // '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 Status.EXISTING:
-                switch (previousStatus) {
-                    case Status.EXISTING_MODIFIED:
-                        // was modified and is now refreshed
-                        changeLog.modifiedStates.remove(state);
-                        break;
-                    case Status.EXISTING_REMOVED:
-                        // was removed and is now refreshed
-                        changeLog.deletedStates.remove(state);
-                        break;
-                    case Status.STALE_MODIFIED:
-                        // was modified and state and is now refreshed
-                        changeLog.modifiedStates.remove(state);
-                        break;
-                    case Status.NEW:
-                        // was new and has been saved now
-                        changeLog.addedStates.remove(state);
-                        break;
-                }
-                break;
             case Status.EXISTING_MODIFIED:
-                changeLog.modified(state);
-                break;
             case Status.EXISTING_REMOVED:
-                // check if modified earlier
-                if (previousStatus == Status.EXISTING_MODIFIED) {
-                    changeLog.modifiedStates.remove(state);
-                    // todo: remove operation(s) as well
-                }
-                changeLog.deleted(state);
-                break;
             case Status.REMOVED:
-                if (previousStatus == Status.NEW) {
-                    // was new and now removed again
-                    changeLog.addedStates.remove(state);
-                    // TODO: remove operation as well
-                } else if (previousStatus == Status.EXISTING_REMOVED) {
-                    // was removed and is now saved
-                    changeLog.deletedStates.remove(state);
-                }
-                break;
             case Status.STALE_DESTROYED:
-                // state is now stale. remove from modified
-                changeLog.modifiedStates.remove(state);
-                // TODO: remove operation as well
+                changeLog.removeAffected(state, previousStatus);
                 break;
             case Status.STALE_MODIFIED:
                 // state is now stale. keep in modified. wait until refreshed



Mime
View raw message