Author: rhauch
Date: 2009-04-23 15:37:08 -0400 (Thu, 23 Apr 2009)
New Revision: 854
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-364 Session.move Is Not Implemented
Applied the patch. Some changes were required, as the before code was a little different
than the patch was expecting.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 18:45:00 UTC
(rev 853)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-04-23 19:37:08 UTC
(rev 854)
@@ -180,7 +180,7 @@
JcrWorkspace workspace() {
return this.workspace;
}
-
+
Graph.Batch createBatch() {
return graph.batch();
}
@@ -619,6 +619,7 @@
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
+
parser.setContentHandler(getImportContentHandler(parentAbsPath,
uuidBehavior));
parser.parse(new InputSource(in));
} catch (EnclosingSAXException ese) {
@@ -706,7 +707,7 @@
throw new ItemExistsException();
}
- newParentNode.editor().moveToBeChild(sourceNode.nodeUuid,
newNodeName.getName());
+ newParentNode.editor().moveToBeChild(sourceNode, newNodeName.getName());
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 18:45:00
UTC (rev 853)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-04-23 19:37:08
UTC (rev 854)
@@ -1219,7 +1219,7 @@
* Move the child specified by the supplied UUID to be a child of this node,
appending the child to the end of the current
* list of children. This method automatically disconnects the node from its
current parent.
*
- * @param nodeUuid the UUID of the existing node; may not be null
+ * @param child the UUID of the existing node; may not be null
* @param newNodeName
* @return the representation of the newly-added child, which includes the {@link
ChildNode#getSnsIndex()
* same-name-sibling index}
@@ -1228,11 +1228,11 @@
* @throws ConstraintViolationException if moving the node into this node
violates this node's definition
* @throws RepositoryException if any other error occurs while reading
information from the repository
*/
- public ChildNode moveToBeChild( UUID nodeUuid,
+ public ChildNode moveToBeChild( AbstractJcrNode child,
Name newNodeName )
throws ItemNotFoundException, InvalidItemStateException,
ConstraintViolationException, RepositoryException {
- // UUID nodeUuid = child.nodeUuid;
+ UUID nodeUuid = child.nodeUuid;
if (nodeUuid.equals(node.getUuid()) || isAncestor(nodeUuid)) {
Path pathOfNode = getPathFor(nodeUuid);
Path thisPath = currentLocation.getPath();
@@ -1241,8 +1241,9 @@
}
// Is the node already a child?
+ boolean nameDoesNotChange = newNodeName == null ||
newNodeName.equals(child.path().getLastSegment());
ChildNode existingChild = node.getChildren().getChild(nodeUuid);
- if (existingChild != null) return existingChild;
+ if (existingChild != null && nameDoesNotChange) return
existingChild;
JcrNodeDefinition definition = findBestNodeDefinition(node.getUuid(),
newNodeName, null);
@@ -1287,7 +1288,11 @@
existingParentInfo.addPeer(node.getUuid());
// Now, record the operation to do this ...
- operations.move(newChildEditor.currentLocation).into(currentLocation);
+ if (nameDoesNotChange) {
+ operations.move(newChildEditor.currentLocation).into(currentLocation);
+ } else {
+
operations.move(newChildEditor.currentLocation).as(newNodeName).into(currentLocation);
+ }
return newChild;
}
@@ -1592,19 +1597,18 @@
JcrNodeDefinition definition = nodeTypes().getNodeDefinition(nodeDefinitionId);
assert definition != null;
- if (root == null) {
- // Need to determine if this is the root node ...
- if (location.getPath().isRoot()) {
- // It is a root node ...
- JcrRootNode node = new JcrRootNode(this, uuid);
- jcrNodes.put(uuid, node);
- root = uuid;
- return node;
- }
+ // Need to determine if this is the root node ...
+ if (location.getPath().isRoot()) {
+ // It is a root node ...
+ JcrRootNode node = new JcrRootNode(this, uuid);
+ jcrNodes.put(uuid, node);
+ root = uuid;
+ return node;
}
// It is not a root node ...
JcrNode node = new JcrNode(this, uuid);
+ assert !uuid.equals(root);
jcrNodes.put(uuid, node);
return node;
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-04-23 18:45:00
UTC (rev 853)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2009-04-23 19:37:08
UTC (rev 854)
@@ -30,6 +30,7 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.io.ByteArrayInputStream;
@@ -46,6 +47,7 @@
import javax.jcr.Item;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
@@ -509,4 +511,18 @@
node.getUUID();
}
+ @Test
+ public void shouldMoveToNewName() throws Exception {
+ session.move("/a/b/c", "/a/b/d");
+
+
session.getRootNode().getNode("a").getNode("b").getNode("d");
+ try {
+
session.getRootNode().getNode("a").getNode("b").getNode("c");
+
+ fail("Node still exists at /a/b/c after move");
+ }
+ catch (PathNotFoundException e) {
+ // Expected
+ }
+ }
}
Show replies by date