jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r355510 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ItemImpl.java NodeImpl.java PropertyImpl.java
Date Fri, 09 Dec 2005 14:57:19 GMT
Author: stefan
Date: Fri Dec  9 06:57:15 2005
New Revision: 355510

URL: http://svn.apache.org/viewcvs?rev=355510&view=rev
Log:
JCR-288: inconsistent session state after Item/Session.save() throwing ReferentialIntegrityException

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

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=355510&r1=355509&r2=355510&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Fri Dec  9 06:57:15 2005
@@ -682,6 +682,26 @@
         }
     }
 
+    private void restoreTransientItems(Iterator iter)
+            throws RepositoryException {
+
+        // walk through list of transient states and reapply transient changes
+        while (iter.hasNext()) {
+            ItemState itemState = (ItemState) iter.next();
+            ItemImpl item = itemMgr.getItem(itemState.getId());
+            if (!item.isTransient()) {
+                // reapply transient changes (i.e. undo effect of item.makePersistent())
+                if (item.isNode()) {
+                    NodeImpl node = (NodeImpl) item;
+                    node.restoreTransient((NodeState) itemState);
+                } else {
+                    PropertyImpl prop = (PropertyImpl) item;
+                    prop.restoreTransient((PropertyState) itemState);
+                }
+            }
+        }
+    }
+
     /**
      * Initializes the version history of all new nodes of node type
      * <code>mix:versionable</code>.
@@ -1163,6 +1183,13 @@
                 if (!succeeded) {
                     // update operation failed, cancel all modifications
                     stateMgr.cancel();
+
+                    // JCR-288: if an exception has been thrown during
+                    // update() the transient changes have already been
+                    // applied by persistTransientItems() and we need to
+                    // restore transient state, i.e. undo the effect of
+                    // persistTransientItems()
+                    restoreTransientItems(dirty.iterator());
                 }
             }
 

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=355510&r1=355509&r2=355510&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Fri Dec  9 06:57:15 2005
@@ -936,6 +936,22 @@
         status = STATUS_NORMAL;
     }
 
+    protected void restoreTransient(NodeState transientState)
+            throws RepositoryException {
+        NodeState thisState = (NodeState) getOrCreateTransientItemState();
+        if (transientState.getStatus() == ItemState.STATUS_NEW
+                && thisState.getStatus() != ItemState.STATUS_NEW) {
+            thisState.setStatus(ItemState.STATUS_NEW);
+            stateMgr.disconnectTransientItemState(thisState);
+        }
+        // reapply transient changes
+        thisState.setParentUUID(transientState.getParentUUID());
+        thisState.setMixinTypeNames(transientState.getMixinTypeNames());
+        thisState.setDefinitionId(transientState.getDefinitionId());
+        thisState.setChildNodeEntries(transientState.getChildNodeEntries());
+        thisState.setPropertyNames(transientState.getPropertyNames());
+    }
+
     /**
      * Same as {@link Node#addMixin(String)} except that it takes a
      * <code>QName</code> instead of a <code>String</code>.

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=355510&r1=355509&r2=355510&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri Dec  9 06:57:15 2005
@@ -141,6 +141,21 @@
         status = STATUS_NORMAL;
     }
 
+    protected void restoreTransient(PropertyState transientState)
+            throws RepositoryException {
+        PropertyState thisState = (PropertyState) getOrCreateTransientItemState();
+        if (transientState.getStatus() == ItemState.STATUS_NEW
+                && thisState.getStatus() != ItemState.STATUS_NEW) {
+            thisState.setStatus(ItemState.STATUS_NEW);
+            stateMgr.disconnectTransientItemState(thisState);
+        }
+        // reapply transient changes
+        thisState.setDefinitionId(transientState.getDefinitionId());
+        thisState.setType(transientState.getType());
+        thisState.setMultiValued(transientState.isMultiValued());
+        thisState.setValues(transientState.getValues());
+    }
+
     /**
      * Determines the length of the given value.
      *



Mime
View raw message