You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by kenclark <ke...@snet.net> on 2008/09/19 06:02:04 UTC

Adding a new property


As you will see, I am very new to Jackrabbit and JCR in general.

I am working on storing binary content using nt:file.  I have this working.

I would like to keep track of the user id of the user that saved the binary
content.  It is clear to me that I can't just add a property of whatever
name I like -- I need to (apparently) configure a new node type which
extends from "jcr:content" (or maybe "nt:resource", I can't be sure.)

I have been googling my head off for about an hour, and am totally unable to
figure out how to do this.

So:

1) Is it correct that I need to make a new node type?

2) How do I define it and then register it?  I would like this to be done in
a portable way if possible so that I can hook up to different
implementations of JCR without having to rewrite.

3) I have a web app which will be using this.  I assume the node type only
needs to be registered once, but is that once per server startup or once
ever or what?  What is the best architecture for doing this setup?

4) Why is it so complicated to add a new property -- or have I totally
missed the easy way to do this?

Thanks,
ken
-- 
View this message in context: http://www.nabble.com/Adding-a-new-property-tp19565880p19565880.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Adding a new property

Posted by kenclark <ke...@snet.net>.
Thanks for the links.  I was on the first linked page several times without
ever noticing the link on that page to the notation page (your second link.) 
I see it now.

Thanks again,
ken


Alexander Klimetschek wrote:
> 
> On Fri, Sep 19, 2008 at 1:16 PM, kenclark <ke...@snet.net> wrote:
>> Any suggestions as far as architecting this?  Can this be done in a
>> configuration file?  I am still trying to find a page that shows an
>> example
>> cnd file.
> 
> Linked right from the jackrabbit home page ;-). See here:
> 
> http://jackrabbit.apache.org/node-types.html
> http://jackrabbit.apache.org/node-type-notation.html
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-a-new-property-tp19565880p19601636.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Adding a new property

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Sep 19, 2008 at 1:16 PM, kenclark <ke...@snet.net> wrote:
> Any suggestions as far as architecting this?  Can this be done in a
> configuration file?  I am still trying to find a page that shows an example
> cnd file.

Linked right from the jackrabbit home page ;-). See here:

http://jackrabbit.apache.org/node-types.html
http://jackrabbit.apache.org/node-type-notation.html

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Adding a new property

Posted by kenclark <ke...@snet.net>.

Thanks for the reply.  As far as I can tell, there are no standard mixin
node types that would fit the bill, so I will need to build one (creating a
mixin node type seems like a good solution).  (Or can I add in a primary
type like nt:unstructured as a mixin type?)

Is there a link that has good step by step instructions as to how to do
this?

Can I make a new node type in the "mix" namespace (such as "mix:authored"),
or do I also need to create a new namespace?

Any suggestions as far as architecting this?  Can this be done in a
configuration file?  I am still trying to find a page that shows an example
cnd file.

Thanks,
ken



Julian Reschke wrote:
> 
> kenclark wrote:
>> 
>> As you will see, I am very new to Jackrabbit and JCR in general.
>> 
>> I am working on storing binary content using nt:file.  I have this
>> working.
>> 
>> I would like to keep track of the user id of the user that saved the
>> binary
>> content.  It is clear to me that I can't just add a property of whatever
>> name I like -- I need to (apparently) configure a new node type which
>> extends from "jcr:content" (or maybe "nt:resource", I can't be sure.)
>> 
>> I have been googling my head off for about an hour, and am totally unable
>> to
>> figure out how to do this.
>> 
>> So:
>> 
>> 1) Is it correct that I need to make a new node type?
> 
> Only if the node type you have doesn't allow residual properties (in 
> which case you can just go ahead and set new properties). This is 
> probably not the case here, otherwise you'd already be doing it. But it 
> could be the case on other JCR implementations.
> 
> An alternative would be to go hunting for a existing *mixin* type that 
> does allow setting arbitrary properties, and try to add it to given node 
> instance.
> 
>> 2) How do I define it and then register it?  I would like this to be done
>> in
>> a portable way if possible so that I can hook up to different
>> implementations of JCR without having to rewrite.
> 
> Not possible with JCR 1.0, but part of the JCR 2.0 (potentially the most 
> important change!).
> 
>> 3) I have a web app which will be using this.  I assume the node type
>> only
>> needs to be registered once, but is that once per server startup or once
>> ever or what?  What is the best architecture for doing this setup?
> 
> It would need to be done once.
> 
>> 4) Why is it so complicated to add a new property -- or have I totally
>> missed the easy way to do this?
> 
> The JCR spec allows "strict" node types and "flexible" node types (which 
> is good). Jackrabbit implements "nt:file/nt:resource" exactly as 
> specified in the JCR spec, so doesn't make them less strict that they 
> need to be. Not sure why.
> 
> 
> BR, Julian
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-a-new-property-tp19565880p19570513.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Jackrabbit:OCM : Recursive Same Type Objects

