You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ted Roeloffzen <te...@gmail.com> on 2006/11/15 09:41:35 UTC

Checking existence of the repository

Hi all,

I have made a small web application with JackRabbit and the first time that
i run it I have to register the new nodetypedefinitions and the namespace
URI. Now is my question this: Is there a generic way to check whether or not
your using the repository for the first time?

Ted

Re: Checking existence of the repository

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 11/15/06, Nicolas <nt...@gmail.com> wrote:
> I had a similar issue (on the backup tool), maybe it could be a good
> addition to write a small method to check for the existence of a specific
> NodeType and a Namespace.

See the NamespaceRegistryImpl.safeRegisterNamespace() method that
achieves the full use case for namespaces. It's an internal Jackrabbit
method, so I wouldn't advocate using it from general JCR clients, but
the backup tool can well use it.

> It seems to be a common use case and catching exception for this is not a
> good practice, although not JCR compliant.

Catching the esceptions is JCR compliant.

I don't think it makes much sense to add Jackrabbit specific
extensions for doing this, the extra benefit of having a boolean
return value from something like isNamespaceRegistered() or
nodeTypeExists() instead of catching the respective exception is
rather minor (both achieve the same result, and the use case is quite
rare), so it definitely wouldn't justify adding a direct Jackrabbit
dependency to a client.

You may want to send the suggestion to jsr-283-comments@jcp.org for
consideration in JCR 2.0, but at least I would be intuitively against
adding such utility methods since the need for them is quite limited.

BR,

Jukka Zitting

Re: Checking existence of the repository

Posted by Ted Roeloffzen <te...@gmail.com>.
Sounds like a good idea. It's OK by me.

Ted

2006/11/15, Nicolas <nt...@gmail.com>:
>
> Hi Jukka,
>
> I had a similar issue (on the backup tool), maybe it could be a good
> addition to write a small method to check for the existence of a specific
> NodeType and a Namespace.
>
> It seems to be a common use case and catching exception for this is not a
> good practice, although not JCR compliant.
>
> If you are OK, with it, I will open a JIRA issue so we can discuss it
> further.
>
> BR,
> Nico
>
> On 11/15/06, Jukka Zitting <ju...@gmail.com> wrote:
> >
> > Hi,
> >
> > On 11/15/06, Ted Roeloffzen <te...@gmail.com> wrote:
> > > I have made a small web application with JackRabbit and the first time
> > that
> > > i run it I have to register the new nodetypedefinitions and the
> > namespace
> > > URI. Now is my question this: Is there a generic way to check whether
> or
> > not
> > > your using the repository for the first time?
> >
> > I generally check whether my namespaces or nodetypes are already
> > registered. Something like this:
> >
> >     try {
> >         session.getNamespacePrefix(MY_NAMESPACE);
> >     } catch (NamespaceException e) {
> >         // register the namespace(s)
> >     }
> >
> > or:
> >
> >     try {
> >         session.getWorkspace().getNodeTypeManager()
> >             .getNodeType(MY_NODETYPE);
> >     } catch (NoSuchNodeTypeException e) {
> >         // register the node type(s)
> >     }
> >
> > BR,
> >
> > Jukka Zitting
> >
>
>

Re: Checking existence of the repository

Posted by Nicolas <nt...@gmail.com>.
Hi Jukka,

I had a similar issue (on the backup tool), maybe it could be a good
addition to write a small method to check for the existence of a specific
NodeType and a Namespace.

It seems to be a common use case and catching exception for this is not a
good practice, although not JCR compliant.

If you are OK, with it, I will open a JIRA issue so we can discuss it
further.

BR,
Nico

On 11/15/06, Jukka Zitting <ju...@gmail.com> wrote:
>
> Hi,
>
> On 11/15/06, Ted Roeloffzen <te...@gmail.com> wrote:
> > I have made a small web application with JackRabbit and the first time
> that
> > i run it I have to register the new nodetypedefinitions and the
> namespace
> > URI. Now is my question this: Is there a generic way to check whether or
> not
> > your using the repository for the first time?
>
> I generally check whether my namespaces or nodetypes are already
> registered. Something like this:
>
>     try {
>         session.getNamespacePrefix(MY_NAMESPACE);
>     } catch (NamespaceException e) {
>         // register the namespace(s)
>     }
>
> or:
>
>     try {
>         session.getWorkspace().getNodeTypeManager()
>             .getNodeType(MY_NODETYPE);
>     } catch (NoSuchNodeTypeException e) {
>         // register the node type(s)
>     }
>
> BR,
>
> Jukka Zitting
>

Re: Checking existence of the repository

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 11/15/06, Ted Roeloffzen <te...@gmail.com> wrote:
> I have made a small web application with JackRabbit and the first time that
> i run it I have to register the new nodetypedefinitions and the namespace
> URI. Now is my question this: Is there a generic way to check whether or not
> your using the repository for the first time?

I generally check whether my namespaces or nodetypes are already
registered. Something like this:

    try {
        session.getNamespacePrefix(MY_NAMESPACE);
    } catch (NamespaceException e) {
        // register the namespace(s)
    }

or:

    try {
        session.getWorkspace().getNodeTypeManager()
            .getNodeType(MY_NODETYPE);
    } catch (NoSuchNodeTypeException e) {
        // register the node type(s)
    }

BR,

Jukka Zitting