jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r474319 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ItemImpl.java state/ChangeLog.java state/ItemState.java state/NodeState.java state/PropertyState.java state/Status.java
Date Mon, 13 Nov 2006 13:56:22 GMT
Author: angela
Date: Mon Nov 13 05:56:21 2006
New Revision: 474319

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

- add invalidate(), refresh() to NodeState (missing impl)
- rename ItemState.refresh(ChangeLog) to persisted(ChangeLog)
- Item.refresh(boolean) must not call checkStatus. a stale, invalidated
  item may be refreshed unless its state has a terminal status (removed, stale_destroyed).
ItemState.refresh() is therefore called after reverting transient modifications only.
- javadoc and some comments

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

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?view=diff&rev=474319&r1=474318&r2=474319
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
Mon Nov 13 05:56:21 2006
@@ -241,15 +241,21 @@
      * @see javax.jcr.Item#refresh(boolean)
      */
     public void refresh(boolean keepChanges) throws InvalidItemStateException, RepositoryException
{
-        checkStatus();
+        // check session status
+        session.checkIsAlive();
+        // check if item has been removed
+        if (Status.isTerminal(state.getStatus())) {
+            throw new InvalidItemStateException("Item '" + this + "' doesn't exist anymore");
+        }
 
-        if (!keepChanges) {
+        if (keepChanges) {
+            state.refresh();
+        } else {
             // check status of this item's state
-            switch (state.getStatus()) {
-                case Status.NEW:
-                    String msg = "Cannot refresh a new item (" + safeGetJCRPath() + ").";
-                    log.debug(msg);
-                    throw new RepositoryException(msg);
+            if (state.getStatus() == Status.NEW) {
+                String msg = "Cannot refresh a new item (" + safeGetJCRPath() + ").";
+                log.debug(msg);
+                throw new RepositoryException(msg);
             }
 
             // reset all transient modifications from this item and its decendants.
@@ -260,10 +266,9 @@
                 log.debug(msg);
                 throw new RepositoryException(msg, e);
             }
+            // now refresh to persistent state as present on the server
+            state.refresh();
         }
-
-        // now refresh to persistent state on server
-        state.refresh();
     }
 
     /**
@@ -400,17 +405,14 @@
         // check session status
         session.checkIsAlive();
         // check status of this item for read operation
-        if (state != null) {
-            if (state.getStatus() == Status.INVALIDATED) {
-                // refresh to get current status from persistent storage
-                state.refresh();
-            }
-            // now check if valid
-            if (state.isValid()) {
-                return;
-            }
+        if (state.getStatus() == Status.INVALIDATED) {
+            // refresh to get current status from persistent storage
+            state.refresh();
+        }
+        // now check if valid
+        if (!state.isValid()) {
+            throw new InvalidItemStateException("Item '" + this + "' doesn't exist anymore");
         }
-        throw new InvalidItemStateException("Item '" + this + "' doesn't exist anymore");
     }
 
     /**

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=474319&r1=474318&r2=474319
==============================================================================
--- 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
Mon Nov 13 05:56:21 2006
@@ -124,11 +124,11 @@
 
     /**
      * Call this method when this change log has been sucessfully persisted.
-     * This implementation will call {@link ItemState#refresh(ChangeLog)
+     * This implementation will call {@link ItemState#persisted(ChangeLog)
      * ItemState.refresh(this)} on the target item of this change log.
      */
     public void persisted() {
-        target.refresh(this);
+        target.persisted(this);
     }
 
     //----------------------< Retrieve information present in the ChangeLog >---

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=474319&r1=474318&r2=474319
==============================================================================
--- 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 Nov 13 05:56:21 2006
@@ -227,8 +227,7 @@
                 builder.addLast(name, index);
             }
         } else {
-            PropertyState propState = (PropertyState) state;
-            // add to path
+            // property-state: add to path
             builder.addLast(name);
         }
     }
@@ -333,12 +332,13 @@
 
     /**
      * Unmodifiable iterator over the listeners present on this item state.
-     * 
+     *
      * @return
      */
     public Iterator getListeners() {
         return Collections.unmodifiableCollection(listeners).iterator();
     }
