jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r410311 - in /jackrabbit/trunk/jackrabbit/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/test/api/ test/java/org/apache/jackrabbit/test/api/version/
Date Tue, 30 May 2006 16:06:31 GMT
Author: tripod
Date: Tue May 30 09:06:30 2006
New Revision: 410311

URL: http://svn.apache.org/viewvc?rev=410311&view=rev
Log:
JCR-444 Error while restoring OPV=Version childnodes (Restore of root version not allowed)

Added:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
  (with props)
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
  (contents, props changed)
      - copied, changed from r409349, jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/GenericVersionSelector.java
Removed:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/GenericVersionSelector.java
Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java
    jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=410311&r1=410310&r2=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Tue
May 30 09:06:30 2006
@@ -33,12 +33,13 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.core.version.GenericVersionSelector;
+import org.apache.jackrabbit.core.version.LabelVersionSelector;
 import org.apache.jackrabbit.core.version.InternalFreeze;
 import org.apache.jackrabbit.core.version.InternalFrozenNode;
 import org.apache.jackrabbit.core.version.InternalFrozenVersionHistory;
 import org.apache.jackrabbit.core.version.VersionSelector;
 import org.apache.jackrabbit.core.version.AbstractVersion;
+import org.apache.jackrabbit.core.version.DateVersionSelector;
 import org.apache.jackrabbit.core.lock.LockManager;
 import org.apache.jackrabbit.name.IllegalNameException;
 import org.apache.jackrabbit.name.MalformedPathException;
@@ -83,6 +84,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -2982,9 +2984,9 @@
         checkSessionHasPending();
         checkLock();
 
-        GenericVersionSelector gvs = new GenericVersionSelector();
-        gvs.setName(versionName);
-        internalRestore(getVersionHistory().getVersion(versionName), gvs, removeExisting);
+        Version v = getVersionHistory().getVersion(versionName);
+        DateVersionSelector gvs = new DateVersionSelector(v.getCreated());
+        internalRestore(v, gvs, removeExisting);
         // session.save/revert is done in internal restore
     }
 
@@ -3007,7 +3009,7 @@
             throw new VersionException("Unable to restore version. Not same version history.");
         }
 
-        internalRestore(version, new GenericVersionSelector(version.getCreated()), removeExisting);
+        internalRestore(version, new DateVersionSelector(version.getCreated()), removeExisting);
         // session.save/revert is done in internal restore
     }
 
@@ -3054,7 +3056,7 @@
             }
 
             // recreate node from frozen state
-            node.internalRestore(version, new GenericVersionSelector(version.getCreated()),
removeExisting);
+            node.internalRestore(version, new DateVersionSelector(version.getCreated()),
removeExisting);
             // session.save/revert is done in internal restore
         }
     }
@@ -3076,7 +3078,7 @@
         if (v == null) {
             throw new VersionException("No version for label " + versionLabel + " found.");
         }
-        internalRestore(v, new GenericVersionSelector(versionLabel), removeExisting);
+        internalRestore(v, new LabelVersionSelector(versionLabel), removeExisting);
         // session.save/revert is done in internal restore
     }
 
@@ -3846,12 +3848,17 @@
                 InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
                 VersionHistory history = (VersionHistory) session.getNodeById(f.getVersionHistoryId());
                 NodeId nodeId = NodeId.valueOf(history.getVersionableUUID());
+                String oldVersion = "jcr:dummy";
 
                 // check if representing versionable already exists somewhere
                 if (itemMgr.itemExists(nodeId)) {
                     NodeImpl n = session.getNodeById(nodeId);
                     if (removeExisting) {
-                        session.move(n.getPath(), getPath() + "/" + n.getName());
+                        String dstPath = getPath() + "/" + n.getName();
+                        if (!n.getPath().equals(dstPath)) {
+                            session.move(n.getPath(), dstPath);
+                        }
+                        oldVersion = n.getBaseVersion().getName();
                     } else if (n.getParent().isSame(this)) {
                         n.internalRemove(true);
                     } else {
@@ -3861,11 +3868,50 @@
                                 + n.safeGetJCRPath());
                     }
                 }
