You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Gadbury <ga...@googlemail.com> on 2009/09/15 12:03:33 UTC

Re-register Custom Node Types Without Destroying Repository?

Hi all,

If I make a change to my CND file, is there a way to update the registered
node types without deleting and rebuilding the entire repository?  I have
added a new property to a node type defined in my CND file but I have useful
data within the repository that I do not wish to lose.  Usually I drop my
database schemas, remove my repository and workspaces directories from my
repository home directory, and have jackrabbit rebuild and re-register
everything from my repository.xml and customNodeTypeDefinition.cnd files.
-- 
View this message in context: http://www.nabble.com/Re-register-Custom-Node-Types-Without-Destroying-Repository--tp25451318p25451318.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


RE: Re-register Custom Node Types Without Destroying Repository?

Posted by Alfie Kirkpatrick <Al...@ioko.com>.
I also tried the same approach and it's definitely workable. I would
like to see this as an option in Jackrabbit so people can switch on this
lax feature at their own risk. Note however that it causes a problem
with restoring versions, because Jackrabbit attempts to commit the
restored node which won't have new required properties or might contain
deleted properties/nodes that are no longer valid. You don't get an
opportunity to migrate the node before the commit.

Regards, Alfie.

-----Original Message-----
From: Charles Brooking [mailto:public+jackrabbit@charlie.brooking.id.au]

Sent: 15 September 2009 14:37
To: users@jackrabbit.apache.org
Subject: Re: Re-register Custom Node Types Without Destroying
Repository?

Gadbury wrote:
>  If I make a change to my CND file, is there a way to update the
>  registered node types without deleting and rebuilding the entire
>  repository?  I have added a new property to a node type defined in my
>  CND file but I have useful data within the repository that I do not
>  wish to lose.  Usually I drop my database schemas, remove my
>  repository and workspaces directories from my repository home
>  directory, and have jackrabbit rebuild and re-register everything
>  from my repository.xml and customNodeTypeDefinition.cnd files.

 From http://markmail.org/message/d7iujo5nuxfcnrrr:

NodeTypeManagerImpl manager = (NodeTypeManagerImpl)
    session.getWorkspace().getNodeTypeManager();
NodeType[] nodeTypes = manager.registerNodeTypes(
    in, // input stream for new CND file
    NodeTypeManagerImpl.TEXT_X_JCR_CND,
    true // reregister existing node types
);

But unless you make very simple changes, like adding an optional 
property type, you'll also need to write "migration" code. For example, 
to add a mandatory property type, first add it as optional then create 
properties in nodes having the relevant node type before replacing the 
property type with its mandatory form. Similarly, to remove a mandatory 
node/property type you have to first make it optional then delete data 
then remove the node/property type.

You will also need to apply the patch below. Support for migrating node 
types is currently limited in Jackrabbit to "trivial" changes. If you 
apply this patch and reregister node types you risk losing data 
integrity so take backups and write migrations carefully. Hopefully 
there'll be support for Rails-like migrations in the future; this is 
something I may attempt but haven't had the time yet.

Later
Charlie

Index: 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTy
peRegistry.java
===================================================================
--- 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTy
peRegistry.java    
(revision 783800)
+++ 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTy
peRegistry.java    
(working copy)
@@ -402,7 +402,7 @@
             // the definition has not been modified, there's nothing to

do here...
             return getEffectiveNodeType(name);
         }
