Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>JCR's standard approach for child nodes having the same name is to use same-name-siblings, or SNS (see <a href="https://docs.jboss.org/author/display/MODE/Concepts#Concepts-Node,children,names,andpaths" rel="nofollow">here</a> and <a href="http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.1.3.1%20Same-Name%20Siblings" rel="nofollow">here</a>). However, their use is generally discouraged, because as the children of a node are moved, renamed, inserted, and deleted, the same-name-sibling index (and thus the path) for a given child node may change.</p> <p>The JCR 2.0 API also does not define a way to automatically generate unique child node names. (JSR-333, or "JCR 2.1", is nearing final adoption and will add a way to add child nodes with unique names in an automated way. ModeShape plans to support JSR-333 in 4.0; check our <a href="https://issues.jboss.org/browse/MODE" rel="nofollow">roadmap</a> for a schedule.)</p> <p>So, given this, there are two ways to accomplish what you are asking, and both techniques work well in a ModeShape cluster.</p> <h3>Generate your own unique names</h3> <p>The standard <code>nt:folder</code> node type does <strong>not</strong> allow child nodes with same-name-siblings. After all, the <code>nt:folder</code> and <code>nt:file</code> where designed to behave like most file systems, and most of those do not allow files/folders with the same name. Therefore, when you create a node with a primary type of <code>nt:folder</code>, then every child must have a unique name.</p> <p>One very simple way to create a unique name for a child is to use the standard <code>java.util.UUID</code> class. Simply generate a unique ID, and use the string form within the new child's name.</p> <h3>Use Same Name Siblings (SNS)</h3> <p>Alternatively, if you'd rather have the repository manage the uniqueness of the child node names via SNS indexes and can live with the disadvantages of SNS nodes, then simply define a <a href="https://docs.jboss.org/author/display/MODE/Defining+custom+node+types" rel="nofollow">custom node type</a> that makes this possible. For example, here is a node type definition that subtypes <code>nt:hierarchyNode</code> (which is the supertype of both <code>nt:folder</code> and <code>nt:file</code>), and is thus <em>similar</em> but unrelated to <code>nt:folder</code>:</p> <pre><code>[acme:folder] &gt; nt:hierarchyNode + * (nt:hierarchyNode) version sns </code></pre> <p>(Your custom node type is not required to extend <code>nt:hierarchyNode</code>, but doing so makes it possible for <code>nt:folder</code> to contain nodes of type <code>nt:file</code>, <code>nt:folder</code>, <em>and</em> <code>acme:folder</code>.)</p> <p>Once this node type definition is registered, simply create your folder nodes with that custom type as their primary type (or change the primary type later, which ModeShape does support).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload