You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ben Short <be...@benshort.co.uk> on 2009/12/14 13:25:44 UTC
Versioning
Hi,
I'm using Jackrabbit 2. Is the following scenario possible?
Node page = testRootNode.addNode("page");
page.addMixin("mix:versionable");
page.setProperty("name", "1");
page.setProperty("published", true);
session.save();
session.getWorkspace().getVersionManager().checkin(page.getPath());
session.getWorkspace().getVersionManager().checkout(page.getPath());
page.setProperty("name", "2");
page.setProperty("published", false);
session.save();
session.getWorkspace().getVersionManager().checkin(page.getPath());
At this point I would want to get the node that has the published
property set to true.
I can't see how to get the actual node from the version history so I
can query the bodes properties.
How can I proceed?
Ben Short
Re: Versioning
Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Dec 14, 2009 at 14:53, Ben Short <be...@benshort.co.uk> wrote:
> Version version = it.nextVersion();
>
> NodeIterator nodeIterator = version.getNodes();
>
> while(nodeIterator.hasNext()){
>
> Node node = nodeIterator.nextNode();
>
> System.out.println(node.getProperty("name").getString() + " " +
> node.getProperty("published").getString());
> }
>
> Why do I need to skip passed the first version?
The original node is stored as "jcr:frozenNode" child node below the
version node. This allows the version node to contain its own
metadata, like version tags etc.
See the JCR specs (1.0 [1] and 2.0 [2]). In JCR 2.0, a helper method
Version.getFrozenNode() was added for that [3].
[1] http://www.day.com/specs/jcr/1.0/8.2.2.5_nt_version.html
[2] http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#ntversion
[3] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/version/Version.html#getFrozenNode()
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Versioning
Posted by Ben Short <be...@benshort.co.uk>.
OK I have found the solution..
VersionHistory versionHistory =
session.getWorkspace().getVersionManager().getVersionHistory(page.getPath());
VersionIterator it = versionHistory.getAllVersions();
it.skip(1);
while ( it.hasNext()) {
Version version = it.nextVersion();
NodeIterator nodeIterator = version.getNodes();
while(nodeIterator.hasNext()){
Node node = nodeIterator.nextNode();
System.out.println(node.getProperty("name").getString() + " " +
node.getProperty("published").getString());
}
}
Why do I need to skip passed the first version?
2009/12/14 Ben Short <be...@benshort.co.uk>:
> Hi,
>
> I'm using Jackrabbit 2. Is the following scenario possible?
>
> Node page = testRootNode.addNode("page");
> page.addMixin("mix:versionable");
> page.setProperty("name", "1");
> page.setProperty("published", true);
>
> session.save();
>
> session.getWorkspace().getVersionManager().checkin(page.getPath());
>
> session.getWorkspace().getVersionManager().checkout(page.getPath());
> page.setProperty("name", "2");
> page.setProperty("published", false);
>
> session.save();
>
> session.getWorkspace().getVersionManager().checkin(page.getPath());
>
> At this point I would want to get the node that has the published
> property set to true.
>
> I can't see how to get the actual node from the version history so I
> can query the bodes properties.
>
> How can I proceed?
>
> Ben Short
>