jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r264785 - in /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core: ItemImpl.java NodeImpl.java PropertyImpl.java state/ItemState.java
Date Tue, 30 Aug 2005 14:05:02 GMT
Author: stefan
Date: Tue Aug 30 07:04:56 2005
New Revision: 264785

URL: http://svn.apache.org/viewcvs?rev=264785&view=rev
Log:
fixing another concurrency issue that could lead to inconsistent repository content

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java?rev=264785&r1=264784&r2=264785&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java Tue
Aug 30 07:04:56 2005
@@ -170,7 +170,7 @@
 
     protected abstract ItemState getOrCreateTransientItemState() throws RepositoryException;
 
-    protected abstract void makePersistent();
+    protected abstract void makePersistent() throws InvalidItemStateException;
 
     /**
      * Marks this instance as 'removed' and notifies its listeners.
@@ -324,7 +324,7 @@
         ArrayList dirty = new ArrayList();
         ItemState transientState;
 
-        // check status of this item's state
+        // fail-fast test: check status of this item's state
         if (isTransient()) {
             switch (state.getStatus()) {
                 case ItemState.STATUS_EXISTING_MODIFIED:
@@ -376,6 +376,7 @@
             Iterator iter = stateMgr.getDescendantTransientItemStates((NodeId) id);
             while (iter.hasNext()) {
                 transientState = (ItemState) iter.next();
+                // fail-fast test: check status of transient state
                 switch (transientState.getStatus()) {
                     case ItemState.STATUS_NEW:
                     case ItemState.STATUS_EXISTING_MODIFIED:

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java?rev=264785&r1=264784&r2=264785&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/NodeImpl.java Tue
Aug 30 07:04:56 2005
@@ -884,7 +884,7 @@
         return session.getNodeTypeManager().getPropertyDefinition(pd.getId());
     }
 
-    protected void makePersistent() {
+    protected void makePersistent() throws InvalidItemStateException {
         if (!isTransient()) {
             log.debug(safeGetJCRPath() + " (" + id + "): there's no transient state to persist");
             return;
@@ -899,6 +899,13 @@
         }
 
         synchronized (persistentState) {
+            // check staleness of transient state first
+            if (transientState.isStale()) {
+                String msg = safeGetJCRPath()
+                        + ": the node cannot be saved because it has been modified externally.";
+                log.debug(msg);
+                throw new InvalidItemStateException(msg);
+            }
             // copy state from transient state:
             // parent uuid's
             persistentState.setParentUUID(transientState.getParentUUID());

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=264785&r1=264784&r2=264785&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/PropertyImpl.java
Tue Aug 30 07:04:56 2005
@@ -40,6 +40,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.PropertyDefinition;
@@ -98,7 +99,7 @@
         return state;
     }
 
-    protected void makePersistent() {
+    protected void makePersistent() throws InvalidItemStateException {
         if (!isTransient()) {
             log.debug(safeGetJCRPath() + " (" + id + "): there's no transient state to persist");
             return;
@@ -112,6 +113,13 @@
         }
 
         synchronized (persistentState) {
+            // check staleness of transient state first
+            if (transientState.isStale()) {
+                String msg = safeGetJCRPath()
+                        + ": the property cannot be saved because it has been modified externally.";
+                log.debug(msg);
+                throw new InvalidItemStateException(msg);
+            }
             // copy state from transient state
             persistentState.setDefinitionId(transientState.getDefinitionId());
             persistentState.setType(transientState.getType());

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java?rev=264785&r1=264784&r2=264785&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
Tue Aug 30 07:04:56 2005
@@ -196,14 +196,6 @@
     }
 
     /**
-     * Determines whether this item state has become stale.
-     * @return true if this item state has become stale, false otherwise.
-     */
-    boolean isStale() {
-        return overlayedState != null && modCount != overlayedState.getModCount();
-    }
-
-    /**
      * Called by <code>TransientItemStateManager</code> and
      * <code>LocalItemStateManager</code> when this item state has been disposed.
      */
@@ -339,6 +331,20 @@
     public boolean isTransient() {
         return isTransient;
 
+    }
+
+    /**
+     * Determines whether this item state has become stale.
+     * @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();
+        }
     }
 
     /**



Mime
View raw message