Following code segment is used to add a label to a node using ModeShape. What query string I could use to query this node with the QueryManager? It seems that the nodes from versionHistory side cannot be queried with the QueryManager.
VersionHistory history = session.getWorkspace().getVersionManager()
.getVersionHistory(node.getPath());
history.addVersionLabel(version.getName(), "label", true);
I cannot find any nodes with the following query relating to version history. Is there anything missing from this query?
Query query = queryManager
.createQuery("select * from [nt:base]", Query.JCR_SQL2);
Thanks!
All of the version information is stored on the
nt:versionHistory
nodes under the/jcr:system/jcr:versionStorage
area of the workspace (shared amongst all workspaces in a repository). The structure of this area looks something like this:The
jcr:versionLabels
node contains a property for each label, where the name of the property is the label string and the value of the property is a REFERENCE to the version to which that label applies.In order to find the labeled version of a versionable node, you'll actually have to query the contents of this "/jcr:system/jcr:versionStorage" area, using the appropriate types and join constraints.
For example, to find the version with a particular label "foo", you'd do something like this:
This search all of the
nt:versionLabels
nodes looking for a property named 'myLabel' (which is the name of your label), and then finds thent:version
node to which that points, and thent:frozenNode
that is the copy of the versionable node for that version.As you can see, the version history representations as prescribed by the JCR specification are quite difficult to query.
Alternatively, you could do this in two steps:
jcr:uuid
of the version(s) that has a particular label