5 Replies Latest reply on May 2, 2013 10:29 AM by hchiorean

    Assign custom node ID in modeshape

    m.jawwad

      Hi,

       

           I am curerntly using mode shape on trial basis for our Web Application. My question here is that Is it possible to assign a custom or self generated node id to  a new node?  As in Apache Jackrabbit we have a class named NodeImpl having a method NodeImpl.addNodeWithUuid.

       

            Is it possible to do this in modeshape?

       

           Thanks in advance.

        • 1. Re: Assign custom node ID in modeshape
          hchiorean

          Hi,

           

          No, unfortunately this is not possible atm. Internally, ModeShape uses a NodeKey (https://github.com/ModeShape/modeshape/blob/master/modeshape-jcr/src/main/java/org/modeshape/jcr/cache/NodeKey.java) which has a predefined semantic (more specifically is made up of several "segments"), required by the implementation.

          • 2. Re: Assign custom node ID in modeshape
            m.jawwad

            Hi,

             

                     Thanks a lot for the reply. Ok so for my requirement, is there a way to find out if the file being added has the same content as an already added file? I mean if I have a file a.txt on my drive and it is added to the repository. Then I create a copy of the same file on my disk and change the name to b.txt, Is there a way in modeshape through which I can determine that there is already a file with the same content?

             

                      Thanks again.

            • 3. Re: Assign custom node ID in modeshape
              hchiorean

              In the case of binary content, ModeShape's binary store implementations (which are used to store binary content) use the SHA1 of the content being written. In other words, in the above example, ModeShape would only store the content of the file the first time, while any subsequent changes in the file/node name would not trigger additional content being stored (rather the same sha1 being referred).

               

              Only if the content of the file changed (and hence the SHA1) would additional binary content be stored.

              • 4. Re: Assign custom node ID in modeshape
                m.jawwad

                Right,  Thanks, thats is really very helpful/ Just to clerify, what will happen if the FIles are at different locations like: one at : C:\folder1\a.txt and other at: C:\folder\b.txt and both have same content. What will happen in this scenario?

                • 5. Re: Assign custom node ID in modeshape
                  hchiorean

                  Let's say you have 2 different nodes in the repository which represent the 2 files (using the standard JCR types): fileA/jcr:content/jcr:data and fileB/jcr:content/jcr:data.

                   

                  The binary content from the jcr:data properties(i.e. the bytes[] content of the file) will only be stored once by ModeShape and when reading from the input stream of the above jcr:data properties, the same "content" will be returned. It's as if the binary properties "had a symbolic link" to the data from the binary store.