jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r966697 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ state/
Date Thu, 22 Jul 2010 14:57:23 GMT
Author: stefan
Date: Thu Jul 22 14:57:22 2010
New Revision: 966697

URL: http://svn.apache.org/viewvc?rev=966697&view=rev
Log:
JCR-2650: don't silently merge session-local transient changes with external changes before
save().

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateMap.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Thu Jul 22 14:57:22 2010
@@ -1086,7 +1086,6 @@ public class ItemManager implements Dump
                  */
                 case ItemState.STATUS_EXISTING_REMOVED:
                 case ItemState.STATUS_EXISTING_MODIFIED:
-                case ItemState.STATUS_STALE_MODIFIED:
                     ItemState persistentState = discarded.getOverlayedState();
                     // the state is a transient wrapper for the underlying
                     // persistent state, therefore restore the persistent state

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemRefreshOperation.java
Thu Jul 22 14:57:22 2010
@@ -57,7 +57,6 @@ public class ItemRefreshOperation implem
         // check status of this item's state
         if (state.isTransient()) {
             switch (state.getStatus()) {
-            case ItemState.STATUS_STALE_MODIFIED:
             case ItemState.STATUS_STALE_DESTROYED:
                 // add this item's state to the list
                 transientStates.add(state);
@@ -87,7 +86,6 @@ public class ItemRefreshOperation implem
             for (ItemState transientState
                     : stateMgr.getDescendantTransientItemStates(state.getId())) {
                 switch (transientState.getStatus()) {
-                case ItemState.STATUS_STALE_MODIFIED:
                 case ItemState.STATUS_STALE_DESTROYED:
                 case ItemState.STATUS_NEW:
                 case ItemState.STATUS_EXISTING_MODIFIED:

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemSaveOperation.java
Thu Jul 22 14:57:22 2010
@@ -290,7 +290,7 @@ class ItemSaveOperation implements Sessi
 
     /**
      * Builds a list of transient (i.e. new or modified) item states that are
-     * within the scope of <code>this.{@link #save()}</code>. The collection
+     * within the scope of <code>this.{@link #perform(SessionContext)}</code>.
The collection
      * returned is ordered depth-first, i.e. the item itself (if transient)
      * comes last.
      *
@@ -316,11 +316,6 @@ class ItemSaveOperation implements Sessi
                         dirty.add(transientState);
                         break;
 
-                    case ItemState.STATUS_STALE_MODIFIED:
-                        throw new InvalidItemStateException(
-                                "Item cannot be saved because it has been "
-                                + "modified externally: " + this);
-
                     case ItemState.STATUS_STALE_DESTROYED:
                         throw new InvalidItemStateException(
                                 "Item cannot be saved because it has been "
@@ -351,11 +346,6 @@ class ItemSaveOperation implements Sessi
                     throw new RepositoryException(
                             "Cannot save a new item: " + this);
 
-                case ItemState.STATUS_STALE_MODIFIED:
-                    throw new InvalidItemStateException(
-                            "Item cannot be saved because it has been"
-                            + " modified externally: " + this);
-
                 case ItemState.STATUS_STALE_DESTROYED:
                     throw new InvalidItemStateException(
                             "Item cannot be saved because it has been"
@@ -380,7 +370,7 @@ class ItemSaveOperation implements Sessi
     /**
      * Builds a list of transient descendant item states in the attic
      * (i.e. those marked as 'removed') that are within the scope of
-     * <code>this.{@link #save()}</code>.
+     * <code>this.{@link #perform(SessionContext)}</code>.
      *
      * @return list of transient item states
      * @throws InvalidItemStateException
@@ -394,13 +384,7 @@ class ItemSaveOperation implements Sessi
             for (ItemState transientState
                     : sism.getDescendantTransientItemStatesInAttic(state.getId())) {
                 // check if stale
-                switch (transientState.getStatus()) {
-                case ItemState.STATUS_STALE_MODIFIED:
-                    throw new InvalidItemStateException(
-                            "Item can't be removed because it has been"
-                            + " modified externally: "
-                            + transientState.getId());
-                case ItemState.STATUS_STALE_DESTROYED:
+                if (transientState.getStatus() == ItemState.STATUS_STALE_DESTROYED) {
                     throw new InvalidItemStateException(
                             "Item can't be removed because it has already"
                             + " been deleted externally: "

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Thu Jul 22 14:57:22 2010
@@ -820,48 +820,44 @@ public class NodeImpl extends ItemImpl i
 
         NodeState transientState = data.getNodeState();
 
-        NodeState persistentState = (NodeState) transientState.getOverlayedState();
-        if (persistentState == null) {
+        NodeState localState = (NodeState) transientState.getOverlayedState();
+        if (localState == null) {
             // this node is 'new'
-            persistentState = stateMgr.createNew(transientState);
+            localState = stateMgr.createNew(transientState);
         }
 
-        synchronized (persistentState) {
-            // check staleness of transient state first
-            if (transientState.isStale()) {
-                String msg =
-                    this + ": the node cannot be saved because it has been"
-                    + " modified externally.";
-                log.debug(msg);
-                throw new InvalidItemStateException(msg);
-            }
+        synchronized (localState) {
             // copy state from transient state:
             // parent id's
-            persistentState.setParentId(transientState.getParentId());
+            localState.setParentId(transientState.getParentId());
             // primary type
-            persistentState.setNodeTypeName(transientState.getNodeTypeName());
+            localState.setNodeTypeName(transientState.getNodeTypeName());
             // mixin types
-            persistentState.setMixinTypeNames(transientState.getMixinTypeNames());
+            localState.setMixinTypeNames(transientState.getMixinTypeNames());
             // child node entries
-            persistentState.setChildNodeEntries(transientState.getChildNodeEntries());
+            localState.setChildNodeEntries(transientState.getChildNodeEntries());
             // property entries
-            persistentState.setPropertyNames(transientState.getPropertyNames());
+            localState.setPropertyNames(transientState.getPropertyNames());
             // shared set
-            persistentState.setSharedSet(transientState.getSharedSet());
+            localState.setSharedSet(transientState.getSharedSet());
+            // modCount
+            if (localState.getModCount() != transientState.getModCount()) {
+                localState.setModCount(transientState.getModCount());
+            }
 
             // make state persistent
-            stateMgr.store(persistentState);
+            stateMgr.store(localState);
         }
 
         // tell state manager to disconnect item state
         stateMgr.disconnectTransientItemState(transientState);
-        // swap transient state with persistent state
-        data.setState(persistentState);
+        // swap transient state with local state
+        data.setState(localState);
         // reset status
         data.setStatus(STATUS_NORMAL);
 
         if (isShareable() && data.getPrimaryParentId() == null) {
-            data.setPrimaryParentId(persistentState.getParentId());
+            data.setPrimaryParentId(localState.getParentId());
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemState.java
Thu Jul 22 14:57:22 2010
@@ -53,10 +53,6 @@ public abstract class ItemState {
      */
     public static final int STATUS_NEW = 4;
     /**
-     * 'existing', i.e. persistent state that has been persistently modified by somebody
else
-     */
-    public static final int STATUS_STALE_MODIFIED = 5;
-    /**
      * 'existing', i.e. persistent state that has been destroyed by somebody else
      */
     public static final int STATUS_STALE_DESTROYED = 6;
@@ -286,13 +282,8 @@ public abstract class ItemState {
      * @return true if this item state has become stale, false otherwise.
      */
     public boolean isStale() {
-        if (isTransient) {
-            return status == STATUS_STALE_MODIFIED
-                    || status == STATUS_STALE_DESTROYED;
-        } else {
-            return overlayedState != null
-                    && modCount != overlayedState.getModCount();
-        }
+        return overlayedState != null
+                && modCount != overlayedState.getModCount();
     }
 
     /**
@@ -324,7 +315,6 @@ public abstract class ItemState {
             case STATUS_EXISTING:
             case STATUS_EXISTING_REMOVED:
             case STATUS_EXISTING_MODIFIED:
-            case STATUS_STALE_MODIFIED:
             case STATUS_STALE_DESTROYED:
             case STATUS_UNDEFINED:
                 status = newStatus;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateMap.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateMap.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateMap.java
Thu Jul 22 14:57:22 2010
@@ -126,9 +126,6 @@ public class ItemStateMap implements Ite
             case ItemState.STATUS_STALE_DESTROYED:
                 ps.print("[stale, destroyed]   ");
                 break;
-            case ItemState.STATUS_STALE_MODIFIED:
-                ps.print("[stale, modified]    ");
-                break;
             case ItemState.STATUS_UNDEFINED:
                 ps.print("[undefined]          ");
                 break;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java?rev=966697&r1=966696&r2=966697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
Thu Jul 22 14:57:22 2010
@@ -401,7 +401,7 @@ public class SessionItemStateManager
     }
 
     /**
-     * Same as <code>{@link #getDescendantTransientItemStates(NodeId)}</code>
+     * Same as <code>{@link #getDescendantTransientItemStates(ItemId)}</code>
      * except that item state instances in the attic are returned.
      *
      * @param id identifier of the common parent of the transient item state
@@ -819,8 +819,8 @@ public class SessionItemStateManager
                         transientState.setModCount(local.getModCount());
                         transientState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
                     } catch (ItemStateException e) {
-                        // something went wrong, mark as stale
-                        transientState.setStatus(ItemState.STATUS_STALE_MODIFIED);
+                        // something went wrong
+                        transientState.setStatus(ItemState.STATUS_UNDEFINED);
                     }
                 }
                 visibleState = transientState;
@@ -838,61 +838,7 @@ public class SessionItemStateManager
      */
     public void stateModified(ItemState modified) {
         ItemState visibleState = modified;
-        if (modified.getContainer() != this) {
-            // local state was modified
-            ItemState transientState = transientStore.get(modified.getId());
-            if (transientState != null) {
-                if (transientState.isNode() && !transientState.isStale()) {
-                    // try to silently merge non-conflicting changes (JCR-584)
-                    NodeStateMerger.MergeContext context =
-                            new NodeStateMerger.MergeContext() {
-                                public boolean isAdded(ItemId id) {
-                                    ItemState is = transientStore.get(id);
-                                    return is != null
-                                            && is.getStatus() == ItemState.STATUS_NEW;
-                                }
-
-                                public boolean isDeleted(ItemId id) {
-                                    return atticStore.contains(id);
-                                }
-
-                                public boolean isModified(ItemId id) {
-                                    ItemState is = transientStore.get(id);
-                                    return is != null
-                                            && is.getStatus() == ItemState.STATUS_EXISTING_MODIFIED;
-                                }
-
-                                public boolean allowsSameNameSiblings(NodeId id) {
-                                    try {
-                                        NodeState ns = (NodeState) getItemState(id);
-                                        NodeState parent = (NodeState) getItemState(ns.getParentId());
-                                        Name name = parent.getChildNodeEntry(id).getName();
-                                        EffectiveNodeType ent = ntReg.getEffectiveNodeType(
-                                                parent.getNodeTypeName(),
-                                                parent.getMixinTypeNames());
-                                        QNodeDefinition def = ent.getApplicableChildNodeDef(name,
ns.getNodeTypeName(), ntReg);
-                                        return def != null && def.allowsSameNameSiblings();
-                                    } catch (Exception e) {
-                                        log.warn("Unable to get node definition", e);
-                                        return false;
-                                    }
-                                }
-                            };
-                    if (NodeStateMerger.merge((NodeState) transientState, context)) {
-                        // merge succeeded
-                        return;
-                    }
-                }
-                transientState.setStatus(ItemState.STATUS_STALE_MODIFIED);
-                visibleState = transientState;
-            }
-            // check attic as well (JCR-1432)
-            transientState = atticStore.get(modified.getId());
-            if (transientState != null) {
-                transientState.setStatus(ItemState.STATUS_STALE_MODIFIED);
-                visibleState = transientState;
-            }
-        }
+        // JCR-2650: ignore external changes, they will be considered/merged on save().
         dispatcher.notifyStateModified(visibleState);
     }
 



Mime
View raw message