Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 49900 invoked from network); 24 Dec 2006 07:31:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Dec 2006 07:31:53 -0000 Received: (qmail 45937 invoked by uid 500); 24 Dec 2006 07:32:01 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 45846 invoked by uid 500); 24 Dec 2006 07:32:00 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 45837 invoked by uid 99); 24 Dec 2006 07:32:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Dec 2006 23:32:00 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Dec 2006 23:31:52 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 2A5B71A981A; Sat, 23 Dec 2006 23:31:02 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r489996 - in /jackrabbit/branches/1.2/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java test/java/org/apache/jackrabbit/core/XATest.java Date: Sun, 24 Dec 2006 07:31:02 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061224073102.2A5B71A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Sat Dec 23 23:31:01 2006 New Revision: 489996 URL: http://svn.apache.org/viewvc?view=rev&rev=489996 Log: 1.2: Merged revisions 488639 and 488687 (JCR-529) Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java jackrabbit/branches/1.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java?view=diff&rev=489996&r1=489995&r2=489996 ============================================================================== --- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java (original) +++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/AbstractVersionManager.java Sat Dec 23 23:31:01 2006 @@ -29,12 +29,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; import javax.jcr.version.VersionException; import javax.jcr.version.VersionHistory; -import java.util.List; /** * Base implementation of the {@link VersionManager} interface. @@ -168,7 +169,7 @@ private boolean success = false; /** - * Saves the pending operations in the {@link StateManager}. + * Saves the pending operations in the {@link LocalItemStateManager}. * * @throws ItemStateException if the pending state is invalid * @throws RepositoryException if the pending state could not be persisted @@ -360,6 +361,7 @@ /** * Checks in a node * + * @param history the version history * @param node node to checkin * @return internal version * @throws javax.jcr.RepositoryException if an error occurs @@ -369,36 +371,7 @@ throws RepositoryException { WriteOperation operation = startWriteOperation(); try { - // 1. search a predecessor, suitable for generating the new name - Value[] values = node.getProperty(QName.JCR_PREDECESSORS).getValues(); - InternalVersion best = null; - for (int i = 0; i < values.length; i++) { - InternalVersion pred = history.getVersion(NodeId.valueOf(values[i].getString())); - if (best == null || pred.getSuccessors().length < best.getSuccessors().length) { - best = pred; - } - } - - // 2. generate version name (assume no namespaces in version names) - String versionName = best.getName().getLocalName(); - int pos = versionName.lastIndexOf('.'); - if (pos > 0) { - String newVersionName = versionName.substring(0, pos + 1) - + (Integer.parseInt(versionName.substring(pos + 1)) + 1); - if (history.hasVersion(new QName("", newVersionName))) { - versionName += ".1"; - } else { - versionName = newVersionName; - } - } else { - versionName = String.valueOf(best.getSuccessors().length + 1) + ".0"; - } - - // 3. check for colliding names - while (history.hasVersion(new QName("", versionName))) { - versionName += ".1"; - } - + String versionName = calculateCheckinVersionName(history, node); InternalVersionImpl v = history.checkin(new QName("", versionName), node); operation.save(); return v; @@ -409,6 +382,76 @@ } } + /** + * Calculates the name of the new version that will be created by a + * checkin call. The name is determined as follows: + *
    + *
  • first the predecessor version with the shortes name is searched. + *
  • if that predecessor version is the root version, the new version gets + * the name "{number of successors}+1" + ".0" + *
  • if that predecessor version has no successor, the last digit of it's + * version number is incremented. + *
  • if that predecessor version has successors but the incremented name + * does not exist, that name is used. + *
  • otherwise a ".0" is added to the name until a non conflicting name + * is found. + *
      + * + * Example Graph: + * + * jcr:rootVersion + * | | + * 1.0 2.0 + * | + * 1.1 + * | + * 1.2 ---\ ------\ + * | \ \ + * 1.3 1.2.0 1.2.0.0 + * | | + * 1.4 1.2.1 ----\ + * | | \ + * 1.5 1.2.2 1.2.1.0 + * | | | + * 1.6 | 1.2.1.1 + * |-----/ + * 1.7 + * + * + * @param history the version history + * @param node the node to checkin + * @return the new version name + * @throws RepositoryException if an error occurs. + */ + protected String calculateCheckinVersionName(InternalVersionHistoryImpl history, + NodeImpl node) + throws RepositoryException { + // 1. search a predecessor, suitable for generating the new name + Value[] values = node.getProperty(QName.JCR_PREDECESSORS).getValues(); + InternalVersion best = null; + for (int i = 0; i < values.length; i++) { + InternalVersion pred = history.getVersion(NodeId.valueOf(values[i].getString())); + if (best == null + || pred.getName().getLocalName().length() < best.getName().getLocalName().length()) { + best = pred; + } + } + // 2. generate version name (assume no namespaces in version names) + String versionName = best.getName().getLocalName(); + int pos = versionName.lastIndexOf('.'); + if (pos > 0) { + String newVersionName = versionName.substring(0, pos + 1) + + (Integer.parseInt(versionName.substring(pos + 1)) + 1); + while (history.hasVersion(new QName("", newVersionName))) { + versionName += ".0"; + newVersionName = versionName; + } + return newVersionName; + } else { + // best is root version + return String.valueOf(best.getSuccessors().length + 1) + ".0"; + } + } /** * Removes the specified version from the history Modified: jackrabbit/branches/1.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java?view=diff&rev=489996&r1=489995&r2=489996 ============================================================================== --- jackrabbit/branches/1.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java (original) +++ jackrabbit/branches/1.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java Sat Dec 23 23:31:01 2006 @@ -1077,7 +1077,7 @@ check(v1_2, phase, "1.0", 2); check(v2_2, phase, "1.0", 1); check(v2_3, phase, "1.1", 0); - check(v1_3, phase, "1.1.1", 0); + check(v1_3, phase, "1.0.0", 0); //log.println("--------checkout/checkin n1 (committed) ----------"); phase="checkin N1 committed."; @@ -1089,7 +1089,7 @@ check(v1_2, phase, "1.0", 2); check(v2_2, phase, "1.0", 2); check(v2_3, phase, "1.1", 0); - check(v1_3, phase, "1.1.1", 0); + check(v1_3, phase, "1.0.0", 0); //log.println("--------remove n1-1.0 (uncommitted) ----------"); phase="remove N1 1.0 uncommitted."; @@ -1104,7 +1104,7 @@ check(v1_2, phase, "1.0", -1); check(v2_2, phase, "1.0", 2); check(v2_3, phase, "1.1", 0); - check(v1_3, phase, "1.1.1", 0); + check(v1_3, phase, "1.0.0", 0); //log.println("--------remove n1-1.0 (committed) ----------"); phase="remove N1 1.0 committed."; @@ -1116,7 +1116,7 @@ check(v1_2, phase, "1.0", -1); check(v2_2, phase, "1.0", -1); check(v2_3, phase, "1.1", 0); - check(v1_3, phase, "1.1.1", 0); + check(v1_3, phase, "1.0.0", 0); //s1.logout(); s2.logout();