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

Reply via email to