jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kraemer, Fabian" <F.Krae...@esolut.de>
Subject AW: Restoring a node after move
Date Tue, 17 Oct 2006 13:01:27 GMT
Hi.

I'm new to JCR and wanted to test this case. I ran into the problem that after moving the
parent node my child reference becomes worthless, because it has been removed. Is there a
way I can teach my old object (Node d) that it has been moved (like calling a refresh, but
that doesn't help).

Thanks for any help in understanding this.
Regards, Fabian

	public void testMove() throws Exception {
		assertEquals("true", this.repository
				.getDescriptor(Repository.OPTION_VERSIONING_SUPPORTED));

		Node a = root.addNode("a");
		Node b = a.addNode("b");
		Node c = b.addNode("c");
		Node d = c.addNode("d");

		// make the node versionable
		d.addMixin("mix:versionable");
		d.setProperty("test", true);
		session.save();
		// make the original version
		Version beforeMove = d.checkin();
		d.checkout();

		assertEquals("/a/b/c/d", d.getPath());
		assertTrue(d.getProperty("test").getBoolean());

		// move the node
		session.move(d.getPath(), d.getParent().getPath() + "/e");
		// change the property
		d.setProperty("test", false);
		session.save();

		assertEquals("/a/b/c/e", d.getPath());
		assertTrue(!d.getProperty("test").getBoolean());

		d.restore(beforeMove, false);

		// after the restore of the original version the property has to be
		// restored, but the path
		// has to stay the same because it is in fact a property of the parent
		assertEquals("/a/b/c/e", d.getPath());
		assertTrue(d.getProperty("test").getBoolean());

		// now make the parent versionable
		c.addMixin("mix:versionable");
		session.save();
		// get the version of the parent
		Version beforeMoveParent = c.checkin();
		c.checkout();

		assertEquals("/a/b/c/e", d.getPath());

		// move the node
		session.move(d.getPath(), d.getParent().getPath() + "/f");
		session.save();

		assertEquals("/a/b/c/f", d.getPath());

		String uuid = d.getUUID();

		// restore the original father version
		c.restore(beforeMoveParent, false);

		// in fact, the item doesn't exist in the repository anymore
		try {
			uuid = d.getUUID();
			fail();
		} catch (InvalidItemStateException e) {

		}

		// get the only node of c
		NodeIterator iterator = c.getNodes();
		assertTrue(iterator.hasNext());
		Node movedNode = (Node) iterator.next();
		assertTrue(!iterator.hasNext());

		// the nodes are not the same objects anymore
		assertTrue(movedNode != d);
		
		//but have the same uuid
		assertEquals(uuid, movedNode.getUUID());

		//and the path is the old one
		assertEquals("/a/b/c/e", movedNode.getPath());
	} 

-----Urspr√ľngliche Nachricht-----
Von: tobias.strasser@gmail.com [mailto:tobias.strasser@gmail.com] Im Auftrag von Tobias Bocanegra
Gesendet: Dienstag, 17. Oktober 2006 12:49
An: users@jackrabbit.apache.org
Betreff: Re: Restoring a node after move

you would need to restore /a/b/c/d since a move modifies the state of the parent(s).

regards, toby

On 10/17/06, JavaJ <ponfar99@yahoo.com> wrote:
>
> Say you have a Node F at: /A/B/D/F with version 1.0, then you decide 
> to move it to /A/B/D/E (basically renaming it to "E") and version it 
> 1.1.  What happens if you restore the Node to version 1.0?  Will it's 
> name be "F" or "E"?
>
>
> --
> View this message in context: 
> http://www.nabble.com/Restoring-a-node-after-move-tf2456196.html#a6846
> 023 Sent from the Jackrabbit - Users mailing list archive at 
> Nabble.com.
>
>


--
-----------------------------------------< tobias.bocanegra@day.com >--- Tobias Bocanegra,
Day Management AG, Barfuesserplatz 6, CH - 4001 Basel T +41 61 226 98 98, F +41 61 226 98
97 -----------------------------------------------< http://www.day.com >---

Mime
View raw message