Hi,

On Jan 16, 2008 10:55 PM, Dan Diephouse <[EMAIL PROTECTED]> wrote:
> Thanks. Follow up question: My data has no unique id or anything associated
> with it. So I'm going to have to generate an id then.

A good way to solve such issues is to think of the content repository
as an advanced file system. How would you name your content if you'd
be storing it as files in a file system instead of nodes in a content
repository?

Even if the node or file name has no real semantics or there is no
clear unique identifier available, I often still try to extract at
least some weakly identifiable information from the content and use
that to generate the node name. Typically I use some normalization to
make the base name a valid JCR name and then add some unique suffix
(perhaps a counter, like you often see done with normal files) if that
name is already taken.

Such names make it much easier for an administrator to manually work
with the content even if your application cares nothing about the
names. For example, if you're storing spreadsheets, can you extract
the title property or previous file name of the spreadsheet and use
that as the basis for the node name?

>  I can do an increment type thing like this:
>
>  public Node getNode(int nodeName, Node parent) {
>    try { return parent.addNode(new Integer(nodeName).toString()) }
>    catch (ItemExistsException e) { return getNode(nodeName+1); }
>  }
>
>  Lets say I have two open transactions where this is occurring at the same
> time. Will Tx#2 see that #1 has added a node named "1" and get an
> ItemExistsException even though I haven't committed Tx#1?

No, they'll end up conflicting. Uncommitted changes are never seen by
other sessions.

> Are there any bundled utilities within jackrabbit that can create unique
> ids across a cluster? Should I just use UUIDs?

There are some related code snippets in the mailing list archives, but
I'd probably use a UUID instead of a counter.

BR,

Jukka Zitting

Reply via email to