jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r209776 - in /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core: ItemImpl.java version/VersionManager.java version/VersionManagerImpl.java xml/WorkspaceImporter.java
Date Fri, 08 Jul 2005 13:53:28 GMT
Author: stefan
Date: Fri Jul  8 06:53:26 2005
New Revision: 209776

URL: http://svn.apache.org/viewcvs?rev=209776&view=rev
Log:
JCR-166: Versioned node importXML fails

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManager.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java?rev=209776&r1=209775&r2=209776&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java Fri
Jul  8 06:53:26 2005
@@ -34,6 +34,7 @@
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
 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.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
@@ -897,12 +898,25 @@
                 NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId());
                 if (node.isNodeType(MIX_VERSIONABLE)) {
                     if (!node.hasProperty(JCR_VERSIONHISTORY)) {
-                        VersionHistory hist = session.getVersionManager().createVersionHistory(session,
(NodeState) itemState);
-                        node.internalSetProperty(JCR_VERSIONHISTORY, InternalValue.create(new
UUID(hist.getUUID())));
-                        node.internalSetProperty(JCR_BASEVERSION, InternalValue.create(new
UUID(hist.getRootVersion().getUUID())));
+                        VersionManager vMgr = session.getVersionManager();
+                        NodeState nodeState = (NodeState) itemState;
+                        /**
+                         * check if there's already a version history for that
+                         * node; this would e.g. be the case if a versionable
+                         * node had been exported, removed and re-imported with
+                         * either IMPORT_UUID_COLLISION_REMOVE_EXISTING or
+                         * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
+                         * otherwise create a new version history
+                         */
+                        VersionHistory vh = vMgr.getVersionHistory(session, nodeState);
+                        if (vh == null) {
+                            vh = vMgr.createVersionHistory(session, nodeState);
+                        }
+                        node.internalSetProperty(JCR_VERSIONHISTORY, InternalValue.create(new
UUID(vh.getUUID())));
+                        node.internalSetProperty(JCR_BASEVERSION, InternalValue.create(new
UUID(vh.getRootVersion().getUUID())));
                         node.internalSetProperty(JCR_ISCHECKEDOUT, InternalValue.create(true));
                         node.internalSetProperty(JCR_PREDECESSORS,
-                                new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))});
+                                new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
                         createdTransientState = true;
                     }
                 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManager.java?rev=209776&r1=209775&r2=209776&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManager.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManager.java
Fri Jul  8 06:53:26 2005
@@ -48,8 +48,25 @@
      * @param node
      * @return
      * @throws RepositoryException
+     * @see #getVersionHistory(Session, NodeState) 
      */
     VersionHistory createVersionHistory(Session session, NodeState node)
+            throws RepositoryException;
+
+    /**
+     * Returns the version history of the specified <code>node</code> or
+     * <code>null</code> if the given node doesn't (yet) have an associated
+     * version history.
+     *
+     * @param session
+     * @param node node whose version history should be returned
+     * @return the version history of the specified <code>node</code> or
+     *         <code>null</code> if the given node doesn't (yet) have an
+     *        associated version history.
+     * @throws RepositoryException if an error occurs
+     * @see #createVersionHistory(Session, NodeState)
+     */
+    VersionHistory getVersionHistory(Session session, NodeState node)
             throws RepositoryException;
 
     /**

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=209776&r1=209775&r2=209776&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Fri Jul  8 06:53:26 2005
@@ -204,6 +204,19 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public VersionHistory getVersionHistory(Session session, NodeState node)
+            throws RepositoryException {
+
+        String vhId = getVersionHistoryId(node);
+        if (vhId == null) {
+            return null;
+        }
+        return (VersionHistoryImpl) session.getNodeByUUID(vhId);
+    }
+
+    /**
      * Creates a new Version History.
      *
      * @param node the node for which the version history is to be initialized
@@ -257,6 +270,35 @@
                 stateMgr.cancel();
             }
         }
+    }
+
+    /**
+     * Returns the id of the version history associated with the given node
+     * or <code>null</code> if that node doesn't have a version history.
+     *
+     * @param node the node whose version history's id is to be returned.
+     * @return the the id of the version history associated with the given node
+     *         or <code>null</code> if that node doesn't have a version history.
+     * @throws RepositoryException if an error occurs
+     */
+    private String getVersionHistoryId(NodeState node)
+            throws RepositoryException {
+
+        // build and traverse path
+        String uuid = node.getUUID();
+        NodeStateEx n = historyRoot;
+        for (int i = 0; i < 3; i++) {
+            QName name = new QName(NS_DEFAULT_URI, uuid.substring(i * 2, i * 2 + 2));
+            if (!n.hasNode(name)) {
+                return null;
+            }
+            n = n.getNode(name, 1);
+        }
+        QName historyNodeName = new QName(NS_DEFAULT_URI, uuid);
+        if (!n.hasNode(historyNodeName)) {
+            return null;
+        }
+        return n.getNode(historyNodeName, 1).getUUID();
     }
 
     /**

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?rev=209776&r1=209775&r2=209776&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Fri Jul  8 06:53:26 2005
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.core.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.core.nodetype.NodeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
@@ -271,7 +272,19 @@
             PropDef def;
             PropertyState prop;
             SessionImpl session = (SessionImpl) wsp.getSession();
-            VersionHistory hist = session.getVersionManager().createVersionHistory(session,
node);
+            VersionManager vMgr = session.getVersionManager();
+            /**
+             * check if there's already a version history for that
+             * node; this would e.g. be the case if a versionable node
+             * had been exported, removed and re-imported with either
+             * IMPORT_UUID_COLLISION_REMOVE_EXISTING or
+             * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
+             * otherwise create a new version history
+             */
+            VersionHistory vh = vMgr.getVersionHistory(session, node);
+            if (vh == null) {
+                vh = vMgr.createVersionHistory(session, node);
+            }
 
             // jcr:versionHistory
             if (!node.hasPropertyName(JCR_VERSIONHISTORY)) {
@@ -279,7 +292,7 @@
                         PropertyType.REFERENCE, false, node);
                 prop = itemOps.createPropertyState(node, JCR_VERSIONHISTORY,
                         PropertyType.REFERENCE, def);
-                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(hist.getUUID()))});
+                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getUUID()))});
             }
 
             // jcr:baseVersion
@@ -288,7 +301,7 @@
                         PropertyType.REFERENCE, false, node);
                 prop = itemOps.createPropertyState(node, JCR_BASEVERSION,
                         PropertyType.REFERENCE, def);
-                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))});
+                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
             }
 
             // jcr:predecessors
@@ -297,7 +310,7 @@
                         PropertyType.REFERENCE, true, node);
                 prop = itemOps.createPropertyState(node, JCR_PREDECESSORS,
                         PropertyType.REFERENCE, def);
-                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(hist.getRootVersion().getUUID()))});
+                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
             }
 
             // jcr:isCheckedOut
@@ -308,7 +321,6 @@
                         PropertyType.BOOLEAN, def);
                 prop.setValues(new InternalValue[]{InternalValue.create(true)});
             }
-
         }
     }
 



Mime
View raw message