jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1593061 - in /jackrabbit/oak/trunk/oak-upgrade/src: main/java/org/apache/jackrabbit/oak/upgrade/ test/java/org/apache/jackrabbit/oak/upgrade/
Date Wed, 07 May 2014 16:31:00 GMT
Author: jukka
Date: Wed May  7 16:31:00 2014
New Revision: 1593061

URL: http://svn.apache.org/r1593061
Log:
OAK-1801: Versionable path of version histories not set during migration

Track versionable paths during the migration.
Plus a bit more detailed logging of progress.

Modified:
    jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
    jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
    jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java

Modified: jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java?rev=1593061&r1=1593060&r2=1593061&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
Wed May  7 16:31:00 2014
@@ -31,10 +31,13 @@ import static org.apache.jackrabbit.JcrC
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.JcrConstants.JCR_VERSIONHISTORY;
 import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
+import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE;
 import static org.apache.jackrabbit.JcrConstants.NT_BASE;
 import static org.apache.jackrabbit.JcrConstants.NT_FROZENNODE;
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
+import static org.apache.jackrabbit.JcrConstants.NT_VERSIONHISTORY;
 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.STRING;
@@ -103,10 +106,16 @@ class JackrabbitNodeState extends Abstra
      */
     private final BundleLoader loader;
 
+    private final String workspaceName;
+
     private final TypePredicate isReferenceable;
 
     private final TypePredicate isOrderable;
 
+    private final TypePredicate isVersionable;
+
+    private final TypePredicate isVersionHistory;
+
     private final TypePredicate isFrozenNode;
 
     /**
@@ -114,42 +123,55 @@ class JackrabbitNodeState extends Abstra
      */
     private final Map<String, String> uriToPrefix;
 
+    private final Map<String, String> versionablePaths;
+
+    private final boolean useBinaryReferences;
+
     private final Map<String, NodeId> nodes;
 
     private final Map<String, PropertyState> properties;
 
-    private final boolean useBinaryReferences;
-
     private JackrabbitNodeState(
             JackrabbitNodeState parent, String name, NodePropBundle bundle) {
         this.parent = parent;
         this.name = name;
         this.path = null;
         this.loader = parent.loader;
+        this.workspaceName = parent.workspaceName;
         this.isReferenceable = parent.isReferenceable;
         this.isOrderable = parent.isOrderable;
+        this.isVersionable = parent.isVersionable;
+        this.isVersionHistory = parent.isVersionHistory;
         this.isFrozenNode = parent.isFrozenNode;
         this.uriToPrefix = parent.uriToPrefix;
+        this.versionablePaths = parent.versionablePaths;
+        this.useBinaryReferences = parent.useBinaryReferences;
         this.properties = createProperties(bundle);
         this.nodes = createNodes(bundle);
         setChildOrder();
+        setVersionablePaths();
         fixFrozenUuid();
-        this.useBinaryReferences = parent.useBinaryReferences;
         logNewNode(this);
     }
 
     JackrabbitNodeState(
             PersistenceManager source, NodeState root,
             Map<String, String> uriToPrefix, NodeId id, String path,
+            String workspaceName, Map<String, String> versionablePaths,
             boolean useBinaryReferences) {
         this.parent = null;
         this.name = null;
         this.path = path;
         this.loader = new BundleLoader(source);
+        this.workspaceName = workspaceName;
         this.isReferenceable = new TypePredicate(root, MIX_REFERENCEABLE);
         this.isOrderable = TypePredicate.isOrderable(root);
+        this.isVersionable = new TypePredicate(root, MIX_VERSIONABLE);
+        this.isVersionHistory = new TypePredicate(root, NT_VERSIONHISTORY);
         this.isFrozenNode = new TypePredicate(root, NT_FROZENNODE);
         this.uriToPrefix = uriToPrefix;
+        this.versionablePaths = versionablePaths;
+        this.useBinaryReferences = useBinaryReferences;
         try {
             NodePropBundle bundle = loader.loadBundle(id);
             this.properties = createProperties(bundle);
@@ -158,7 +180,6 @@ class JackrabbitNodeState extends Abstra
         } catch (ItemStateException e) {
             throw new IllegalStateException("Unable to access node " + id, e);
         }
-        this.useBinaryReferences = useBinaryReferences;
         logNewNode(this);
     }
 
@@ -255,6 +276,21 @@ class JackrabbitNodeState extends Abstra
         }
     }
 