-        if (diff.isTrivial()) {
+        //if (diff.isTrivial()) {
             /**
              * the change is trivial and has no effect on current
content
              * (e.g. that would be the case when non-mandatory 
properties had
@@ -429,15 +429,15 @@
             // notify listeners
             notifyReRegistered(name);
             return entNew;
-        }
+        //}
 
-        String message =
-            "The following nodetype change contains non-trivial
changes."
-            + "Up until now only trivial changes are supported."
-            + " (see javadoc for "
-            + NodeTypeDefDiff.class.getName()
-            + "):\n" + diff.toString();
-        throw new RepositoryException(message);
+        //String message =
+        //    "The following nodetype change contains non-trivial
changes."
+        //    + "Up until now only trivial changes are supported."
+        //    + " (see javadoc for "
+        //    + NodeTypeDefDiff.class.getName()
+        //    + "):\n" + diff.toString();
+        //throw new RepositoryException(message);
 
         // TODO Implement checkForConflictingContent()
         // make sure existing content would not conflict



Re: Re-register Custom Node Types Without Destroying Repository?

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Sep 15, 2009 at 15:36, Charles Brooking
<pu...@charlie.brooking.id.au> wrote:
> Hopefully there'll be support for Rails-like migrations in the future; this is something
> I may attempt but haven't had the time yet.

One very-JCR-like trick is to always use nt:unstructured as base for
all your node types. That way you cannot put constraints on your
nodes, ie. restrict applications/users to only set one of the
pre-defined nodes, but it makes changing nodetypes much easier. Also
note that JCR 2.0 will allow for changing the primary node type of a
node.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Re-register Custom Node Types Without Destroying Repository?

Posted by Charles Brooking <pu...@charlie.brooking.id.au>.
Gadbury wrote:
>  If I make a change to my CND file, is there a way to update the
>  registered node types without deleting and rebuilding the entire
>  repository?  I have added a new property to a node type defined in my
>  CND file but I have useful data within the repository that I do not
>  wish to lose.  Usually I drop my database schemas, remove my
>  repository and workspaces directories from my repository home
>  directory, and have jackrabbit rebuild and re-register everything
>  from my repository.xml and customNodeTypeDefinition.cnd files.

 From http://markmail.org/message/d7iujo5nuxfcnrrr:

NodeTypeManagerImpl manager = (NodeTypeManagerImpl)
    session.getWorkspace().getNodeTypeManager();
NodeType[] nodeTypes = manager.registerNodeTypes(
    in, // input stream for new CND file
    NodeTypeManagerImpl.TEXT_X_JCR_CND,
    true // reregister existing node types
);

But unless you make very simple changes, like adding an optional 
property type, you'll also need to write "migration" code. For example, 
to add a mandatory property type, first add it as optional then create 
properties in nodes having the relevant node type before replacing the 
property type with its mandatory form. Similarly, to remove a mandatory 
node/property type you have to first make it optional then delete data 
then remove the node/property type.

You will also need to apply the patch below. Support for migrating node 
types is currently limited in Jackrabbit to "trivial" changes. If you 
apply this patch and reregister node types you risk losing data 
integrity so take backups and write migrations carefully. Hopefully 
there'll be support for Rails-like migrations in the future; this is 
something I may attempt but haven't had the time yet.

Later
Charlie

Index: 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
===================================================================
--- 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java    
(revision 783800)
+++ 
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java    
(working copy)
@@ -402,7 +402,7 @@
             // the definition has not been modified, there's nothing to 
do here...
             return getEffectiveNodeType(name);
         }
-        if (diff.isTrivial()) {
+        //if (diff.isTrivial()) {
             /**
              * the change is trivial and has no effect on current content
              * (e.g. that would be the case when non-mandatory 
properties had
@@ -429,15 +429,15 @@
             // notify listeners
             notifyReRegistered(name);
             return entNew;
-        }
+        //}
 
-        String message =
-            "The following nodetype change contains non-trivial changes."
-            + "Up until now only trivial changes are supported."
-            + " (see javadoc for "
-            + NodeTypeDefDiff.class.getName()
-            + "):\n" + diff.toString();
-        throw new RepositoryException(message);
+        //String message =
+        //    "The following nodetype change contains non-trivial changes."
+        //    + "Up until now only trivial changes are supported."
+        //    + " (see javadoc for "
+        //    + NodeTypeDefDiff.class.getName()
+        //    + "):\n" + diff.toString();
+        //throw new RepositoryException(message);
 
         // TODO Implement checkForConflictingContent()
         // make sure existing content would not conflict


Re: Re-register Custom Node Types Without Destroying Repository?

Posted by Gadbury <ga...@googlemail.com>.
Many thanks for your replies.  There is a lot to consider and read :)

It makes me wonder whether node constraints are a good idea...!


Gadbury wrote:
> 
> Hi all,
> 
> If I make a change to my CND file, is there a way to update the registered
> node types without deleting and rebuilding the entire repository?  I have
> added a new property to a node type defined in my CND file but I have
> useful data within the repository that I do not wish to lose.  Usually I
> drop my database schemas, remove my repository and workspaces directories
> from my repository home directory, and have jackrabbit rebuild and
> re-register everything from my repository.xml and
> customNodeTypeDefinition.cnd files.
> 

-- 
View this message in context: http://www.nabble.com/Re-register-Custom-Node-Types-Without-Destroying-Repository--tp25451318p25456835.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Re-register Custom Node Types Without Destroying Repository?

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

You can find answers in the following threads:
http://markmail.org/message/pyyj4pqew6f7peog
http://markmail.org/message/4ui7en5d6myygngm

--
Sébastien Launay

Le 15/09/2009 12:03, Gadbury a écrit :
> Hi all,
>
> If I make a change to my CND file, is there a way to update the registered
> node types without deleting and rebuilding the entire repository?  I have
> added a new property to a node type defined in my CND file but I have useful
> data within the repository that I do not wish to lose.  Usually I drop my
> database schemas, remove my repository and workspaces directories from my
> repository home directory, and have jackrabbit rebuild and re-register
> everything from my repository.xml and customNodeTypeDefinition.cnd files.
>