jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r416629 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Date Fri, 23 Jun 2006 08:14:31 GMT
Author: tripod
Date: Fri Jun 23 01:14:31 2006
New Revision: 416629

URL: http://svn.apache.org/viewvc?rev=416629&view=rev
Log:
JCR-469: Problem with child order after restoring of parent

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.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=416629&r1=416628&r2=416629&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 Fri
Jun 23 01:14:31 2006
@@ -1454,6 +1454,11 @@
         // check state of this instance
         sanityCheck();
 
+        // the absense of an index does not make sense here, so check
+        if (index <= 0) {
+            index = 1;
+        }
+
         NodeState thisState = (NodeState) state;
         NodeState.ChildNodeEntry cne = thisState.getChildNodeEntry(name, index);
         if (cne == null) {
@@ -1798,18 +1803,6 @@
             throws UnsupportedRepositoryOperationException, VersionException,
             ConstraintViolationException, ItemNotFoundException, LockException,
             RepositoryException {
-        // check state of this instance
-        sanityCheck();
-
-        if (!getPrimaryNodeType().hasOrderableChildNodes()) {
-            throw new UnsupportedRepositoryOperationException("child node ordering not supported
on node " + safeGetJCRPath());
-        }
-
-        // check arguments
-        if (srcName.equals(destName)) {
-            // there's nothing to do
-            return;
-        }
 
         Path.PathElement insertName;
         try {
@@ -1842,15 +1835,41 @@
         } else {
             beforeName = null;
         }
+        orderBefore(insertName, beforeName);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @param srcName
+     * @param dstName
+     */
+    public synchronized void orderBefore(Path.PathElement srcName,
+                                         Path.PathElement dstName)
+            throws UnsupportedRepositoryOperationException, VersionException,
+            ConstraintViolationException, ItemNotFoundException, LockException,
+            RepositoryException {
+
+        // check state of this instance
+        sanityCheck();
+
+        if (!getPrimaryNodeType().hasOrderableChildNodes()) {
+            throw new UnsupportedRepositoryOperationException("child node ordering not supported
on node " + safeGetJCRPath());
+        }
+
+        // check arguments
+        if (srcName.equals(dstName)) {
+            // there's nothing to do
+            return;
+        }
 
         // check existence
-        if (!hasNode(srcName)) {
+        if (!hasNode(srcName.getName(), srcName.getIndex())) {
             throw new ItemNotFoundException(safeGetJCRPath()
                     + " has no child node with name " + srcName);
         }
-        if (destName != null && !hasNode(destName)) {
+        if (dstName != null && !hasNode(dstName.getName(), dstName.getIndex())) {
             throw new ItemNotFoundException(safeGetJCRPath()
-                    + " has no child node with name " + destName);
+                    + " has no child node with name " + dstName);
         }
 
         // make sure this node is checked-out
@@ -1877,16 +1896,16 @@
         for (int i = 0; i < list.size(); i++) {
             NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
             if (srcInd == -1) {
-                if (entry.getName().equals(insertName.getName())
-                        && (entry.getIndex() == insertName.getIndex()
-                        || insertName.getIndex() == 0 && entry.getIndex() == 1))
{
+                if (entry.getName().equals(srcName.getName())
+                        && (entry.getIndex() == srcName.getIndex()
+                        || srcName.getIndex() == 0 && entry.getIndex() == 1)) {
                     srcInd = i;
                 }
             }
-            if (destInd == -1 && beforeName != null) {
-                if (entry.getName().equals(beforeName.getName())
-                        && (entry.getIndex() == beforeName.getIndex()
-                        || beforeName.getIndex() == 0 && entry.getIndex() == 1))
{
+            if (destInd == -1 && dstName != null) {
+                if (entry.getName().equals(dstName.getName())
+                        && (entry.getIndex() == dstName.getIndex()
+                        || dstName.getIndex() == 0 && entry.getIndex() == 1)) {
                     destInd = i;
                     if (srcInd != -1) {
                         break;
@@ -3834,6 +3853,7 @@
         InternalFreeze[] frozenNodes = freeze.getFrozenChildNodes();
         for (int i = 0; i < frozenNodes.length; i++) {
             InternalFreeze child = frozenNodes[i];
+            NodeImpl restoredChild = null;
             if (child instanceof InternalFrozenNode) {
                 InternalFrozenNode f = (InternalFrozenNode) child;
                 // check for existing
@@ -3853,8 +3873,8 @@
                         // ignore, item with uuid does not exist
                     }
                 }
-                NodeImpl n = addNode(f.getName(), f);
-                n.restoreFrozenState(f, vsel, restored, removeExisting);
+                restoredChild = addNode(f.getName(), f);
+                restoredChild.restoreFrozenState(f, vsel, restored, removeExisting);
 
             } else if (child instanceof InternalFrozenVersionHistory) {
                 InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
@@ -3884,7 +3904,6 @@
                 AbstractVersion v = (AbstractVersion) vsel.select(history);
 
                 // check existing version of item exists
-                NodeImpl node;
                 if (!itemMgr.itemExists(nodeId)) {
                     if (v == null) {
                         // if version selector was unable to select version,
@@ -3898,19 +3917,19 @@
                         }
                         v = (AbstractVersion) vs[0];
                     }
-                    node = addNode(child.getName(), v.getFrozenNode());
+                    restoredChild = addNode(child.getName(), v.getFrozenNode());
                 } else {
-                    node = session.getNodeById(nodeId);
+                    restoredChild = session.getNodeById(nodeId);
                     if (v == null || oldVersion == null || v.getName().equals(oldVersion))
{
                         v = null;
                     }
                 }
                 if (v != null) {
                     try {
-                        node.internalRestore(v, vsel, removeExisting);
+                        restoredChild.internalRestore(v, vsel, removeExisting);
                     } catch (RepositoryException e) {
                         log.error("Error while restoring node: " + e.toString());
-                        log.error("  child path: " + node.safeGetJCRPath());
+                        log.error("  child path: " + restoredChild.safeGetJCRPath());
                         log.error("  selected version: " + v.getName());
                         StringBuffer avail = new StringBuffer();
                         VersionIterator vi = history.getAllVersions();
@@ -3927,6 +3946,11 @@
                     // add this version to set
                     restored.add(v);
                 }
+            }
+            // ensure proper odering (issue JCR-469)
+            if (restoredChild != null
+                    && getPrimaryNodeType().hasOrderableChildNodes()) {
+                orderBefore(restoredChild.getPrimaryPath().getNameElement(), null);
             }
         }
     }



Mime
View raw message