+    private void setVersionablePaths() {
+        if (isVersionable.apply(this)) {
+            String uuid = getString(JCR_VERSIONHISTORY);
+            if (uuid != null) {
+                versionablePaths.put(uuid, getPath());
+            }
+        } else if (isVersionHistory.apply(this)) {
+            String uuid = getString(JCR_UUID);
+            String path = versionablePaths.get(uuid);
+            if (path != null) {
+                properties.put(workspaceName, PropertyStates.createProperty(workspaceName,
path, Type.PATH));
+            }
+        }
+    }
+
     private Map<String, NodeId> createNodes(NodePropBundle bundle) {
         Map<String, NodeId> children = newLinkedHashMap();
         for (ChildNodeEntry entry : bundle.getChildNodeEntries()) {

Modified: jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java?rev=1593061&r1=1593060&r2=1593061&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
(original)
+++ jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
Wed May  7 16:31:00 2014
@@ -246,7 +246,7 @@ public class RepositoryUpgrade {
             NodeState base = target.getRoot();
             NodeBuilder builder = base.builder();
 
-            String workspace =
+            String workspaceName =
                     source.getRepositoryConfig().getDefaultWorkspaceName();
             SecurityProviderImpl security = new SecurityProviderImpl(
                     mapSecurityConfig(config.getSecurityConfig()));
@@ -257,7 +257,7 @@ public class RepositoryUpgrade {
                 initializer.initialize(builder);
             }
             for (SecurityConfiguration sc : security.getConfigurations()) {
-                sc.getWorkspaceInitializer().initialize(builder, workspace);
+                sc.getWorkspaceInitializer().initialize(builder, workspaceName);
             }
 
             HashBiMap<String, String> uriToPrefix = HashBiMap.create();
@@ -271,9 +271,10 @@ public class RepositoryUpgrade {
             new TypeEditorProvider(false).getRootEditor(
                     base, builder.getNodeState(), builder, null);
 
+            Map<String, String> versionablePaths = newHashMap();
             NodeState root = builder.getNodeState();
-            copyVersionStore(builder, root, uriToPrefix, idxToPrefix);
-            copyWorkspace(builder, root, workspace, uriToPrefix, idxToPrefix);
+            copyWorkspace(builder, root, workspaceName, uriToPrefix, idxToPrefix, versionablePaths);
+            copyVersionStore(builder, root, workspaceName, uriToPrefix, idxToPrefix, versionablePaths);
 
             logger.info("Applying default commit hooks");
             // TODO: default hooks?
@@ -292,7 +293,7 @@ public class RepositoryUpgrade {
 
             // security-related hooks
             for (SecurityConfiguration sc : security.getConfigurations()) {
-                hooks.addAll(sc.getCommitHooks(workspace));
+                hooks.addAll(sc.getCommitHooks(workspaceName));
             }
 
             // type validation, reference and indexing hooks
@@ -765,34 +766,40 @@ public class RepositoryUpgrade {
     }
 
     private void copyVersionStore(
-            NodeBuilder builder, NodeState root,
-            Map<String, String> uriToPrefix, Map<Integer, String> idxToPrefix)
+            NodeBuilder builder, NodeState root, String workspaceName,
+            Map<String, String> uriToPrefix, Map<Integer, String> idxToPrefix,
+            Map<String, String> versionablePaths)
             throws RepositoryException, IOException {
-        logger.info("Copying version histories");
-
         PersistenceManager pm =
                 source.getInternalVersionManager().getPersistenceManager();
-
         NodeBuilder system = builder.child(JCR_SYSTEM);
+
+        logger.info("Copying version histories");
         copyState(system, JCR_VERSIONSTORAGE, new JackrabbitNodeState(
                 pm, root, uriToPrefix, VERSION_STORAGE_NODE_ID,
-                "/jcr:system/jcr:versionStorage", copyBinariesByReference));
+                "/jcr:system/jcr:versionStorage",
+                workspaceName, versionablePaths, copyBinariesByReference));
+
+        logger.info("Copying activities");
         copyState(system, "jcr:activities", new JackrabbitNodeState(
                 pm, root, uriToPrefix, ACTIVITIES_NODE_ID,
-                "/jcr:system/jcr:activities", copyBinariesByReference));
+                "/jcr:system/jcr:activities",
+                workspaceName, versionablePaths, copyBinariesByReference));
     }
 
     private String copyWorkspace(
-            NodeBuilder builder, NodeState root, String name,
-            Map<String, String> uriToPrefix, Map<Integer, String> idxToPrefix)
+            NodeBuilder builder, NodeState root, String workspaceName,
+            Map<String, String> uriToPrefix, Map<Integer, String> idxToPrefix,
+            Map<String, String> versionablePaths)
             throws RepositoryException, IOException {
-        logger.info("Copying workspace {}", name);
+        logger.info("Copying workspace {}", workspaceName);
 
         PersistenceManager pm =
-                source.getWorkspaceInfo(name).getPersistenceManager();
+                source.getWorkspaceInfo(workspaceName).getPersistenceManager();
 
         NodeState state = new JackrabbitNodeState(
-                pm, root, uriToPrefix, ROOT_NODE_ID, "/", copyBinariesByReference);
+                pm, root, uriToPrefix, ROOT_NODE_ID, "/",
+                workspaceName, versionablePaths, copyBinariesByReference);
 
         for (PropertyState property : state.getProperties()) {
             builder.setProperty(property);
@@ -800,11 +807,12 @@ public class RepositoryUpgrade {
         for (ChildNodeEntry child : state.getChildNodeEntries()) {
             String childName = child.getName();
             if (!JCR_SYSTEM.equals(childName)) {
+                logger.info("Copying subtree /{}", childName);
                 copyState(builder, childName, child.getNodeState());
             }
         }
 
-        return name;
+        return workspaceName;
     }
 
     private void copyState(NodeBuilder parent, String name, NodeState state) {

Modified: jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java?rev=1593061&r1=1593060&r2=1593061&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
Wed May  7 16:31:00 2014
@@ -38,6 +38,7 @@ import java.util.Random;
 import javax.jcr.Binary;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.Repository;
@@ -51,6 +52,7 @@ import javax.jcr.nodetype.PropertyDefini
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 import javax.jcr.security.Privilege;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
@@ -430,6 +432,10 @@ public class RepositoryUpgradeTest exten
                     "OAK-1789",
                     child2.getIdentifier(),
                     frozenChild2.getProperty(JCR_FROZENUUID).getString());
+
+            VersionHistory history = manager.getVersionHistory("/versionable");
+            Property versionablePath = history.getProperty("default");
+            assertEquals("/versionable", versionablePath.getString());
         } finally {
             session.logout();
         }



Mime
View raw message