jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r405417 - in /jackrabbit/trunk/jackrabbit/src: main/java/org/apache/jackrabbit/core/NodeImpl.java main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
Date Tue, 09 May 2006 12:54:10 GMT
Author: tripod
Date: Tue May  9 05:54:08 2006
New Revision: 405417

URL: http://svn.apache.org/viewcvs?rev=405417&view=rev
Log:
JCR_423 Node.restore() fails for existing non-versioned OPV=Version child nodes

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=405417&r1=405416&r2=405417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Tue
May  9 05:54:08 2006
@@ -3779,13 +3779,17 @@
             }
         }
 
-        // first delete all non frozen version histories (i.e. all OPV=Copy)
+        // first delete some of the version histories
         NodeIterator iter = getNodes();
         while (iter.hasNext()) {
             NodeImpl n = (NodeImpl) iter.nextNode();
-            if (!freeze.hasFrozenHistory(n.internalGetUUID())) {
-                if (n.getDefinition().getOnParentVersion() == OnParentVersionAction.COPY)
{
-                    // only remove OPV=Copy nodes
+            if (n.getDefinition().getOnParentVersion() == OnParentVersionAction.COPY) {
+                // only remove OPV=Copy nodes
+                n.internalRemove(true);
+            } else if (n.getDefinition().getOnParentVersion() == OnParentVersionAction.VERSION)
{
+                // only remove, if node to be restored does not contain child
+                UUID vhUUID = new UUID(n.getProperty(QName.JCR_VERSIONHISTORY).getString());
+                if (!freeze.hasFrozenHistory(vhUUID)) {
                     n.internalRemove(true);
                 }
             }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java?rev=405417&r1=405416&r2=405417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
Tue May  9 05:54:08 2006
@@ -70,6 +70,11 @@
     private PropertyState[] frozenProperties;
 
     /**
+     * the frozen child nodes
+     */
+    private InternalFreeze[] frozenNodes = null;
+
+    /**
      * the frozen uuid of the original node
      */
     private UUID frozenUUID = null;
@@ -160,21 +165,25 @@
     /**
      * {@inheritDoc}
      */
-    public InternalFreeze[] getFrozenChildNodes() throws VersionException {
-        try {
-            // maybe add iterator?
-            List entries = node.getState().getChildNodeEntries();
-            InternalFreeze[] freezes = new InternalFreeze[entries.size()];
-            Iterator iter = entries.iterator();
-            int i = 0;
-            while (iter.hasNext()) {
-                NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) iter.next();
-                freezes[i++] = (InternalFreeze) vMgr.getItem(entry.getId());
+    public synchronized InternalFreeze[] getFrozenChildNodes()
+            throws VersionException {
+        if (frozenNodes == null) {
+            try {
+                // maybe add iterator?
+                List entries = node.getState().getChildNodeEntries();
+                frozenNodes = new InternalFreeze[entries.size()];
+                Iterator iter = entries.iterator();
+                int i = 0;
+                while (iter.hasNext()) {
+                    NodeState.ChildNodeEntry entry =
+                            (NodeState.ChildNodeEntry) iter.next();
+                    frozenNodes[i++] = (InternalFreeze) vMgr.getItem(entry.getId());
+                }
+            } catch (RepositoryException e) {
+                throw new VersionException("Unable to retrieve frozen child nodes", e);
             }
-            return freezes;
-        } catch (RepositoryException e) {
-            throw new VersionException("Unable to retrieve frozen child nodes", e);
         }
+        return frozenNodes;
     }
 
     /**
@@ -183,9 +192,13 @@
     public boolean hasFrozenHistory(UUID uuid) {
         try {
             NodeId id = new NodeId(uuid);
-            NodeState.ChildNodeEntry entry  = node.getState().getChildNodeEntry(id);
-            if (entry != null) {
-                return vMgr.getItem(id) instanceof InternalFrozenVersionHistory;
+            InternalFreeze[] frozen = getFrozenChildNodes();
+            for (int i=0; i<frozen.length; i++) {
+                if (frozen[i] instanceof InternalFrozenVersionHistory &&
+                    ((InternalFrozenVersionHistory) frozen[i])
+                            .getVersionHistoryId().equals(id)) {
+                    return true;
+                }
             }
         } catch (RepositoryException e) {
             // ignore

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java?rev=405417&r1=405416&r2=405417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
Tue May  9 05:54:08 2006
@@ -277,4 +277,24 @@
             // success
         }
     }
+
+    public void testRestorChild1() throws RepositoryException {
+        versionableNode.addNode("child1");
+        versionableNode.save();
+        Version v1 = versionableNode.checkin();
+        versionableNode.checkout();
+        Version v2 = versionableNode.checkin();
+
+        versionableNode.restore(v1, true);
+        assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
+
+        versionableNode.restore(version, true);
+        assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
+
+        try {
+            versionableNode.restore(v2, true);
+        } catch (RepositoryException e) {
+            fail("Node.restore('1.3') must fail.");
+        }
+    }
 }



Mime
View raw message