Posted by Christophe Lombart <ch...@gmail.com>.
On Mon, Sep 22, 2008 at 11:19, Boni Gopalan (BioImagene) <
Boni.G@bioimagene.com> wrote:

> Hi Christopher:
>
> The recursive beans get persisted without any problems.  So it was a non
> issue.  I need a quick help on persisting an Enum.  Is there a converter
> available?,  Should I have to implement a custom converter?  If so would
> it be an Atomic Converter or a Bean Converter?


Yes I think so.
I think both can be used depending on your enum.
If you have a single atomic value inside the Enum, it should be nice to have
a Atomic converter.
If you have multiple fields inside the Enum, a specific BeanConverter
becomes interesting. eg. :

public enum Planet {
    MERCURY (3.303e+23, 2.4397e6),
    VENUS   (4.869e+24, 6.0518e6),
    EARTH   (5.976e+24, 6.37814e6),
    MARS    (6.421e+23, 3.3972e6),
    JUPITER (1.9e+27,   7.1492e7),
    SATURN  (5.688e+26, 6.0268e7),
    URANUS  (8.686e+25, 2.5559e7),
    NEPTUNE (1.024e+26, 2.4746e7),
    PLUTO   (1.27e+22,  1.137e6);

    private final double mass;   // in kilograms
    private final double radius; // in meters
    Planet(double mass, double radius) {
        this.mass = mass;
        this.radius = radius;
    }
    public double mass()   { return mass; }
    public double radius() { return radius; }

    // universal gravitational constant  (m3 kg-1 s-2)
    public static final double G = 6.67300E-11;

