You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Philipp Bunge <bu...@crimson.ch> on 2009/09/21 15:24:18 UTC

Namespaces for Property and child Node Names

Hi All

I'm curious to know when people prefix property and child node names
with namespaces and when not.

I tend to specify namespaces for all my property definitions. With
child nodes, I tend to omit the namespace only for residual items.
In the case of the blog sample from David's Model for example, I would
therefore have a path as follows:

myblog/foo:posts/what_i_learned_today
myblog/foo:posts/iphone_shipping
myblog/foo:comments/iphone_shipping/i_like_it_too
myblog/foo:comments/iphone_shipping/i_like_it_too/i_hate_it

Where the nodetype definition could look something like this:

[foo:Blog] > nt:base
    + foo:posts (foo:PostList)
    + foo:comments (foo:CommentList)

[foo:PostList] > nt:base
    + * (foo:Post)

[foo:CommentList] > nt:base
    + * (foo:Comment)

...

You get the point.

Anyway, do you have any best practices for this?
When would you use a namespace and when wouldn't you?
Do you ever omit namespaces for properties?

Thanks,
Philipp

Re: Namespaces for Property and child Node Names

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Sep 22, 2009 at 09:07, Philipp Bunge <bu...@crimson.ch> wrote:
>> Using a namespace from the start can also be useful for migration
>> because you can then distinguish a node/property created with
>> old http://foo/1.0 namespace and the new http://foo/2.0 in order to
>> manage them differently.
>
> I was wondering on how to deal with model changes and hadn't even
> thought about using namespaces! Obviously this would be putting
> namespaces to good use. Thanks for pointing this out to me!

I don't think this approach works in practice. You will duplicate all
your data - and then what? If two properties have the same name, it
makes sense to see them as the same. That's why JCR already has a lot
of common node types and properties, like nt:file, jcr:title,
jcr:lastModified etc. (JCR 2.0 defines some helpful standardized
mixins like mix:title). And upgrading nodetypes is also possible, with
JCR 2.0 you will even be able to change the primary node type of an
existing node.

It might be some effort during upgrade, but it's definitely better to
be forced to think about how your content model evolves and how to
handle the migration than to create a "mess" that you will have to
clean up later when it's much harder.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Namespaces for Property and child Node Names

Posted by Philipp Bunge <bu...@crimson.ch>.
Hi Sébastien

Thanks for your reply! You made some interesting points and I will
take them away to think about how I use namespaces. Just wanted to
drop a comment one or two of your items.

> - i do not control the property name (set by the user) and i  do
>  not want collision with existing properties without namespace.

This is interesting. I don't think I've had the situation where I had
users setting properties using arbitrary keys before.
I usually have users only manipulating property values or, if I need a
more flexible structure, a subtree of nodes (where the users set
entire child node names without prefixes).

> - i want to expose parts of the path of a node in a URI on a web
>  server (a prefix: is not very sexy ;)).

Hehe, I agree. :)
Although I like to keep my structured data and my URI mappings (if
any) separated by some domain model. The structure in my repository
and the URIs will certainly be similar as the both reflect the same
model, but I don't necessarily have a 1-to-1 mapping (and can deal
with stripping namespaces, etc.).

> Using a namespace from the start can also be useful for migration
> because you can then distinguish a node/property created with
> old http://foo/1.0 namespace and the new http://foo/2.0 in order to
> manage them differently.

I was wondering on how to deal with model changes and hadn't even
thought about using namespaces! Obviously this would be putting
namespaces to good use. Thanks for pointing this out to me!

Thanks for the responses,
Philipp

Re: Namespaces for Property and child Node Names

Posted by Sébastien Launay <se...@anyware-tech.com>.
Hi,

