jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r314862 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Date Wed, 12 Oct 2005 12:44:10 GMT
Author: stefan
Date: Wed Oct 12 05:44:07 2005
New Revision: 314862

URL: http://svn.apache.org/viewcvs?rev=314862&view=rev
Log:
JCR-238 workspace.copy causes 2 nodes in the same workspace to have the same version history

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=314862&r1=314861&r2=314862&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Wed Oct 12 05:44:07 2005
@@ -1,6 +1,6 @@
 /*
  * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- *                     as applicable.
+  *                     as applicable.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
 import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.Path;
@@ -51,6 +52,7 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -1592,6 +1594,7 @@
             NodeId id;
             EffectiveNodeType ent = getEffectiveNodeType(srcState);
             boolean referenceable = ent.includesNodeType(QName.MIX_REFERENCEABLE);
+            boolean versionable = ent.includesNodeType(QName.MIX_VERSIONABLE);
             switch (flag) {
                 case COPY:
                     // always create new uuid
@@ -1715,6 +1718,37 @@
 
                 PropertyState newChildState =
                         copyPropertyState(srcChildState, uuid, propName);
+
+                if (versionable && flag == COPY) {
+                    /**
+                     * a versionable node is being copied:
+                     * copied properties declared by mix:versionable need to be
+                     * adjusted accordingly.
+                     */
+                    // jcr:versionHistory
+                    if (!propName.equals(QName.JCR_VERSIONHISTORY)) {
+                        VersionHistory vh = getOrCreateVersionHistory(newState);
+                        newChildState.setValues(new InternalValue[]{InternalValue.create(new
UUID(vh.getUUID()))});
+                    }
+
+                    // jcr:baseVersion
+                    if (!propName.equals(QName.JCR_BASEVERSION)) {
+                        VersionHistory vh = getOrCreateVersionHistory(newState);
+                        newChildState.setValues(new InternalValue[]{InternalValue.create(new
UUID(vh.getRootVersion().getUUID()))});
+                    }
+
+                    // jcr:predecessors
+                    if (!propName.equals(QName.JCR_PREDECESSORS)) {
+                        VersionHistory vh = getOrCreateVersionHistory(newState);
+                        newChildState.setValues(new InternalValue[]{InternalValue.create(new
UUID(vh.getRootVersion().getUUID()))});
+                    }
+
+                    // jcr:isCheckedOut
+                    if (!propName.equals(QName.JCR_ISCHECKEDOUT)) {
+                        newChildState.setValues(new InternalValue[]{InternalValue.create(true)});
+                    }
+                }
+
                 if (newChildState.getType() == PropertyType.REFERENCE) {
                     refTracker.processedReference(newChildState);
                 }
@@ -1775,5 +1809,24 @@
             }
         }
         return newState;
+    }
+
+    /**
+     * Returns the version history of the given node state. A new
+     * version history will be created if doesn't exist yet.
+     *
+     * @param node node state
+     * @return the version history of the target node state
+     * @throws RepositoryException if an error occurs
+     */
+    private VersionHistory getOrCreateVersionHistory(NodeState node)
+            throws RepositoryException {
+        VersionManager vMgr = session.getVersionManager();
+        VersionHistory vh = vMgr.getVersionHistory(session, node);
+        if (vh == null) {
+            // create a new version history
+            vh = vMgr.createVersionHistory(session, node);
+        }
+        return vh;
     }
 }



Mime
View raw message