+                // get desired version from version selector
+                AbstractVersion v = (AbstractVersion) vsel.select(history);
+
+                // check existing version of item exists
+                NodeImpl node;
                 if (!itemMgr.itemExists(nodeId)) {
-                    // get desired version from version selector
-                    AbstractVersion v = (AbstractVersion) vsel.select(history);
-                    NodeImpl node = addNode(child.getName(), v.getFrozenNode());
-                    node.internalRestore(v, vsel, removeExisting);
+                    if (v == null) {
+                        // if version selector was unable to select version,
+                        // choose the initial one
+                        Version[] vs = history.getRootVersion().getSuccessors();
+                        if (vs.length == 0) {
+                            String msg = "Unable to select appropariate version for " +
+                                    child.getName() + " using " + vsel;
+                            log.error(msg);
+                            throw new VersionException(msg);
+                        }
+                        v = (AbstractVersion) vs[0];
+                    }
+                    node = addNode(child.getName(), v.getFrozenNode());
+                } else {
+                    node = session.getNodeById(nodeId);
+                    if (v == null || oldVersion == null || v.getName().equals(oldVersion))
{
+                        v = null;
+                    }
+                }
+                if (v != null) {
+                    try {
+                        node.internalRestore(v, vsel, removeExisting);
+                    } catch (RepositoryException e) {
+                        log.error("Error while restoring node: " + e.toString());
+                        log.error("  child path: " + node.safeGetJCRPath());
+                        log.error("  selected version: " + v.getName());
+                        StringBuffer avail = new StringBuffer();
+                        VersionIterator vi = history.getAllVersions();
+                        while (vi.hasNext()) {
+                            avail.append(vi.nextVersion().getName());
+                            if (vi.hasNext()) {
+                                avail.append(", ");
+                            }
+                        }
+                        log.error("  available versions: " + avail);
+                        log.error("  versionselector: " + vsel);
+                        throw e;
+                    }
                     // add this version to set
                     restored.add(v);
                 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java?rev=410311&r1=410310&r2=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
Tue May 30 09:06:30 2006
@@ -19,16 +19,16 @@
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.lock.LockManager;
+import org.apache.jackrabbit.core.observation.EventStateCollection;
+import org.apache.jackrabbit.core.observation.EventStateCollectionFactory;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
 import org.apache.jackrabbit.core.observation.ObservationManagerImpl;
-import org.apache.jackrabbit.core.observation.EventStateCollectionFactory;
-import org.apache.jackrabbit.core.observation.EventStateCollection;
 import org.apache.jackrabbit.core.query.QueryManagerImpl;
-import org.apache.jackrabbit.core.state.SharedItemStateManager;
 import org.apache.jackrabbit.core.state.LocalItemStateManager;
-import org.apache.jackrabbit.core.version.GenericVersionSelector;
-import org.apache.jackrabbit.core.version.VersionSelector;
+import org.apache.jackrabbit.core.state.SharedItemStateManager;
 import org.apache.jackrabbit.core.version.AbstractVersion;
+import org.apache.jackrabbit.core.version.DateVersionSelector;
+import org.apache.jackrabbit.core.version.VersionSelector;
 import org.apache.jackrabbit.core.xml.ImportHandler;
 import org.apache.jackrabbit.core.xml.Importer;
 import org.apache.jackrabbit.core.xml.WorkspaceImporter;
@@ -612,7 +612,7 @@
                 Version v = (Version) toRestore.get(versionHistory.getUUID());
                 if (v == null) {
                     // select latest one
-                    v = GenericVersionSelector.selectByDate(versionHistory, null);
+                    v = DateVersionSelector.selectByDate(versionHistory, null);
                 }
                 return v;
             }

Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java?rev=410311&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
(added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
Tue May 30 09:06:30 2006
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import java.util.Calendar;
+
+/**
+ * This Class implements a version selector that selects a version by creation
+ * date. The selected version is the latest that is older or equal than the
+ * given date. If no version could be found <code>null</code> is returned
+ * unless the <code>returnLatest</code> flag is set to <code>true</code>,
where
+ * the latest version is returned.
+ * <xmp>
+ * V1.0 - 02-Sep-2006
+ * V1.1 - 03-Sep-2006
+ * V1.2 - 05-Sep-2006
+ *
+ * new DateVersionSelector("03-Sep-2006").select() -> V1.1
+ * new DateVersionSelector("04-Sep-2006").select() -> V1.1
+ * new DateVersionSelector("01-Sep-2006").select() -> null
+ * new DateVersionSelector("01-Sep-2006", true).select() -> V1.2
+ * new DateVersionSelector(null, true).select() -> V1.2
+ * </xmp>
+ */
+public class DateVersionSelector implements VersionSelector {
+
+    /**
+     * a version date hint
+     */
+    private Calendar date = null;
+
+    /**
+     * flag indicating that it should return the latest version, if no other
+     * found
+     */
+    private boolean returnLatest = false;
+
+    /**
+     * Creates a <code>DateVersionSelector</code> that will select the latest
+     * version of all those that are older than the given date.
+     *
+     * @param date
+     */
+    public DateVersionSelector(Calendar date) {
+        this.date = date;
+    }
+
+    /**
+     * Creates a <code>DateVersionSelector</code> that will select the latest
+     * version of all those that are older than the given date.
+     *
+     * @param date
+     * @param returnLatest
+     */
+    public DateVersionSelector(Calendar date, boolean returnLatest) {
+        this.date = date;
+        this.returnLatest = returnLatest;
+    }
+
+    /**
+     * Returns the date hint
+     *
+     * @return the date hint.
+     */
+    public Calendar getDate() {
+        return date;
+    }
+
+    /**
+     * Sets the date hint
+     *
+     * @param date
+     */
+    public void setDate(Calendar date) {
+        this.date = date;
+    }
+
+    /**
+     * Returns the flag, if the latest version should be selected, if no
+     * version can be found using the given hint.
+     *
+     * @return <code>true</code> if it returns latest.
+     */
+    public boolean isReturnLatest() {
+        return returnLatest;
+    }
+
+    /**
+     * Sets the flag, if the latest version should be selected, if no
+     * version can be found using the given hint.
+     *
+     * @param returnLatest
+     */
+    public void setReturnLatest(boolean returnLatest) {
+        this.returnLatest = returnLatest;
+    }
+
+    /**
+     * Selects a version from the given version history using the previously
+     * assigned hint in the following order: name, label, date, latest.
+     *
+     * @param versionHistory
+     * @return
+     * @throws RepositoryException
+     */
+    public Version select(VersionHistory versionHistory) throws RepositoryException {
+        Version selected = null;
+        if (date != null) {
+            selected = DateVersionSelector.selectByDate(versionHistory, date);
+        }
+        if (selected == null && returnLatest) {
+            selected = DateVersionSelector.selectByDate(versionHistory, null);
+        }
+        return selected;
+    }
+
+    /**
+     * Selects a version by date.
+     *
+     * @param history
+     * @param date
+     * @return the latest version that is older than the given date date or
+     * <code>null</code>
+     * @throws RepositoryException
+     */
+    public static Version selectByDate(VersionHistory history, Calendar date)
+            throws RepositoryException {
+        long time = (date != null) ? date.getTimeInMillis() : Long.MAX_VALUE;
+        long latestDate = Long.MIN_VALUE;
+        Version latestVersion = null;
+        VersionIterator iter = history.getAllVersions();
+        while (iter.hasNext()) {
+            Version v = iter.nextVersion();
+            if (v.getPredecessors().length==0) {
+                // ignore root version
+                continue;
+            }
+            long c = v.getCreated().getTimeInMillis();
+            if (c > latestDate && c <= time) {
+                latestDate = c;
+                latestVersion = v;
+            }
+        }
+        return latestVersion;
+    }
+
+    /**
+     * returns debug information
+     * @return debug information
+     */
+    public String toString() {
+        StringBuffer ret = new StringBuffer();
+        ret.append("DateVersionSelector(");
+        ret.append("date=");
+        ret.append(date);
+        ret.append(", returnLatest=");
+        ret.append(returnLatest);
+        ret.append(")");
+        return ret.toString();
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/DateVersionSelector.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Copied: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
(from r409349, jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/GenericVersionSelector.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java?p2=jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java&p1=jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/GenericVersionSelector.java&r1=409349&r2=410311&rev=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/GenericVersionSelector.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
Tue May 30 09:06:30 2006
@@ -1,9 +1,10 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,22 +18,22 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
-import javax.jcr.version.VersionIterator;
-import java.util.Calendar;
 
 /**
- * This Class implements a generic version selector that either selects a
- * version by name, label or creation date. If no version is found and the
- * 'returnLatest' flag is set to <code>true</code>, the latest version is
- * returned.
+ * This Class implements a version selector that selects a version by label.
+ *
+ * <xmp>
+ * V1.0
+ * V1.1 - "foo"
+ *
+ * new LabelVersionSelector("foo").select() --> V1.1
+ * new LabelVersionSelector("bar").select() --> null
+ *
+ * </xmp>
  */
-public class GenericVersionSelector implements VersionSelector {
-
-    /**
-     * a versionname hint
-     */
-    private String name = null;
+public class LabelVersionSelector implements VersionSelector {
 
     /**
      * a versionlabel hint
@@ -40,61 +41,16 @@
     private String label = null;
 
     /**
-     * a version date hint
-     */
-    private Calendar date = null;
-
-    /**
-     * flag indicating that it should return the latest version, if no other found
-     */
-    private boolean returnLatest = true;
-
-    /**
-     * Creates a default <code>GenericVersionSelector</code> that always selects
-     * the latest version.
-     */
-    public GenericVersionSelector() {
-    }
-
-    /**
-     * Creates a <code>GenericVersionSelector</code> that will try to select
a
+     * Creates a <code>LabelVersionSelector</code> that will try to select a
      * version with the given label.
      *
      * @param label
      */
-    public GenericVersionSelector(String label) {
+    public LabelVersionSelector(String label) {
         this.label = label;
     }
 
     /**
-     * Creates a <code>GenericVersionSelector</code> that will select the oldest
-     * version of all those that are more recent than the given date.
-     *
-     * @param date
-     */
-    public GenericVersionSelector(Calendar date) {
-        this.date = date;
-    }
-
-    /**
-     * Returns the name hint.
-     *
-     * @return the name hint.
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Sets the name hint
-     *
-     * @param name
-     */
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    /**
      * Returns the label hint
      *
      * @return the label hint.
@@ -113,44 +69,6 @@
     }
 
     /**
-     * Returns the date hint
-     *
-     * @return the date hint.
-     */
-    public Calendar getDate() {
-        return date;
-    }
-
-    /**
-     * Sets the date hint
-     *
-     * @param date
-     */
-    public void setDate(Calendar date) {
-        this.date = date;
-    }
-
-    /**
-     * Returns the flag, if the latest version should be selected, if no
-     * version can be found using the given hint.
-     *
-     * @return <code>true</code> if it returns latest.
-     */
-    public boolean isReturnLatest() {
-        return returnLatest;
-    }
-
-    /**
-     * Sets the flag, if the latest version should be selected, if no
-     * version can be found using the given hint.
-     *
-     * @param returnLatest
-     */
-    public void setReturnLatest(boolean returnLatest) {
-        this.returnLatest = returnLatest;
-    }
-
-    /**
      * Selects a version from the given version history using the previously
      * assigned hint in the following order: name, label, date, latest.
      *
@@ -158,38 +76,9 @@
      * @return
      * @throws RepositoryException
      */
-    public Version select(VersionHistory versionHistory) throws RepositoryException {
-        Version selected = null;
-        if (name != null) {
-            selected = selectByName(versionHistory, name);
-        }
-        if (selected == null && label != null) {
-            selected = selectByLabel(versionHistory, label);
-        }
-        if (selected == null && date != null) {
-            selected = selectByDate(versionHistory, date);
-        }
-        if (selected == null && returnLatest) {
-            selected = selectByDate(versionHistory, null);
-        }
-        return selected;
-    }
-
-    /**
-     * Selects a version by version name.
-     *
-     * @param history
-     * @param name
-     * @return the version with the given name or <code>null</code>
-     * @throws RepositoryException
-     */
-    public static Version selectByName(VersionHistory history, String name)
+    public Version select(VersionHistory versionHistory)
             throws RepositoryException {
-        if (history.hasNode(name)) {
-            return history.getVersion(name);
-        } else {
-            return null;
-        }
+        return selectByLabel(versionHistory, label);
     }
 
     /**
@@ -202,32 +91,23 @@
      */
     public static Version selectByLabel(VersionHistory history, String label)
             throws RepositoryException {
-        return history.getVersionByLabel(label);
+        try {
+            return history.getVersionByLabel(label);
+        } catch (VersionException e) {
+            return null;
+        }
     }
 
     /**
-     * Selects a version by date.
-     *
-     * @param history
-     * @param date
-     * @return the latest version newer than the given date date or <code>null</code>
-     * @throws RepositoryException
+     * returns debug information
+     * @return debug information
      */
-    public static Version selectByDate(VersionHistory history, Calendar date)
-            throws RepositoryException {
-        long time = (date != null) ? date.getTimeInMillis() : Long.MAX_VALUE;
-        long latestDate = Long.MIN_VALUE;
-        Version latestVersion = null;
-        VersionIterator iter = history.getAllVersions();
-        while (iter.hasNext()) {
-            Version v = iter.nextVersion();
-            long c = v.getCreated().getTimeInMillis();
-            if (c > latestDate && c <= time) {
-                latestDate = c;
-                latestVersion = v;
-            }
-        }
-        return latestVersion;
+    public String toString() {
+        StringBuffer ret = new StringBuffer();
+        ret.append("LabelVersionSelector(");
+        ret.append("label=");
+        ret.append(label);
+        ret.append(")");
+        return ret.toString();
     }
-
 }

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/LabelVersionSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java?rev=410311&r1=410310&r2=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionSelector.java
Tue May 30 09:06:30 2006
@@ -16,19 +16,46 @@
  */
 package org.apache.jackrabbit.core.version;
 
+import org.apache.jackrabbit.core.NodeImpl;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 
 /**
  * This Interface defines the version selector that needs to provide a version,
- * given some hints and a version history
+ * given some hints and a version history. the selector is used in the various
+ * restore methods in order to select the correct version of previously versioned
+ * OPV=Version children upon restore. JSR170 states: <em>"This determination
+ * [of the version] depends on the configuration of the workspace and is outside
+ * the scope of this specification."</em>
+ * <p/>
+ * The version selection in jackrabbit works as follows:<br/>
+ * The <code>Node.restore()</code> methods uses the
+ * {@link DateVersionSelector} which is initialized with the creation date of
+ * the parent version. This selector selects the latest version that is equal
+ * or older than the given date. if no such version exists, the initial one
+ * is restored.<br/>
+ * The <code>Node.restoreByLabel()</code> uses the
+ * {@link LabelVersionSelector} which is initialized with the label of the
+ * version to be restored. This selector selectes the version with the same
+ * label. if no such version exists, the initial one is restored.
+ * <p/>
+ *
+ * @see DateVersionSelector
+ * @see LabelVersionSelector
+ * @see NodeImpl#restore(String, boolean)
+ * @see NodeImpl#restore(Version, boolean)
+ * @see NodeImpl#restore(Version, String, boolean)
+ * @see NodeImpl#restoreByLabel(String, boolean)
+ *
  */
 public interface VersionSelector {
 
     /**
      * Selects a version of the given version history. If this VersionSelector
-     * is unable to select one, it can return <code>null</code>.
+     * is unable to select one, it can return <code>null</code>. Please note,
+     * that a version selector is not allowed to return the root version.
      *
      * @param versionHistory
      * @return A version or <code>null</code>.

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java?rev=410311&r1=410310&r2=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java
Tue May 30 09:06:30 2006
@@ -50,6 +50,24 @@
     }
 
     /**
+     * If successful, the changes are persisted immediately, there is no need to
+     * call save.
+     */
+    public void testCloneNodesTwice() throws RepositoryException {
+        // clone referenceable node below non-referenceable node
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+
+        Node folder = node1.addNode("folder");
+        folder.addMixin("mix:referenceable");
+        node1.save();
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+
+        // there should not be any pending changes after clone
+        assertFalse(superuserW2.hasPendingChanges());
+    }
+
+    /**
      * A NoSuchWorkspaceException is thrown if srcWorkspace does not exist.
      */
     public void testCloneNodesInvalidWorkspace() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java?rev=410311&r1=410310&r2=410311&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/version/RestoreTest.java
Tue May 30 09:06:30 2006
@@ -298,4 +298,85 @@
             fail("Node.restore('1.3') must fail.");
         }
     }
+
+    /**
+     * Test the restore of the OPV=Version child nodes.
+     * @throws RepositoryException
+     */
+    public void testRestoreLabel() throws RepositoryException {
+        // V1.0 of versionableNode has no child
+        Node child1 = versionableNode.addNode("test:versionOnParentVersion");
+        child1.addMixin("mix:versionable");
+        versionableNode.save();
+        // create v1.0 of child
+        child1.checkin();
+
+        // V1 of versionable node has child1
+        Version v1 = versionableNode.checkin();
+
+        // mark V1 with label test and foo
+        versionableNode.getVersionHistory().addVersionLabel(v1.getName(), "test", true);
+        versionableNode.getVersionHistory().addVersionLabel(v1.getName(), "foo", true);
+
+        // create V1.1 of child
+        child1.checkout();
+        child1.checkin();
+        child1.getVersionHistory().addVersionLabel("1.1", "foo", true);
+
+        // restore 1.0 of versionable node --> no child
+        versionableNode.restore(version, true);
+        assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("test:versionOnParentVersion"));
+
+        // restore V1 via label. since child has no label, initial version should
+        // be restored
+        versionableNode.restoreByLabel("test", true);
+        assertTrue("Node.restore('test') must restore child node.", versionableNode.hasNode("test:versionOnParentVersion"));
+        child1 = versionableNode.getNode("test:versionOnParentVersion");
+        assertEquals("Node.restore('test') must restore child node version 1.0.", "1.0",
child1.getBaseVersion().getName());
+
+        // restore V1 via label 'foo'. since child has foo, 1.1 version should
+        // be restored
+        versionableNode.restoreByLabel("foo", true);
+        child1 = versionableNode.getNode("test:versionOnParentVersion");
+        assertEquals("Node.restore('foo') must restore child node version 1.1.", "1.1", child1.getBaseVersion().getName());
+    }
+
+    /**
+     * Test the restore of the OPV=Version child nodes.
+     * @throws RepositoryException
+     */
+    public void testRestoreName() throws RepositoryException {
+        // V1.0 of versionableNode has no child
+        Node child1 = versionableNode.addNode("test:versionOnParentVersion");
+        child1.addMixin("mix:versionable");
+        versionableNode.save();
+        // create v1.0 of child
+        child1.checkin();
+
+        // V1 of versionable node has child1
+        String v1 = versionableNode.checkin().getName();
+
+        // create V1.1 of child
+        child1.checkout();
+        child1.checkin();
+
+        // V2 of versionable node has child1
+        versionableNode.checkout();
+        String v2 = versionableNode.checkin().getName();
+
+        // restore 1.0 of versionable node --> no child
+        versionableNode.restore(version, true);
+        assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("test:versionOnParentVersion"));
+
+        // restore V1 via name. since child was checkin first, 1.0 should be restored
+        versionableNode.restore(v1, true);
+        assertTrue("Node.restore('test') must restore child node.", versionableNode.hasNode("test:versionOnParentVersion"));
+        child1 = versionableNode.getNode("test:versionOnParentVersion");
+        assertEquals("Node.restore('test') must restore child node version 1.0.", "1.0",
child1.getBaseVersion().getName());
+
+        // restore V2 via name. child should be 1.1
+        versionableNode.restore(v2, true);
+        child1 = versionableNode.getNode("test:versionOnParentVersion");
+        assertEquals("Node.restore('foo') must restore child node version 1.1.", "1.1", child1.getBaseVersion().getName());
+    }
 }



Mime
View raw message