jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r379085 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ItemValidator.java version/AbstractVersionManager.java
Date Mon, 20 Feb 2006 11:11:10 GMT
Author: tripod
Date: Mon Feb 20 03:11:07 2006
New Revision: 379085

URL: http://svn.apache.org/viewcvs?rev=379085&view=rev
Log:
- adjust generation of version names 
- suppress error message in ItemValidator 

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemValidator.java?rev=379085&r1=379084&r2=379085&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
Mon Feb 20 03:11:07 2006
@@ -32,6 +32,7 @@
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import java.util.Set;
 
@@ -234,7 +235,10 @@
     public String safeGetJCRPath(ItemId id) {
         try {
             return safeGetJCRPath(hierMgr.getPath(id));
-        } catch (RepositoryException re) {
+        } catch (ItemNotFoundException e) {
+            // return string representation if id as a fallback
+            return id.toString();
+        } catch (RepositoryException e) {
             log.error(id + ": failed to build path");
             // return string representation if id as a fallback
             return id.toString();

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java?rev=379085&r1=379084&r2=379085&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java
Mon Feb 20 03:11:07 2006
@@ -222,45 +222,29 @@
     protected InternalVersion checkin(InternalVersionHistoryImpl history, NodeImpl node)
             throws RepositoryException {
 
-        // 0. resolve the predecessors
+        // 1. search a predecessor, suitable for generating the new name
         Value[] values = node.getProperty(QName.JCR_PREDECESSORS).getValues();
-        InternalVersion[] preds = new InternalVersion[values.length];
+        InternalVersion best = null;
         for (int i = 0; i < values.length; i++) {
-            preds[i] = history.getVersion(NodeId.valueOf(values[i].getString()));
+            InternalVersion pred = history.getVersion(NodeId.valueOf(values[i].getString()));
+            if (best == null || pred.getSuccessors().length < best.getSuccessors().length)
{
+                best = pred;
+            }
         }
 
-        // 0.1 search a predecessor, suitable for generating the new name
-        String versionName = null;
-        int maxDots = Integer.MAX_VALUE;
-        for (int i = 0; i < preds.length; i++) {
-            // take the first pred. without a successor
-            if (preds[i].getSuccessors().length == 0) {
-                versionName = preds[i].getName().getLocalName(); //assuming no namespaces
in version names
-                // need to count the dots
-                int pos = -1;
-                int numDots = 0;
-                while (versionName.indexOf('.', pos + 1) >= 0) {
-                    pos = versionName.indexOf('.', pos + 1);
-                    numDots++;
-                }
-                if (numDots < maxDots) {
-                    maxDots = numDots;
-                    if (pos < 0) {
-                        versionName = "1.0";
-                    } else {
-                        versionName = versionName.substring(0, pos + 1)
-                                + (Integer.parseInt(versionName.substring(pos + 1)) + 1);
-                    }
-                }
-                break;
-            }
+        // 2. generate version name (assume no namespaces in version names)
+        String versionName = best.getName().getLocalName();
+        int pos = versionName.lastIndexOf('.');
+        if (pos>0) {
+            versionName = versionName.substring(0, pos + 1) +
+                (Integer.parseInt(versionName.substring(pos + 1)) + 1);
+        } else {
+            versionName = String.valueOf(best.getSuccessors().length + 1) + ".0";
         }
-        // if no empty found, generate new name
-        if (versionName == null) {
-            versionName = preds[0].getName().getLocalName();
-            do {
-                versionName += ".1";
-            } while (history.hasVersion(new QName("", versionName)));
+
+        // 3. check for colliding names
+        while (history.hasVersion(new QName("", versionName))) {
+            versionName += ".1";
         }
 
         try {



Mime
View raw message