Le 21/09/2009 15:53, Torgeir Veimo a écrit :
> 2009/9/21 Philipp Bunge <bu...@crimson.ch>:
>   
>>> Why not
>>>
>>>       
>>>> myblog/what_i_learned_today
>>>> myblog/iphone_shipping
>>>> myblog/iphone_shipping/foo:comments/i_like_it_too
>>>> myblog/iphone_shipping/foo:comments/i_like_it_too/i_hate_it
>>>>         
>> Jep, that's fine too. I just copied the example from DavidsModel on
>> the Wiki [1] and prepended the namespace where I would use it.
>>
>> My question was more on the line of when to use a namespace prefix and when not.
>>     
>
> Use prefixes for operational properties, and none for value
> properties. The former properties might eventually end up in a schema.
>   
I generally use a namespace when:
- i want to separate properties/nodes of unrelated content and to
  iterate over a set properties simply by using:
node.getProperties("foo:*");
node.getNodes("foo:*");
- i do not control the property name (set by the user) and i  do
  not want collision with existing properties without namespace.
- i could have a property and a child node with the same (local)
  name.
- i want to optimize a search of a node having a specific property
  (@foo:title will result in better relevant matches than @title).

I generally do not use a namespace when:
- i want to expose parts of the path of a node in a URI on a web
  server (a prefix: is not very sexy ;)).
- i know there will be only one kind of child node below a node.

Using a namespace from the start can also be useful for migration
because you can then distinguish a node/property created with
old http://foo/1.0 namespace and the new http://foo/2.0 in order to
manage them differently.

--
Sébastien Launay

Re: Namespaces for Property and child Node Names

Posted by Torgeir Veimo <to...@netenviron.com>.
2009/9/21 Philipp Bunge <bu...@crimson.ch>:
> My question was more on the line of when to use a namespace prefix and when not.

In general, don't use prefixes for node names, since they will in most
cases map to urls, and you don't want them in urls.

-- 
-Tor

Re: Namespaces for Property and child Node Names

Posted by Torgeir Veimo <to...@netenviron.com>.
2009/9/21 Philipp Bunge <bu...@crimson.ch>:
>> Why not
>>
>>> myblog/what_i_learned_today
>>> myblog/iphone_shipping
>>> myblog/iphone_shipping/foo:comments/i_like_it_too
>>> myblog/iphone_shipping/foo:comments/i_like_it_too/i_hate_it
>
> Jep, that's fine too. I just copied the example from DavidsModel on
> the Wiki [1] and prepended the namespace where I would use it.
>
> My question was more on the line of when to use a namespace prefix and when not.

Use prefixes for operational properties, and none for value
properties. The former properties might eventually end up in a schema.


-- 
-Tor

Re: Namespaces for Property and child Node Names

Posted by Philipp Bunge <bu...@crimson.ch>.
> Why not
>
>> myblog/what_i_learned_today
>> myblog/iphone_shipping
>> myblog/iphone_shipping/foo:comments/i_like_it_too
>> myblog/iphone_shipping/foo:comments/i_like_it_too/i_hate_it

Jep, that's fine too. I just copied the example from DavidsModel on
the Wiki [1] and prepended the namespace where I would use it.

My question was more on the line of when to use a namespace prefix and when not.

P.

[1] http://wiki.apache.org/jackrabbit/DavidsModel

Re: Namespaces for Property and child Node Names

Posted by Torgeir Veimo <to...@netenviron.com>.
2009/9/21 Philipp Bunge <bu...@crimson.ch>:
> In the case of the blog sample from David's Model for example, I would
> therefore have a path as follows:
>
> myblog/foo:posts/what_i_learned_today
> myblog/foo:posts/iphone_shipping
> myblog/foo:comments/iphone_shipping/i_like_it_too
> myblog/foo:comments/iphone_shipping/i_like_it_too/i_hate_it

Why not

> myblog/what_i_learned_today
> myblog/iphone_shipping
> myblog/iphone_shipping/foo:comments/i_like_it_too
> myblog/iphone_shipping/foo:comments/i_like_it_too/i_hate_it

-- 
-Tor