7 Replies Latest reply on Jul 21, 2010 4:32 PM by kurtstam

    Cloning and ItemExistsException Question

    kurtstam

      Hi guys,

       

      When I clone an item in a workspace to a different destination then its source, then I am not expecting a ItemExistsException, but I am getting:

       

      javax.jcr.ItemExistsException: A node with UUID "65b5f638-a452-4d14-906c-7f88d9303721" already exists at path "/ns001:repository/ns001:package_area/globalArea/assets/testAddRuleItemFromGlobalAreaRuleItem" in workspace ""

       

      when executing: workspace.clone(workspace.getName(), globalAssetItem.getNode().getPath(), path, false);

       

      The value of 'path' is:

       

      /drools:repository/drools:package_area/testAddRuleItemFromGlobalArea1/assets/testAddRuleItemFromGlobalAreaRuleItem

       

      which is different from the srcPath, which is the path mentioned in the exception.

       

      What am I doing wrong here, or is this a bug? I'm using ModeShape 2.0.0.Final.

       

      Thx,

       

      --Kurt

       

      for the complete source code see the 'addAssetImportedFromGlobalArea' test:

      http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/PackageItemTest.java

        • 1. Re: Cloning and ItemExistsException Question
          rhauch

          Hi, Kurt:

          When I clone an item in a workspace to a different destination then its source,

          ...

          when executing: workspace.clone(workspace.getName(), globalAssetItem.getNode().getPath(), path, false);

          The short answer is that you're cloning from one area of a workspace into the other (since you're passing the same workspace name as the first parameter), and although the second and third parameters are different paths, the fourth parameter says that the clone operation should not remove any nodes in the destination workspace with the same identifiers.  If you're getting an ItemAlreadyExistsException, the content you are cloning must have at least one "mix:referenceable" node.

           

          Remember that Workspace.clone() does not assign new identifiers (see [1]).  If you want to copy a subgraph but do want the copy to have newly-generated identifiers, then Workspace.copy() may be a better fit (see [2]).

           

          [1] http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/Workspace.html#clone(java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean)

          [2] http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/Workspace.html#copy(java.lang.String,%20java.lang.String)

          • 2. Re: Cloning and ItemExistsException Question
            kurtstam

            Right that makes sense. One more question though, if I clone an item do the items in it become 'linked'? So if the content in one of the items is updated, does that automatically update the content of the clone?

            • 3. Re: Cloning and ItemExistsException Question
              rhauch

              Right that makes sense. One more question though, if I clone an item do the items in it become 'linked'? So if the content in one of the items is updated, does that automatically update the content of the clone?

               

              No, the clone and it's original are not dynamically linked. Once the clone is made, the cloned content does not automatically change if the original content is changed. For all intents and purposes, Workspace.clone() and Workspace.copy() semantics are almost the same - the primary difference being that clone() reuses the same identifiers while copy always creates new identifiers for the clone.

              • 4. Re: Cloning and ItemExistsException Question
                rhauch

                Actually, when I wrote my replies above I wasn't thinking of the new shareable nodes feature. With JCR 2.0, shareable nodes are created exactly using the Workspace.clone() method exactly as your example used it, so I suspect that Guvnor is using shareable nodes.  Shareable nodes is a feature that is not yet in ModeShape but is scheduled to be implemented before the next release (see MODE-794).

                • 5. Re: Cloning and ItemExistsException Question
                  kurtstam

                  Ah right. I was just going to reply to you about where to find it in the spec b/c jackrabbit and modeshape differ in behavior on this. And I know you told me about the shared nodes before. I'm slowly starting to find my way around..  And btw if I change the clone to a copy, my unit test start failing (both  jackrabbit and modeshape), so I really seem to need that clone in this  case, since the test expects the sharing behavior: getNode().addMixin("mix:shareable");

                   

                  Thx,

                   

                  --Kurt

                  • 6. Re: Cloning and ItemExistsException Question
                    rhauch

                    I'm not surprised. If Guvnor depends on sharable nodes, there's no getting around that. Stay tuned for more progress on MODE-794.

                    • 7. Re: Cloning and ItemExistsException Question
                      kurtstam

                      OK, thus far I have only found code paths going into repository unit tests, not Guvnor code. However I'm working my way through it and I'm not done yet.