jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1484947 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
Date Tue, 21 May 2013 20:44:48 GMT
Author: mreutegg
Date: Tue May 21 20:44:48 2013
New Revision: 1484947

URL: http://svn.apache.org/r1484947
Log:
OAK-168: Basic JCR VersionManager support
- Create frozen nodes for referenceable nodes in the versionable subtree.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java?rev=1484947&r1=1484946&r2=1484947&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
Tue May 21 20:44:48 2013
@@ -47,6 +47,7 @@ import static org.apache.jackrabbit.JcrC
 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_FROZENNODE;
 import static org.apache.jackrabbit.JcrConstants.NT_VERSIONEDCHILD;
@@ -116,7 +117,8 @@ class VersionableState {
     static VersionableState fromVersion(@Nonnull NodeBuilder version,
                                         @Nonnull NodeBuilder versionable,
                                         @Nonnull ReadOnlyNodeTypeManager ntMgr) {
-        return new VersionableState(version, versionable, ntMgr).init();
+        VersionableState state = new VersionableState(version, versionable, ntMgr);
+        return state.initFrozen(version.child(JCR_FROZENNODE), versionable);
     }
 
     /**
@@ -136,23 +138,24 @@ class VersionableState {
     /**
      * Creates a frozen node under the version and initializes it with the basic
      * frozen properties (jcr:frozenPrimaryType, jcr:frozenMixinTypes and
-     * jcr:frozenUuid) from the given versionable node.
+     * jcr:frozenUuid) from the given node. The node must be referenceable.
      *
      * @return this versionable state.
      */
-    private VersionableState init() {
+    private VersionableState initFrozen(NodeBuilder frozen,
+                                        NodeBuilder referenceable) {
         // initialize jcr:frozenNode
-        frozenNode.setProperty(JCR_UUID, IdentifierManager.generateUUID(), Type.STRING);
-        frozenNode.setProperty(JCR_PRIMARYTYPE, NT_FROZENNODE, Type.NAME);
+        frozen.setProperty(JCR_UUID, IdentifierManager.generateUUID(), Type.STRING);
+        frozen.setProperty(JCR_PRIMARYTYPE, NT_FROZENNODE, Type.NAME);
         Iterable<String> mixinTypes;
-        if (versionable.hasProperty(JCR_MIXINTYPES)) {
-            mixinTypes = versionable.getNames(JCR_MIXINTYPES);
+        if (referenceable.hasProperty(JCR_MIXINTYPES)) {
+            mixinTypes = referenceable.getNames(JCR_MIXINTYPES);
         } else {
             mixinTypes = Collections.emptyList();
         }
-        frozenNode.setProperty(JCR_FROZENMIXINTYPES, mixinTypes, Type.NAMES);
-        frozenNode.setProperty(JCR_FROZENPRIMARYTYPE, primaryTypeOf(versionable), Type.NAME);
-        frozenNode.setProperty(JCR_FROZENUUID, uuidFromNode(versionable), Type.STRING);
+        frozen.setProperty(JCR_FROZENMIXINTYPES, mixinTypes, Type.NAMES);
+        frozen.setProperty(JCR_FROZENPRIMARYTYPE, primaryTypeOf(referenceable), Type.NAME);
+        frozen.setProperty(JCR_FROZENUUID, uuidFromNode(referenceable), Type.STRING);
         return this;
     }
 
@@ -165,7 +168,7 @@ class VersionableState {
      */
     NodeBuilder create() throws CommitFailedException {
         try {
-            createState(versionable, frozenNode);
+            createFrozen(versionable, frozenNode);
             return frozenNode;
         } catch (RepositoryException e) {
             throw new CommitFailedException(CommitFailedException.VERSION,
@@ -350,9 +353,9 @@ class VersionableState {
         }
     }
 
-    private void createState(NodeBuilder src,
-                             NodeBuilder dest)
+    private void createFrozen(NodeBuilder src, NodeBuilder dest)
             throws CommitFailedException, RepositoryException {
+        initFrozen(dest, src);
         copyProperties(src, dest, new OPVProvider() {
             @Override
             public int getAction(NodeBuilder src,
@@ -377,12 +380,18 @@ class VersionableState {
                 if (ntMgr.isNodeType(new ReadOnlyTree(child.getNodeState()), MIX_VERSIONABLE))
{
                     // create frozen versionable child
                     versionedChild(child, dest.child(name));
+                } else if (isReferenceable(child)) {
+                    createFrozen(child, dest.child(name));
                 } else {
                     // else copy
                     copy(child, dest.child(name));
                 }
             } else if (opv == COPY) {
-                copy(child, dest.child(name));
+                if (isReferenceable(child)) {
+                    createFrozen(child, dest.child(name));
+                } else {
+                    copy(child, dest.child(name));
+                }
             }
         }
     }
@@ -399,7 +408,11 @@ class VersionableState {
         copyProperties(src, dest, OPVForceCopy.INSTANCE, false);
         for (String name : src.getChildNodeNames()) {
             NodeBuilder child = src.getChildNode(name);
-            copy(child, dest.child(name));
+            if (isReferenceable(child)) {
+                createFrozen(child, dest.child(name));
+            } else {
+                copy(child, dest.child(name));
+            }
         }
     }
 
@@ -428,6 +441,16 @@ class VersionableState {
         }
     }
 
+    private boolean isReferenceable(NodeBuilder node)
+            throws RepositoryException {
+        if (!node.hasProperty(JCR_UUID)) {
+            // quick check without looking at type hierarchy
+            return false;
+        }
+        ReadOnlyTree tree = new ReadOnlyTree(node.getNodeState());
+        return ntMgr.isNodeType(tree, MIX_REFERENCEABLE);
+    }
+
     private int getOPV(NodeBuilder parent, NodeBuilder child, String childName)
             throws RepositoryException {
         ReadOnlyTree parentTree = new ReadOnlyTree(parent.getNodeState());

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java?rev=1484947&r1=1484946&r2=1484947&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/version/VersionableTest.java
Tue May 21 20:44:48 2013
@@ -52,6 +52,15 @@ public class VersionableTest extends Abs
         } catch (VersionException e) {
             // expected
         }
+    }
 
+    public void testReferenceableChild() throws RepositoryException {
+        Node node = testRootNode.addNode(nodeName1, ntUnstructured);
+        node.addMixin(mixVersionable);
+        Node child = node.addNode(nodeName2, ntUnstructured);
+        child.addMixin(mixReferenceable);
+        superuser.save();
+        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
+        vMgr.checkin(node.getPath());
     }
 }



Mime
View raw message