jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r944258 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ItemImpl.java NodeImpl.java PropertyImpl.java
Date Fri, 14 May 2010 13:45:58 GMT
Author: jukka
Date: Fri May 14 13:45:58 2010
New Revision: 944258

URL: http://svn.apache.org/viewvc?rev=944258&view=rev
Log:
JCR-2503: inconsistent session and persistent state after ReferentialIntegrityException

Patch by Stephan Huttenhuis

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.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/PropertyImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=944258&r1=944257&r2=944258&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Fri May 14 13:45:58 2010
@@ -690,15 +690,14 @@ public abstract class ItemImpl implement
                         itemState.setStatus(ItemState.STATUS_NEW);
                     }
                 }
-                if (!item.isTransient()) {
-                    // re-apply 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);
-                    }
+                // re-apply transient changes
+                // for persistent nodes 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);
                 }
             } catch (RepositoryException re) {
                 // something went wrong, log exception and carry on

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=944258&r1=944257&r2=944258&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
Fri May 14 13:45:58 2010
@@ -826,15 +826,35 @@ public class NodeImpl extends ItemImpl i
 
     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);
+        NodeState thisState = null;
+
+        if (!isTransient()) {
+            thisState = (NodeState) getOrCreateTransientItemState();
+            if (transientState.getStatus() == ItemState.STATUS_NEW
+                    && thisState.getStatus() != ItemState.STATUS_NEW) {
+                thisState.setStatus(ItemState.STATUS_NEW);
+                stateMgr.disconnectTransientItemState(thisState);
+            }
+            thisState.setParentId(transientState.getParentId());
+            thisState.setNodeTypeName(transientState.getNodeTypeName());
+        } else {
+            // JCR-2503: Re-create transient state in the state manager,
+            // because it was removed
+            synchronized (data) {
+                try {
+                    thisState = stateMgr.createTransientNodeState(
+                            (NodeId) transientState.getId(),
+                            transientState.getNodeTypeName(),
+                            transientState.getParentId(),
+                            NodeState.STATUS_NEW);
+                    data.setState(thisState);
+                } catch (ItemStateException e) {
+                    throw new RepositoryException(e);
+                }
+            }
         }
+
         // re-apply transient changes
-        thisState.setParentId(transientState.getParentId());
-        thisState.setNodeTypeName(transientState.getNodeTypeName());
         thisState.setMixinTypeNames(transientState.getMixinTypeNames());
         thisState.setChildNodeEntries(transientState.getChildNodeEntries());
         thisState.setPropertyNames(transientState.getPropertyNames());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=944258&r1=944257&r2=944258&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri May 14 13:45:58 2010
@@ -154,12 +154,31 @@ public class PropertyImpl extends ItemIm
 
     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);
+        PropertyState thisState = null;
+
+        if (!isTransient()) {
+            thisState = (PropertyState) getOrCreateTransientItemState();
+            if (transientState.getStatus() == ItemState.STATUS_NEW
+                    && thisState.getStatus() != ItemState.STATUS_NEW) {
+                thisState.setStatus(ItemState.STATUS_NEW);
+                stateMgr.disconnectTransientItemState(thisState);
+            }
+        } else {
+            // JCR-2503: Re-create transient state in the state manager,
+            // because it was removed
+            synchronized (data) {
+                try {
+                    thisState = stateMgr.createTransientPropertyState(
+                            transientState.getParentId(),
+                            transientState.getName(),
+                            PropertyState.STATUS_NEW);
+                    data.setState(thisState);
+                } catch (ItemStateException e) {
+                    throw new RepositoryException(e);
+                }
+            }
         }
+
         // reapply transient changes
         thisState.setType(transientState.getType());
         thisState.setMultiValued(transientState.isMultiValued());



Mime
View raw message