jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1592567 - in /jackrabbit/oak/branches/1.0: ./ oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/ oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/
Date Mon, 05 May 2014 16:38:16 GMT
Author: jukka
Date: Mon May  5 16:38:16 2014
New Revision: 1592567

URL: http://svn.apache.org/r1592567
Log:
1.0: Merged revisions 1591704, 1591713, 1591715 and 1591723 (OAK-1789)

Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
    jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
    jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk:r1591704,1591713,1591715,1591723

Modified: jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java?rev=1592567&r1=1592566&r2=1592567&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
(original)
+++ jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/JackrabbitNodeState.java
Mon May  5 16:38:16 2014
@@ -18,16 +18,26 @@ package org.apache.jackrabbit.oak.upgrad
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.addAll;
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Lists.newArrayListWithCapacity;
 import static com.google.common.collect.Maps.newHashMap;
 import static com.google.common.collect.Maps.newLinkedHashMap;
+import static com.google.common.collect.Sets.newHashSet;
 import static com.google.common.collect.Sets.newLinkedHashSet;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID;
 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.MIX_REFERENCEABLE;
+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.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER;
 
 import java.io.ByteArrayInputStream;
@@ -97,6 +107,8 @@ class JackrabbitNodeState extends Abstra
 
     private final TypePredicate isOrderable;
 
+    private final TypePredicate isFrozenNode;
+
     /**
      * Source namespace mappings (URI -< prefix).
      */
@@ -116,9 +128,12 @@ class JackrabbitNodeState extends Abstra
         this.loader = parent.loader;
         this.isReferenceable = parent.isReferenceable;
         this.isOrderable = parent.isOrderable;
+        this.isFrozenNode = parent.isFrozenNode;
         this.uriToPrefix = parent.uriToPrefix;
-        this.nodes = createNodes(bundle);
         this.properties = createProperties(bundle);
+        this.nodes = createNodes(bundle);
+        setChildOrder();
+        fixFrozenUuid();
         this.useBinaryReferences = parent.useBinaryReferences;
         logNewNode(this);
     }
@@ -133,11 +148,13 @@ class JackrabbitNodeState extends Abstra
         this.loader = new BundleLoader(source);
         this.isReferenceable = new TypePredicate(root, MIX_REFERENCEABLE);
         this.isOrderable = TypePredicate.isOrderable(root);
+        this.isFrozenNode = new TypePredicate(root, NT_FROZENNODE);
         this.uriToPrefix = uriToPrefix;
         try {
             NodePropBundle bundle = loader.loadBundle(id);
-            this.nodes = createNodes(bundle);
             this.properties = createProperties(bundle);
+            this.nodes = createNodes(bundle);
+            setChildOrder();
         } catch (ItemStateException e) {
             throw new IllegalStateException("Unable to access node " + id, e);
         }
@@ -226,6 +243,13 @@ class JackrabbitNodeState extends Abstra
 
     //-----------------------------------------------------------< private >--
 
+    private void setChildOrder() {
+        if (isOrderable.apply(this)) {
+            properties.put(OAK_CHILD_ORDER, PropertyStates.createProperty(
+                    OAK_CHILD_ORDER, nodes.keySet(), Type.NAMES));
+        }
+    }
+
     private Map<String, NodeId> createNodes(NodePropBundle bundle) {
         Map<String, NodeId> children = newLinkedHashMap();
         for (ChildNodeEntry entry : bundle.getChildNodeEntries()) {
@@ -239,7 +263,7 @@ class JackrabbitNodeState extends Abstra
         return children;
     }
 
-    public Map<String, PropertyState> createProperties(NodePropBundle bundle) {
+    private Map<String, PropertyState> createProperties(NodePropBundle bundle) {
         Map<String, PropertyState> properties = newHashMap();
 
         String primary;
@@ -269,11 +293,6 @@ class JackrabbitNodeState extends Abstra
                     JCR_UUID, bundle.getId().toString()));
         }
 
