jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r806531 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/
Date Fri, 21 Aug 2009 12:44:22 GMT
Author: tripod
Date: Fri Aug 21 12:44:22 2009
New Revision: 806531

URL: http://svn.apache.org/viewvc?rev=806531&view=rev
Log:
JCR-2270 Restoring a deleted version does not work (throws Exception)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/JcrVersionManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java?rev=806531&r1=806530&r2=806531&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
Fri Aug 21 12:44:22 2009
@@ -197,10 +197,19 @@
                 throw new ItemExistsException(msg);
             }
         } else {
-            // create new node below parent
-            NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
-            state.setMixins(fn.getFrozenMixinTypes());
-            restore(state, v, removeExisting);
+            WriteOperation ops = startWriteOperation();
+            try {
+                // create new node below parent
+                NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
+                state.setMixins(fn.getFrozenMixinTypes());
+                internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
+                parent.store();
+                ops.save();
+            } catch (ItemStateException e) {
+                throw new RepositoryException(e);
+            } finally {
+                ops.close();
+            }
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java?rev=806531&r1=806530&r2=806531&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
Fri Aug 21 12:44:22 2009
@@ -30,6 +30,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.NodeIterator;
+import javax.jcr.Session;
 
 /**
  * <code>RestoreTest</code> covers tests related to the restore methods available
@@ -801,6 +802,37 @@
         }
     }
 
+    public void testRestoreRemoved() throws RepositoryException {
+        Node parent = versionableNode.getParent();
+        String oldName = versionableNode.getName();
+        Version v1 = versionableNode.checkin();
+        versionableNode.remove();
+        versionableNode = null;
+        parent.getSession().save();
+
+        parent.restore(v1, oldName, true);
+
+        versionableNode = parent.getNode(oldName);
+
+        String value = versionableNode.getProperty(propertyName1).getString();
+        assertEquals("Restoring a node must set the correct property.", propertyValue2, value);
+    }
+
+    public void testRestoreRemovedJcr2() throws RepositoryException {
+        String path = versionableNode.getPath();
+        Version v1 = versionManager.checkin(path);
+        versionableNode.remove();
+        versionableNode = null;
+        superuser.save();
+
+        versionManager.restore(path, v1, true);
+
+        versionableNode = superuser.getNode(path);
+
+        String value = versionableNode.getProperty(propertyName1).getString();
+        assertEquals("Restoring a node must set the correct property.", propertyValue2, value);
+    }
+
     public void testRestoreChild1Jcr2() throws RepositoryException {
         versionableNode.addNode("child1");
         versionableNode.getSession().save();

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/JcrVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/JcrVersionManager.java?rev=806531&r1=806530&r2=806531&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/JcrVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/JcrVersionManager.java
Fri Aug 21 12:44:22 2009
@@ -16,35 +16,36 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.jackrabbit.jcr2spi.state.NodeState;
-import org.apache.jackrabbit.jcr2spi.version.VersionManager;
-import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
-import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import java.util.Iterator;
 
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionHistory;
-import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
 import javax.jcr.ItemExistsException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.NodeIterator;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.MergeException;
+import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
-import javax.jcr.ItemNotFoundException;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
-import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.lock.LockException;
-import java.util.Iterator;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+
+import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.version.VersionManager;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * <code>VersionManagerImpl</code>...
@@ -171,9 +172,12 @@
      */
     public void restore(String absPath, Version version, boolean removeExisting) throws PathNotFoundException,
ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException,
LockException, InvalidItemStateException, RepositoryException {
         session.checkIsAlive();
-
-        Node n = itemManager.getNode(resolver.getQPath(absPath));
-        n.restore(version, removeExisting);
+        // get parent
+        int idx = absPath.lastIndexOf("/");
+        String parent = idx == 0 ? "/" : absPath.substring(0, idx);
+        String name = absPath.substring(idx + 1);
+        Node n = itemManager.getNode(resolver.getQPath(parent));
+        n.restore(version, name, removeExisting);
     }
 
     /**



Mime
View raw message