Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2206

Session.move fails even if existing destination node is removed in the same session

XMLWordPrintable

    • Hide
      @Test
      public void testOverwritingMove() throws Exception {
          final Session session = repository.login();
      
          try {
              // add 2 nodes under a parent that doesn't allow SNS
              final Node root = session.getRootNode();
      
              final Node parent = root.addNode("parent", "nt:folder");
      
              parent.addNode("name1", "nt:folder");
              parent.addNode("name2", "nt:folder");
      
              session.save();
      
              assertTrue("Added node 1 exists", session.nodeExists("/parent/name1"));
              assertTrue("Added node 2 exists", session.nodeExists("/parent/name2"));
      
              // overwrite 2 with 1
              session.removeItem("/parent/name2");
              // or session.getNode("/parent/name2").remove()
      
              assertFalse("Added node 2 doest not exist after remove", session.nodeExists("/parent/name2"));
              assertTrue("Added node 1 still exists", session.nodeExists("/parent/name1"));
      
              session.move("/parent/name1", "/parent/name2"); // <-- BUG: ItemExistsException thrown
      
              session.save();
      
          } finally {
              session.logout();
          }
      }
      
      Show
      @Test public void testOverwritingMove() throws Exception { final Session session = repository.login(); try { // add 2 nodes under a parent that doesn't allow SNS final Node root = session.getRootNode(); final Node parent = root.addNode( "parent" , "nt:folder" ); parent.addNode( "name1" , "nt:folder" ); parent.addNode( "name2" , "nt:folder" ); session.save(); assertTrue( "Added node 1 exists" , session.nodeExists( "/parent/name1" )); assertTrue( "Added node 2 exists" , session.nodeExists( "/parent/name2" )); // overwrite 2 with 1 session.removeItem( "/parent/name2" ); // or session.getNode( "/parent/name2" ).remove() assertFalse( "Added node 2 doest not exist after remove" , session.nodeExists( "/parent/name2" )); assertTrue( "Added node 1 still exists" , session.nodeExists( "/parent/name1" )); session.move( "/parent/name1" , "/parent/name2" ); // <-- BUG: ItemExistsException thrown session.save(); } finally { session.logout(); } }
    • Hide

      Perform a Session.save() after Session.removeItem(destPath), and then do the Session.move after the save.

      (But this means it is not possible to perform a move with overwrite in one session)

      Show
      Perform a Session.save() after Session.removeItem(destPath) , and then do the Session.move after the save. (But this means it is not possible to perform a move with overwrite in one session)

      When trying to use Session.move(srcPath, destPath) when destPath exists, we must remove the node in destPath first. However, even after performing a Session.removeItem(destPath), Session.move still fails with the following exception:

      javax.jcr.ItemExistsException: A node definition that allows same name siblings could not be found for the node "/parent/name2[2]" in workspace "default"
      	at org.modeshape.jcr.AbstractJcrNode.validateChildNodeDefinition(AbstractJcrNode.java:1323)
      	at org.modeshape.jcr.JcrSession.move(JcrSession.java:1037)
      

      The problem only occurs if the parent node does not allow same name siblings.

      This effectively means it is not possible to implement behaviour to move and overwrite the destination node within one session.

              hchiorean Horia Chiorean (Inactive)
              herculeszeus_jira Hercules Zeus (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: