2
votes

I'm using Jackrabbit/JCR 2.0.

Imagine the following scenario: I add a node, then I do a check-out on it, edit some properties and do check-in. Then I do it again.

Next, I can see in version history that versions 1.0 and 1.1 are created. How can I make it to increment always by 1, for example 1,2,3... etc.?

Also If I have node of type Version how to get to actual versioned Node (node that contains my data)?

And how can I add and get some other properties winch are version related like comment or author (user that checked in) of the version?

1

1 Answers

3
votes

You have to use your own version number property so you can increment it like you want (especially if you are not in simple versionable mode). To access the history and the properties of historised versions you have to use the VersionHisoty and get the version nodes using code like this :

VersionHistory history = session.getWorkspace().getVersionManager().getVersionHistory("/my/node/path");
// To iterate over all versions
VersionIterator versions = history.getAllVersions();
while (versions.hasNext()) {
  Version version = versions.nextVersion();
}
// Obtain version per name
Version mySpecificVersion = history.getVersion("myVersion");
//Obtain version per label
Version labelisedVersion = history.getVersionByLabel("myLabel");
String myVersionPropertyValue = labelisedVersion.getFrozenNode().getProperty("myProperty").getString();