Search code examples
jackrabbitjcr

Adding same name restriction to Jackrabbit nodes


I want to create a node that has a restriction about same name siblings. I have used a CND file for that.

[cog:example]
- * (undefined) multiple
- * (undefined)
- cog:name (string)
= 'Example Node Name'
mandatory 
- cog:description (string)
= 'Description Goes Here'
autocreated

Then when I tests adding of the nodes:

Node root = session.getRootNode();
Node projects = root.addNode("projects");
Node exampleNode = projects.addNode("example 1","cog:example");
exampleNode.setProperty("cog:name", "example name");
session.save();

Node exampleNode2 = projects.addNode("example 1","cog:example");
exampleNode2.setProperty("cog:name", "example name");
session.save();

dumpToConsole(projects);

Adding the second node did not throw ItemExistsException exception, and dumping the node shows the second node (example 1[2]). Can you please tell me how to make a restriction so that same name nodes are not allowed?


Solution

  • You set same name sibling restrictions via the parent. So you can add eg.

    [nt:parent]
      + * (cog:example)
    

    then set the type of projects

    Node projects = root.addNode("projects", "nt:parent");
    

    Works for me.