jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1478420 - /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java
Date Thu, 02 May 2013 15:56:44 GMT
Author: jukka
Date: Thu May  2 15:56:40 2013
New Revision: 1478420

URL: http://svn.apache.org/r1478420
Log:
OAK-806: Content migration from Jackrabbit to Oak

Improve the node type migration code. WIP...

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java?rev=1478420&r1=1478419&r2=1478420&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/core/RepositoryUpgrade.java
Thu May  2 15:56:40 2013
@@ -16,29 +16,62 @@
  */
 package org.apache.jackrabbit.core;
 
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Lists.newArrayListWithCapacity;
+import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.JcrConstants.JCR_AUTOCREATED;
+import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
+import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
+import static org.apache.jackrabbit.JcrConstants.JCR_MANDATORY;
+import static org.apache.jackrabbit.JcrConstants.JCR_MULTIPLE;
+import static org.apache.jackrabbit.JcrConstants.JCR_NAME;
 import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_ONPARENTVERSION;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYITEMNAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_PROPERTYDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.JCR_PROTECTED;
+import static org.apache.jackrabbit.JcrConstants.JCR_REQUIREDTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_SUPERTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.JcrConstants.JCR_VALUECONSTRAINTS;
 import static org.apache.jackrabbit.JcrConstants.JCR_VERSIONSTORAGE;
+import static org.apache.jackrabbit.JcrConstants.NT_NODETYPE;
+import static org.apache.jackrabbit.JcrConstants.NT_PROPERTYDEFINITION;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_AVAILABLE_QUERY_OPERATORS;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_ABSTRACT;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_FULLTEXT_SEARCHABLE;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_QUERYABLE;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_QUERY_ORDERABLE;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.core.RepositoryContext;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.RepositoryImpl.WorkspaceInfo;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -185,11 +218,102 @@ public class RepositoryUpgrade {
         for (Name name : sourceRegistry.getRegisteredNodeTypes()) {
             QNodeTypeDefinition def = sourceRegistry.getNodeTypeDef(name);
             NodeBuilder type = types.child(getOakName(name));
-            type.setProperty(JCR_NODETYPENAME, getOakName(name));
-            // TODO ...
+            copyNodeType(def, type);
         }
     }
 
+    private void copyNodeType(QNodeTypeDefinition def, NodeBuilder builder)
+            throws NamespaceException {
+        builder.setProperty(JCR_PRIMARYTYPE, NT_NODETYPE, NAME);
+
+        // - jcr:nodeTypeName (NAME) protected mandatory
+        builder.setProperty(JCR_NODETYPENAME, getOakName(def.getName()), NAME);
+        // - jcr:supertypes (NAME) protected multiple
+        Name[] supertypes = def.getSupertypes();
+        if (supertypes != null && supertypes.length > 0) {
+            List<String> names = newArrayList();
+            for (Name supertype : supertypes) {
+                names.add(getOakName(supertype));
+            }
+            builder.setProperty(JCR_SUPERTYPES, names, NAMES);
+        }
+        // - jcr:isAbstract (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_IS_ABSTRACT, def.isAbstract());
+        // - jcr:isQueryable (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_IS_QUERYABLE, def.isQueryable());
+        // - jcr:isMixin (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_ISMIXIN, def.isMixin());
+        // - jcr:hasOrderableChildNodes (BOOLEAN) protected mandatory
+        builder.setProperty(
+                JCR_HASORDERABLECHILDNODES, def.hasOrderableChildNodes());
+        // - jcr:primaryItemName (NAME) protected
+        Name primary = def.getPrimaryItemName();
+        if (primary != null) {
+            builder.setProperty(
+                    JCR_PRIMARYITEMNAME, getOakName(primary), NAME);
+        }
+
+        // + jcr:propertyDefinition (nt:propertyDefinition) = nt:propertyDefinition protected
sns
+        QPropertyDefinition[] properties = def.getPropertyDefs();
+        for (int i = 0; i < properties.length; i++) {
+            String name = JCR_PROPERTYDEFINITION + '[' + i + ']';
+            copyPropertyDefinition(properties[i], builder.child(name));
+        }
+
+        // + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition protected
sns
+    }
+
+    private void copyPropertyDefinition(
+            QPropertyDefinition def, NodeBuilder builder)
+            throws NamespaceException {
+        builder.setProperty(JCR_PRIMARYTYPE, NT_PROPERTYDEFINITION, NAME);
+
+        // - jcr:name (NAME) protected
+        builder.setProperty(JCR_NAME, getOakName(def.getName()), NAME);
+        // - jcr:autoCreated (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_AUTOCREATED, def.isAutoCreated());
+        // - jcr:mandatory (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_MANDATORY, def.isMandatory());
+        // - jcr:onParentVersion (STRING) protected mandatory
+        //   < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+        builder.setProperty(
+                JCR_ONPARENTVERSION,
+                OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
+        // - jcr:protected (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_PROTECTED, def.isProtected());
+        // - jcr:requiredType (STRING) protected mandatory
+        //   < 'STRING', 'URI', 'BINARY', 'LONG', 'DOUBLE',
+        //     'DECIMAL', 'BOOLEAN', 'DATE', 'NAME', 'PATH',
+        //     'REFERENCE', 'WEAKREFERENCE', 'UNDEFINED'
+        builder.setProperty(
+                JCR_REQUIREDTYPE,
+                Type.fromTag(def.getRequiredType(), false).toString());
+        // - jcr:valueConstraints (STRING) protected multiple
+        QValueConstraint[] constraints = def.getValueConstraints();
+        if (constraints != null && constraints.length > 0) {
+            List<String> strings = newArrayListWithCapacity(constraints.length);
+            for (QValueConstraint constraint : constraints) {
+                strings.add(constraint.getString());
+            }
+            builder.setProperty(JCR_VALUECONSTRAINTS, strings, STRINGS);
+        }
+        // - jcr:defaultValues (UNDEFINED) protected multiple
+        QValue[] values = def.getDefaultValues();
+        if (values != null) {
+            // TODO
+        }
+        // - jcr:multiple (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_MULTIPLE, def.isMultiple());
+        // - jcr:availableQueryOperators (NAME) protected mandatory multiple
+        List<String> operators = asList(def.getAvailableQueryOperators());
+        builder.setProperty(JCR_AVAILABLE_QUERY_OPERATORS, operators, NAMES);
+        // - jcr:isFullTextSearchable (BOOLEAN) protected mandatory
+        builder.setProperty(
+                JCR_IS_FULLTEXT_SEARCHABLE, def.isFullTextSearchable());
+        // - jcr:isQueryOrderable (BOOLEAN) protected mandatory
+        builder.setProperty(JCR_IS_QUERY_ORDERABLE, def.isQueryOrderable());
+    }
+
     private void copyVersionStore(NodeBuilder root)
             throws RepositoryException, IOException {
         logger.info("Copying version histories");



Mime
View raw message