-        if (isOrderable.apply(primary, mixins)) {
-            properties.put(OAK_CHILD_ORDER, PropertyStates.createProperty(
-                    OAK_CHILD_ORDER, nodes.keySet(), Type.NAMES));
-        }
-
         for (PropertyEntry property : bundle.getPropertyEntries()) {
             String name = createName(property.getName());
             try {
@@ -293,6 +312,36 @@ class JackrabbitNodeState extends Abstra
         return properties;
     }
 
+    private void fixFrozenUuid() {
+        // OAK-1789: Convert the jcr:frozenUuid of a non-referenceable
+        // frozen node from UUID to a path identifier
+        PropertyState frozenUuid = properties.get(JCR_FROZENUUID);
+        if (frozenUuid != null
+                && frozenUuid.getType() == STRING
+                && isFrozenNode.apply(this)) {
+            String frozenPrimary = NT_BASE;
+            Set<String> frozenMixins = newHashSet();
+
+            PropertyState property = properties.get(JCR_FROZENPRIMARYTYPE);
+            if (property != null && property.getType() == NAME) {
+                frozenPrimary = property.getValue(NAME);
+            }
+            property = properties.get(JCR_FROZENMIXINTYPES);
+            if (property != null && property.getType() == NAMES) {
+                addAll(frozenMixins, property.getValue(NAMES));
+            }
+
+            if (!isReferenceable.apply(frozenPrimary, frozenMixins)) {
+                String parentFrozenUuid = parent.getString(JCR_FROZENUUID);
+                if (parentFrozenUuid != null) {
+                    frozenUuid = PropertyStates.createProperty(
+                            JCR_FROZENUUID, parentFrozenUuid + "/" + name);
+                    properties.put(JCR_FROZENUUID, frozenUuid);
+                }
+            }
+        }
+    }
+
     private org.apache.jackrabbit.oak.api.PropertyState createProperty(
             String name, int type, InternalValue value)
             throws RepositoryException, IOException {

Modified: jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java?rev=1592567&r1=1592566&r2=1592567&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
(original)
+++ jackrabbit/oak/branches/1.0/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
Mon May  5 16:38:16 2014
@@ -238,7 +238,8 @@ public class RepositoryUpgrade {
         logger.info(
                 "Copying repository content from {} to Oak", config.getHomeDir());
         try {
-            NodeBuilder builder = target.getRoot().builder();
+            NodeState base = target.getRoot();
+            NodeBuilder builder = base.builder();
 
             String workspace =
                     source.getRepositoryConfig().getDefaultWorkspaceName();
@@ -260,6 +261,11 @@ public class RepositoryUpgrade {
             copyNodeTypes(builder, uriToPrefix.inverse());
             copyPrivileges(builder);
 
+            // Triggers compilation of type information, which we need for
+            // the type predicates used by the bulk  copy operations below.
+            new TypeEditorProvider(false).getRootEditor(
+                    base, builder.getNodeState(), builder, null);
+
             NodeState root = builder.getNodeState();
             copyVersionStore(builder, root, uriToPrefix, idxToPrefix);
             copyWorkspace(builder, root, workspace, uriToPrefix, idxToPrefix);

Modified: jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java?rev=1592567&r1=1592566&r2=1592567&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
(original)
+++ jackrabbit/oak/branches/1.0/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgradeTest.java
Mon May  5 16:38:16 2014
@@ -22,6 +22,12 @@ import static junit.framework.Assert.ass
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENMIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENPRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_FROZENUUID;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE;
+import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -35,6 +41,7 @@ import javax.jcr.Node;
 import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
@@ -43,6 +50,8 @@ import javax.jcr.nodetype.NodeTypeTempla
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
 import javax.jcr.security.Privilege;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
@@ -61,9 +70,7 @@ public class RepositoryUpgradeTest exten
         new Random().nextBytes(BINARY);
     }
 
-    // needs to be static because the content is created during the @BeforeClass phase
-    private static String testNodeIdentifier;
-
+    @SuppressWarnings("unchecked")
     protected void createSourceContent(Repository repository) throws Exception {
         Session session = repository.login(CREDENTIALS);
         try {
@@ -99,16 +106,24 @@ public class RepositoryUpgradeTest exten
 
             nodeTypeManager.registerNodeType(template, false);
 
+            template = nodeTypeManager.createNodeTypeTemplate();
+            template.setName("test:referenceable");
+            template.setDeclaredSuperTypeNames(
+                    new String[] {"nt:unstructured", "mix:referenceable"});
+            nodeTypeManager.registerNodeType(template, false);
+
             Node root = session.getRootNode();
 
             Node referenceable =
                 root.addNode("referenceable", "test:unstructured");
             referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
-            Node referenceable2 =
-                root.addNode("referenceable2", "test:unstructured");
-            referenceable2.addMixin(NodeType.MIX_REFERENCEABLE);
+            Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
+            versionable.addMixin(MIX_VERSIONABLE);
+            Node child = versionable.addNode("child", "test:referenceable");
+            child.addNode("child2", NT_UNSTRUCTURED);
             session.save();
-            testNodeIdentifier = referenceable.getIdentifier();
+
+            session.getWorkspace().getVersionManager().checkin("/versionable");
 
             Node properties = root.addNode("properties", "test:unstructured");
             properties.setProperty("boolean", true);
@@ -125,8 +140,8 @@ public class RepositoryUpgradeTest exten
             properties.setProperty("long", 9876543210L);
             properties.setProperty("reference", referenceable);
             properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable,
true));
-            properties.setProperty("mv_reference", new Value[]{session.getValueFactory().createValue(referenceable2,
false)});
-            properties.setProperty("mv_weak_reference", new Value[]{session.getValueFactory().createValue(referenceable2,
true)});
+            properties.setProperty("mv_reference", new Value[]{session.getValueFactory().createValue(versionable,
false)});
+            properties.setProperty("mv_weak_reference", new Value[]{session.getValueFactory().createValue(versionable,
true)});
             properties.setProperty("string", "test");
             properties.setProperty("multiple", "a,b,c".split(","));
             session.save();
@@ -316,6 +331,10 @@ public class RepositoryUpgradeTest exten
     public void verifyReferencePropertiesContent() throws Exception {
         Session session = createAdminSession();
         try {
+            assertTrue(session.nodeExists("/referenceable"));
+            String testNodeIdentifier =
+                    session.getNode("/referenceable").getIdentifier();
+
             assertTrue(session.nodeExists("/properties"));
             Node properties = session.getNode("/properties");
 
@@ -333,7 +352,7 @@ public class RepositoryUpgradeTest exten
             assertEquals(properties.getPath() + "/reference", refs.nextProperty().getPath());
             assertFalse(refs.hasNext());
 
-            PropertyIterator refs2 = session.getNode("/referenceable2").getReferences();
+            PropertyIterator refs2 = session.getNode("/versionable").getReferences();
             assertTrue(refs2.hasNext());
             assertEquals(properties.getPath() + "/mv_reference", refs2.nextProperty().getPath());
             assertFalse(refs2.hasNext());
@@ -351,7 +370,7 @@ public class RepositoryUpgradeTest exten
             assertTrue(weakRefs.hasNext());
             assertEquals(properties.getPath() + "/weak_reference", weakRefs.nextProperty().getPath());
             assertFalse(weakRefs.hasNext());
-            PropertyIterator weakRefs2 = session.getNode("/referenceable2").getWeakReferences();
+            PropertyIterator weakRefs2 = session.getNode("/versionable").getWeakReferences();
             assertTrue(weakRefs2.hasNext());
             assertEquals(properties.getPath() + "/mv_weak_reference", weakRefs2.nextProperty().getPath());
             assertFalse(weakRefs2.hasNext());
@@ -360,4 +379,60 @@ public class RepositoryUpgradeTest exten
         }
     }
 
+    @Test
+    public void verifyVersionHistory() throws RepositoryException {
+        Session session = createAdminSession();
+        try {
+            assertTrue(session.nodeExists("/versionable"));
+            Node versionable = session.getNode("/versionable");
+            assertTrue(versionable.hasNode("child"));
+            Node child = versionable.getNode("child");
+            assertTrue(child.hasNode("child2"));
+            Node child2 = child.getNode("child2");
+
+            assertFalse(versionable.isCheckedOut());
+            assertTrue(versionable.hasProperty(JCR_UUID));
+            assertFalse(child.isCheckedOut());
+            assertTrue(child.hasProperty(JCR_UUID));
+            assertFalse(child2.isCheckedOut());
+            assertFalse(child2.hasProperty(JCR_UUID));
+
+            VersionManager manager = session.getWorkspace().getVersionManager();
+            Version version = manager.getBaseVersion("/versionable");
+
+            Node frozen = version.getFrozenNode();
+            assertEquals(
+                    versionable.getPrimaryNodeType().getName(),
+                    frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
+            assertEquals(
+                    versionable.getMixinNodeTypes()[0].getName(),
+                    frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
+            assertEquals(
+                    versionable.getIdentifier(),
+                    frozen.getProperty(JCR_FROZENUUID).getString());
+
+            Node frozenChild = frozen.getNode("child");
+            assertEquals(
+                    child.getPrimaryNodeType().getName(),
+                    frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
+            assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
+            assertEquals(
+                    "OAK-1789",
+                    child.getIdentifier(),
+                    frozenChild.getProperty(JCR_FROZENUUID).getString());
+
+            Node frozenChild2 = frozenChild.getNode("child2");
+            assertEquals(
+                    child2.getPrimaryNodeType().getName(),
+                    frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
+            assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
+            assertEquals(
+                    "OAK-1789",
+                    child2.getIdentifier(),
+                    frozenChild2.getProperty(JCR_FROZENUUID).getString());
+        } finally {
+            session.logout();
+        }
+    }
+
 }



Mime
View raw message