jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r902110 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/BatchedItemOperations.java test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java test/java/org/apache/jackrabbit/core/TestAll.java
Date Fri, 22 Jan 2010 15:09:08 GMT
Author: dpfister
Date: Fri Jan 22 15:09:07 2010
New Revision: 902110

URL: http://svn.apache.org/viewvc?rev=902110&view=rev
Log:
JCR-2473 Cloning a tree containing shareable nodes into another workspace throws ItemExistsException

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=902110&r1=902109&r2=902110&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Fri Jan 22 15:09:07 2010
@@ -402,7 +402,7 @@
         // 2. check access rights, lock status, node type constraints, etc.
 
         // JCR-2269: store target node state in changelog early as a
-        // precautionary measure in order to isolate it from concurrent 
+        // precautionary measure in order to isolate it from concurrent
         // underlying changes while checking preconditions
         stateMgr.store(destParentState);
         checkAddNode(destParentState, destName.getName(),
@@ -1608,6 +1608,16 @@
             boolean shareable = ent.includesNodeType(NameConstants.MIX_SHAREABLE);
             switch (flag) {
                 case COPY:
+                    /* if this node is shareable and another node in the same shared set
+                     * has been already been copied and given a new uuid, use this one
+                     * (see section 14.5 of the specification)
+                     */
+                    if (shareable && refTracker.getMappedId(srcState.getNodeId())
!= null) {
+                        NodeId newId = refTracker.getMappedId(srcState.getNodeId());
+                        NodeState sharedState = (NodeState) stateMgr.getItemState(newId);
+                        sharedState.addShare(destParentId);
+                        return sharedState;
+                    }
                     // always create new uuid
                     id = new NodeId();
                     if (referenceable) {
@@ -1623,7 +1633,13 @@
                     }
                     // use same uuid as source node
                     id = srcState.getNodeId();
+
                     if (stateMgr.hasItemState(id)) {
+                        if (shareable) {
+                            NodeState sharedState = (NodeState) stateMgr.getItemState(id);
+                            sharedState.addShare(destParentId);
+                            return sharedState;
+                        }
                         // node with this uuid already exists
                         throw new ItemExistsException(safeGetJCRPath(id));
                     }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java?rev=902110&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
Fri Jan 22 15:09:07 2010
@@ -0,0 +1,144 @@
+package org.apache.jackrabbit.core;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+/**
+ * Tests features available with shareable nodes that require multiple
+ * workspaces.
+ */
+public class MultiWorkspaceShareableNodeTest extends AbstractJCRTest {
+
+    /**
+     * The superuser session for the non default workspace
+     */
+    protected Session superuserW2;
+
+    /**
+     * A read-write session for the non default workspace
+     */
+    protected Session rwSessionW2;
+
+    /**
+     * The workspace in the non default session.
+     */
+    Workspace workspaceW2;
+
+    /**
+     * The testroot node in the non default session
+     */
+    Node testRootNodeW2;
+
+    /**
+     * A referenceable node in default workspace
+     */
+    protected Node node1W2;
+
+    /**
+     * A non-referenceable node in default workspace
+     */
+    protected Node node2W2;
+
+    /**
+     * The workspace in the default session.
+     */
+    Workspace workspace;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        workspace = superuser.getWorkspace();
+
+        // init second workspace
+        String otherWspName = getOtherWorkspaceName();
+        superuserW2 = getHelper().getSuperuserSession(otherWspName);
+        rwSessionW2 = getHelper().getReadWriteSession(otherWspName);
+        workspaceW2 = superuserW2.getWorkspace();
+
+        initNodesW2();
+    }
+
+    protected void tearDown() throws Exception {
+        workspace = null;
+
+        // remove all test nodes in second workspace
+        if (superuserW2 != null) {
+            try {
+                if (!isReadOnly) {
+                    // do a 'rollback'
+                    cleanUpTestRoot(superuserW2);
+                }
+            } finally {
+                superuserW2.logout();
+                superuserW2 = null;
+            }
+        }
+        if (rwSessionW2 != null) {
+            rwSessionW2.logout();
+            rwSessionW2 = null;
+        }
+        workspaceW2 = null;
+        testRootNodeW2 = null;
+        node1W2 = null;
+        node2W2 = null;
+        super.tearDown();
+    }
+
+    protected String getOtherWorkspaceName() throws NotExecutableException {
+        if (workspace.getName().equals(workspaceName)) {
+            throw new NotExecutableException("Cannot test copy between workspaces. 'workspaceName'
points to default workspace as well.");
+        }
+        return workspaceName;
+    }
+
+    protected void initNodesW2() throws RepositoryException {
+
+        // testroot
+        if (superuserW2.getRootNode().hasNode(testPath)) {
+            testRootNodeW2 = superuserW2.getRootNode().getNode(testPath);
+            // clean test root
+            for (NodeIterator it = testRootNodeW2.getNodes(); it.hasNext(); ) {
+                it.nextNode().remove();
+            }
+            testRootNodeW2.save();
+        } else {
+            testRootNodeW2 = superuserW2.getRootNode().addNode(testPath, testNodeType);
+            superuserW2.save();
+        }
+    }
+
+    /**
+     * Test cloning a hierarchy of nodes containing a set of shareable nodes.
+     * See also JCR-2473
+     *
+     * @throws Exception if the test fails
+     */
+    public void testClone() throws Exception {
+        Session s1 = testRootNode.getSession();
+        Node a = testRootNode.addNode("a");
+        Node b = a.addNode("b");
+        Node c = a.addNode("c");
+        Node d = b.addNode("d");
+        ensureMixinType(d, mixShareable);
+        s1.save();
+
+        String path = c.getPath() + "/d";
+        workspace.clone(workspace.getName(), d.getPath(), path, false);
+
+        // we now have this hierarchy of nodes:
+        //   a
+        //  / \
+        //  b c
+        //  \ /
+        //   d
+
+        // now clone 'a' to another workspace
+        workspaceW2.clone(workspace.getName(), a.getPath(), a.getPath(), false);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MultiWorkspaceShareableNodeTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?rev=902110&r1=902109&r2=902110&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Fri Jan 22 15:09:07 2010
@@ -36,6 +36,7 @@
 
         suite.addTestSuite(CachingHierarchyManagerTest.class);
         suite.addTestSuite(ShareableNodeTest.class);
+        suite.addTestSuite(MultiWorkspaceShareableNodeTest.class);
         suite.addTestSuite(TransientRepositoryTest.class);
         suite.addTestSuite(XATest.class);
         suite.addTestSuite(RestoreAndCheckoutTest.class);



Mime
View raw message