You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2007/05/23 17:53:46 UTC
svn commit: r540982 -
/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Author: angela
Date: Wed May 23 08:53:45 2007
New Revision: 540982
URL: http://svn.apache.org/viewvc?view=rev&rev=540982
Log:
PathNotFoundException when removing same-name-siblings in the same batch starting from lower index
Modified:
jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?view=diff&rev=540982&r1=540981&r2=540982
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java Wed May 23 08:53:45 2007
@@ -927,6 +927,11 @@
private final class BatchImpl implements Batch {
private final SessionInfoImpl sInfo;
+ /* If this batch needs to remove multiple same-name-siblings starting
+ from lower index, the index of the following siblings must be reset
+ in order to avoid PathNotFoundException.
+ */
+ private final Set removedNodeIds = new HashSet();
private boolean failed = false;
@@ -1033,7 +1038,8 @@
public Object run() throws RepositoryException {
try {
if (itemId.denotesNode()) {
- getNode((NodeId) itemId, sInfo).remove();
+ NodeId nodeId = calcRemoveNodeId(itemId);
+ getNode(nodeId, sInfo).remove();
} else {
getProperty((PropertyId) itemId, sInfo).remove();
}
@@ -1049,6 +1055,32 @@
return null;
}
});
+ }
+
+ private NodeId calcRemoveNodeId(ItemId itemId) {
+ NodeId nodeId = (NodeId) itemId;
+ try {
+ Path p = itemId.getPath();
+ if (p != null) {
+ removedNodeIds.add(itemId);
+ int index = p.getNameElement().getNormalizedIndex();
+ if (index > Path.INDEX_DEFAULT && !removedNodeIds.isEmpty()) {
+ Path.PathElement[] elems = p.getElements();
+ Path.PathBuilder pb = new Path.PathBuilder();
+ for (int i = 0; i <= elems.length - 2; i++) {
+ pb.addLast(elems[i]);
+ }
+ pb.addLast(p.getNameElement().getName(), index - 1);
+ NodeId prevSibling = idFactory.createNodeId(itemId.getUniqueID(), pb.getPath());
+ if (removedNodeIds.contains(prevSibling)) {
+ nodeId = prevSibling;
+ }
+ }
+ }
+ } catch (MalformedPathException e) {
+ // ignore
+ }
+ return nodeId;
}
public void reorderNodes(final NodeId parentId,