+
     //-----------------------------------------< ItemStateLifeCycleListener >---
     /**
      *
@@ -358,6 +358,8 @@
                         synchronized (this) {
                             reset();
                         }
+                        // temporarily set the state to MODIFIED in order to
+                        // inform listeners.
                         setStatus(Status.MODIFIED);
                     } else if (status == Status.EXISTING_MODIFIED) {
                         setStatus(Status.STALE_MODIFIED);
@@ -417,7 +419,7 @@
     }
 
     /**
-     * @throws IllegalStateException if this state is a 'session' state.
+     * @throws IllegalStateException if this state is a 'workspace' state.
      */
     public void checkIsSessionState() {
         if (isWorkspaceState) {
@@ -471,7 +473,7 @@
      * @param changeLog
      * @throws IllegalStateException if this state is a 'session' state.
      */
-    abstract void refresh(ChangeLog changeLog) throws IllegalStateException;
+    abstract void persisted(ChangeLog changeLog) throws IllegalStateException;
 
     /**
      * Copy all state information from overlayed state to this state
@@ -504,11 +506,12 @@
     abstract void remove() throws ItemStateException;
 
     /**
-     * Reverts this item state to its initial status and adds itself to the Set
-     * of <code>affectedItemStates</code> if it reverted itself.
+     * Reverts this item state to its initial status (i.e. removing any transient
+     * modifications and adds itself to the Set of <code>affectedItemStates</code>
+     * if it is reverted itself.
      *
      * @param affectedItemStates the set of affected item states that reverted
-     *                           themselfes.
+     * themselfes.
      */
     abstract void revert(Set affectedItemStates);
 

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=474319&r1=474318&r2=474319
==============================================================================
--- 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 Nov 13 05:56:21 2006
@@ -207,6 +207,14 @@
         return getNodeId();
     }
 
+    public void refresh() {
+        // TODO
+    }
+
+    public void invalidate() {
+        // TODO
+    }
+
     //----------------------------------------------------------< NodeState >---
     /**
      * Returns the id of this node state.
@@ -688,9 +696,9 @@
     //----------------------------------------------------< Session - State >---
     /**
      * {@inheritDoc}
-     * @see ItemState#refresh(ChangeLog)
+     * @see ItemState#persisted(ChangeLog)
      */
-    void refresh(ChangeLog changeLog) throws IllegalStateException {
+    void persisted(ChangeLog changeLog) throws IllegalStateException {
 
         // remember parent states that have need to adjust their uuid/mixintypes
         // or that got a new child entry added or existing entries removed.
@@ -938,14 +946,14 @@
     }
 
     /**
-     * Reverts all property and child node states that belong to this
-     * <code>NodeState</code> and finally reverts this <code>NodeState</code>.
+     * Calls {@link #revert(Set) on all child states and add itself to the
+     * set of affected states, if the current status indicates, that this
+     * <code>NodeState</code> has been transiently modified.
      *
      * @inheritDoc
      * @see ItemState#revert(Set)
      */
     void revert(Set affectedItemStates) {
-        // TODO: TOBEFIXED. revert must include an update with the latest state present on
the server
         checkIsSessionState();
 
         // copy to new list, when a property is reverted it may call this node

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?view=diff&rev=474319&r1=474318&r2=474319
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Mon Nov 13 05:56:21 2006
@@ -309,9 +309,9 @@
     //----------------------------------------------------< Session - State >---
     /**
      * {@inheritDoc}
-     * @see ItemState#refresh(ChangeLog)
+     * @see ItemState#persisted(ChangeLog)
      */
-    void refresh(ChangeLog changeLog) throws IllegalStateException {
+    void persisted(ChangeLog changeLog) throws IllegalStateException {
         for (Iterator it = changeLog.modifiedStates(); it.hasNext();) {
             ItemState modState = (ItemState) it.next();
             if (modState == this) {
@@ -360,7 +360,6 @@
      * @see ItemState#revert(Set)
      */
     void revert(Set affectedItemStates) {
-        // TODO: TOBEFIXED. revert must include an update with the latest state present on
the server
         checkIsSessionState();
 
         switch (getStatus()) {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java?view=diff&rev=474319&r1=474318&r2=474319
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
Mon Nov 13 05:56:21 2006
@@ -131,6 +131,16 @@
         return status == EXISTING_MODIFIED || status == EXISTING_REMOVED || status == NEW;
     }
 
+    /**
+     * Returns true, if the status of an item state can be changed from
+     * <code>oldStatus</code> to <code>newStatus</code>, and false
if the
+     * change is illegal or if any of the given status flags is illegal.
+     *
+     * @param oldStatus
+     * @param newStatus
+     * @param isWorkspaceState
+     * @return
+     */
     public static boolean isValidStatusChange(int oldStatus, int newStatus,
                                               boolean isWorkspaceState) {
         if (oldStatus == newStatus) {
@@ -147,24 +157,16 @@
                     break;
                 case MODIFIED:
                     // temporary state when workspace state is updated or refreshed
-                    switch (oldStatus) {
-                        case EXISTING: // refresh of existing item state
-                        case INVALIDATED: // invalidated item state is refreshed
-                            isValid = true;
-                            break;
-                    }
+                    isValid = (oldStatus == EXISTING || oldStatus == INVALIDATED);
                     break;
                 case REMOVED:
-                    switch (oldStatus) {
-                        case EXISTING: // existing workspace state is externally removed
-                        case INVALIDATED: // invalidated item state is refreshed
-                            isValid = true;
-                            break;
-                    }
+                    // existing or invalidated workspace state is externally removed
+                    isValid = (oldStatus == EXISTING || oldStatus == INVALIDATED);
                     break;
                 // default: no other status possible : -> false
             }
         } else {
+            // valid status changes for session-states
             switch (newStatus) {
                 case INVALIDATED:
                     isValid = (oldStatus == EXISTING); // invalidate
@@ -193,7 +195,8 @@
                     isValid = (oldStatus == EXISTING_MODIFIED);
                     break;
                 case REMOVED:
-                    isValid = (oldStatus == NEW || oldStatus == EXISTING || oldStatus ==
EXISTING_REMOVED || oldStatus == INVALIDATED);
+                    isValid = (oldStatus == NEW || oldStatus == INVALIDATED ||
+                               oldStatus == EXISTING || oldStatus == EXISTING_REMOVED );
                     break;
                 case MODIFIED:
                     isValid = (oldStatus == EXISTING);



Mime
View raw message