Question

My question is : how do you read the version of a (child) frozen node?
More details :
- Lets imagine the following situation : node A has two children node B and node C.
- All three nodes are versionable nodes (have the mixin type)
- Let's say node A has 7 versions from 1.0 to 1.6 : at version 1.2 we added node B, at version 1.4 we added node C.
I have a routine that prints the "output" of node A at version 1.5.

 //I already obtained the Version object version associated to node A version 1.5
 NodeIterator nodeIterator = version.getNodes(); 
 while (nodeIterator.hasNext()) { 
   Node currentNode = nodeIterator.nextNode();
   System.out.println("Node: "+currentNode.getPath());
   // I can see that some of the nodes correspond to children (versions) of 
   //node B and C ..how can I get their version? 
 }

Thank you.

Was it helpful?

Solution

Each version in the history of the parent will contain a "frozen node" that represents a snapshot of the parent as it existed when the version was created (e.g., when the parent node was checked in). This frozen node contains child nodes that are either snapshots of the child (if the child was not versionable) or a "nt:versionedChild" node (if the child was versionable). This "nt:versionedChild" node contains a single "jcr:childVersionHistory" REFERENCE property that points to the version history of the child.

Section 3.13.10 of the JSR-283 specification contains a pretty good diagram that shows this structure.

Note that the "nt:versionedChild" node does not point to the particular version in the child's version history, which means that you have to determine which version of the child existed at the time the parent was checked in. After all, in this case of a versionable child, the parent and child version histories are independent and the nodes are checked in independently. (The reason might also stem from the fact that the application can change both the parent and child nodes in a single session, and then either check the parent in followed by checking the child in, or checking the child in followed by checking the parent in.)

One way to do this is by looking at the creation date of each version in the child's version history. This isn't ideal, as it will only tell you which child version existed at the time the parent was created. This could be ambiguous, since the comparison of timestamps depends on whether the parent was checked in before or after the versioned child. Within your application, you might have conventions that help you get around these ambiguities.

Perhaps a better option is to use version labels and apply the same label to the parent version and child version. (This is probably easier to do just after checking in the nodes rather than at a later time.) Then once you have a particular version of the parent, obtain its label and use it to find the corresponding version of the child in the child's version history (using VersionHistory.getVersionByLabel(String)).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top