    public double surfaceGravity() {
        return G * mass / (radius * radius);
    }
    public double surfaceWeight(double otherMass) {
        return otherMass * surfaceGravity();

    }




>
>
> On another note : I had a need to update multiple objects based on a
> Query.  Since there were no suitable methods available I extended your
> ObjectContentManagerImpl and implemented an updated method that accepts
> a node iterator and Object as parameters.  Did I reinvent any wheels?
>

Can you give more details ? What kind of update is it ?




>
> Thanks
> Boni
>
> -----Original Message-----
> From: Christophe Lombart [mailto:christophe.lombart@gmail.com]
> Sent: 19 September 2008 14:47
> To: users@jackrabbit.apache.org
> Subject: Re: Jackrabbit:OCM : Recursive Same Type Objects
>
> for a bean, no problem but we have to check this specific case within
> Collection.
> We have to add a unit test and a bug fix if needed.
>
> It is not working, please create a jira issue. I can work on it.
>
> Christophe
>
>
> On Fri, Sep 19, 2008 at 10:19, Boni Gopalan (BioImagene) <
> Boni.G@bioimagene.com> wrote:
>
> > Hi , I have a need to persist objects of the following structure.
> >
> > Class Foo{
> >        String id;
> >        List<Foo> children;
> > }
> >
> > Is it possible to achieve a proper mapping with XML mappings?  Is
> there
> > any recursion stopper that will stop me at runtime??, I see an ominous
> > test config file named : jcrmapping-avoidrecursiveloop in the trunk!!
> >
> > Sorry, I should have rather tried it first before asking: Very tight
> > deadline !!
> >
> > Thanks
> > Boni
> >
>

RE: Jackrabbit:OCM : Recursive Same Type Objects

Posted by "Boni Gopalan (BioImagene)" <Bo...@bioimagene.com>.
Hi Christopher:

The recursive beans get persisted without any problems.  So it was a non
issue.  I need a quick help on persisting an Enum.  Is there a converter
available?,  Should I have to implement a custom converter?  If so would
it be an Atomic Converter or a Bean Converter?

On another note : I had a need to update multiple objects based on a
Query.  Since there were no suitable methods available I extended your
ObjectContentManagerImpl and implemented an updated method that accepts
a node iterator and Object as parameters.  Did I reinvent any wheels?

Thanks
Boni

-----Original Message-----
From: Christophe Lombart [mailto:christophe.lombart@gmail.com] 
Sent: 19 September 2008 14:47
To: users@jackrabbit.apache.org
Subject: Re: Jackrabbit:OCM : Recursive Same Type Objects

for a bean, no problem but we have to check this specific case within
Collection.
We have to add a unit test and a bug fix if needed.

It is not working, please create a jira issue. I can work on it.

Christophe


On Fri, Sep 19, 2008 at 10:19, Boni Gopalan (BioImagene) <
Boni.G@bioimagene.com> wrote:

> Hi , I have a need to persist objects of the following structure.
>
> Class Foo{
>        String id;
>        List<Foo> children;
> }
>
> Is it possible to achieve a proper mapping with XML mappings?  Is
there
> any recursion stopper that will stop me at runtime??, I see an ominous
> test config file named : jcrmapping-avoidrecursiveloop in the trunk!!
>
> Sorry, I should have rather tried it first before asking: Very tight
> deadline !!
>
> Thanks
> Boni
>

Re: Jackrabbit:OCM : Recursive Same Type Objects

Posted by Christophe Lombart <ch...@gmail.com>.
for a bean, no problem but we have to check this specific case within
Collection.
We have to add a unit test and a bug fix if needed.

It is not working, please create a jira issue. I can work on it.

Christophe


On Fri, Sep 19, 2008 at 10:19, Boni Gopalan (BioImagene) <
Boni.G@bioimagene.com> wrote:

> Hi , I have a need to persist objects of the following structure.
>
> Class Foo{
>        String id;
>        List<Foo> children;
> }
>
> Is it possible to achieve a proper mapping with XML mappings?  Is there
> any recursion stopper that will stop me at runtime??, I see an ominous
> test config file named : jcrmapping-avoidrecursiveloop in the trunk!!
>
> Sorry, I should have rather tried it first before asking: Very tight
> deadline !!
>
> Thanks
> Boni
>

Jackrabbit:OCM : Recursive Same Type Objects

Posted by "Boni Gopalan (BioImagene)" <Bo...@bioimagene.com>.
Hi , I have a need to persist objects of the following structure. 

Class Foo{
	String id;
	List<Foo> children;
}

Is it possible to achieve a proper mapping with XML mappings?  Is there
any recursion stopper that will stop me at runtime??, I see an ominous
test config file named : jcrmapping-avoidrecursiveloop in the trunk!!  

Sorry, I should have rather tried it first before asking: Very tight
deadline !!

Thanks
Boni

Re: Adding a new property

Posted by Julian Reschke <ju...@gmx.de>.
kenclark wrote:
> 
> As you will see, I am very new to Jackrabbit and JCR in general.
> 
> I am working on storing binary content using nt:file.  I have this working.
> 
> I would like to keep track of the user id of the user that saved the binary
> content.  It is clear to me that I can't just add a property of whatever
> name I like -- I need to (apparently) configure a new node type which
> extends from "jcr:content" (or maybe "nt:resource", I can't be sure.)
> 
> I have been googling my head off for about an hour, and am totally unable to
> figure out how to do this.
> 
> So:
> 
> 1) Is it correct that I need to make a new node type?

Only if the node type you have doesn't allow residual properties (in 
which case you can just go ahead and set new properties). This is 
probably not the case here, otherwise you'd already be doing it. But it 
could be the case on other JCR implementations.

An alternative would be to go hunting for a existing *mixin* type that 
does allow setting arbitrary properties, and try to add it to given node 
instance.

> 2) How do I define it and then register it?  I would like this to be done in
> a portable way if possible so that I can hook up to different
> implementations of JCR without having to rewrite.

Not possible with JCR 1.0, but part of the JCR 2.0 (potentially the most 
important change!).

> 3) I have a web app which will be using this.  I assume the node type only
> needs to be registered once, but is that once per server startup or once
> ever or what?  What is the best architecture for doing this setup?

It would need to be done once.

> 4) Why is it so complicated to add a new property -- or have I totally
> missed the easy way to do this?

The JCR spec allows "strict" node types and "flexible" node types (which 
is good). Jackrabbit implements "nt:file/nt:resource" exactly as 
specified in the JCR spec, so doesn't make them less strict that they 
need to be. Not sure why.


BR, Julian