-
1. Re: Cloning and ItemExistsException Question
rhauch Jul 20, 2010 3:58 PM (in response to kurtstam)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]).
-
2. Re: Cloning and ItemExistsException Question
kurtstam Jul 20, 2010 4:27 PM (in response to 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?
-
3. Re: Cloning and ItemExistsException Question
rhauch Jul 20, 2010 4:36 PM (in response to 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?
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 Jul 20, 2010 6:04 PM (in response to 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 Jul 21, 2010 2:09 PM (in response to rhauch)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 Jul 21, 2010 3:34 PM (in response to kurtstam)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 Jul 21, 2010 4:32 PM (in response to 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.