jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r409609 - in /jackrabbit/branches/1.0/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 Fri, 26 May 2006 09:31:01 GMT
Author: jukka
Date: Fri May 26 02:31:01 2006
New Revision: 409609

URL: http://svn.apache.org/viewvc?rev=409609&view=rev
Log:
1.0: Merged revisions 398968 and 405417: JCR-423

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

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=409609&r1=409608&r2=409609&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Fri May 26 02:31:01 2006
@@ -3796,14 +3796,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
-                        || n.getDefinition().getOnParentVersion() == OnParentVersionAction.VERSION)
{
-                    // only remove OPV=Copy or OPV=Version 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);
                 }
             }
@@ -3843,18 +3846,18 @@
                 // check if representing versionable already exists somewhere
                 if (itemMgr.itemExists(nodeId)) {
                     NodeImpl n = session.getNodeById(nodeId);
-                    if (n.getParent().isSame(this)) {
-                        // so order at end
-                        // orderBefore(n.getName(), "");
-                    } else if (removeExisting) {
+                    if (removeExisting) {
                         session.move(n.getPath(), getPath() + "/" + n.getName());
+                    } else if (n.getParent().isSame(this)) {
+                        n.internalRemove(true);
                     } else {
                         // since we delete the OPV=Copy children beforehand, all
                         // found nodes must be outside of this tree
                         throw new ItemExistsException("Unable to restore node, item already
exists outside of restored tree: "
                                 + n.safeGetJCRPath());
                     }
-                } else {
+                }
+                if (!itemMgr.itemExists(nodeId)) {
                     // get desired version from version selector
                     AbstractVersion v = (AbstractVersion) vsel.select(history);
                     NodeImpl node = addNode(child.getName(), v.getFrozenNode());

Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java?rev=409609&r1=409608&r2=409609&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/InternalFrozenNodeImpl.java
Fri May 26 02:31:01 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/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java?rev=409609&r1=409608&r2=409609&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
(original)
+++ jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
Fri May 26 02:31:01 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