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:[email protected]] Sent: 15 September 2009 14:37 To: [email protected] 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
