Hello Raj, Please find below an excerpt of some of our code that performs what you want. It deletes all nt:file nodes stored under a certain node and all the revisions of that file.
Hope this helps. You should also take a look at http://wiki.apache.org/jackrabbit/DataStore#Data_Store_Garbage_Collection to claim back disk space once you delete lots of revisions. Good luck // Files+revisions StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM [nt:file] WHERE ISDESCENDANTNODE('/workspaces/").append(wname).append("/content')"); // NOI18N NodeIterator nit2 = session.getWorkspace().getQueryManager().createQuery(sb.toString(), Query.JCR_SQL2).execute().getNodes(); VersionManager vm = session.getWorkspace().getVersionManager(); while (nit2.hasNext()) { Node node = nit2.nextNode(); getLogger().fine(String.format("Processing file stored at %s ...", node.getPath())); VersionHistory vh = vm.getVersionHistory(node.getNode(Node.JCR_CONTENT).getPath()); node.remove(); session.save(); for (VersionIterator vit = vh.getAllVersions(); vit.hasNext(); ) { Version v = vit.nextVersion(); String vname = v.getName(); if (!"jcr:rootVersion".equals(vname)) { // NOI18N vh.removeVersion(vname); getLogger().fine(String.format("Deleted version %s", vname)); // NOI18N } } } On Tue, May 24, 2011 at 12:34 PM, Raj <[email protected]> wrote: > Any pointers would be helpful. > > thanks, > Raj > > On Mon, May 23, 2011 at 2:12 PM, Raj <[email protected]> wrote: > >> hi All, >> >> My requirement is to delete the node and its history, as both won't be >> useful as per application logic. >> I would like to completely delete version history for the node as it will >> save us disk space and backup time. >> >> Node childNode = parentNode.getNode("mynode"); /* node to be >> completely deleted */ >> >> /* get a handle to version history before node deletion */ >> VersionHistory vh = >> session.getWorkspace().getVersionManager().getVersionHistory(childNode.getPath()); >> VersionIterator vitr = vh.getAllVersions(); >> vitr.skip(1); /* skipping as this is "jcr:baseVersion" */ >> List<String> vnames = new ArrayList<String>(); >> childNode.remove() ; >> session.save(); >> while (vitr.hasNext()) { >> Version v = vitr.nextVersion(); >> String vName = v.getName(); >> vnames.add(vName); >> } >> for (String name: vnames) { >> vh.removeVersion(name); >> } >> session.save(); >> >> Using this logic I can delete all version nodes, except the base node >> "jcr:baseVersion". >> Node hierarchy is root/parent/childNode. I don't have any references of >> childNode from any other node in Jack rabbit tree. >> >> Would like to know -- >> 1. How to completely delete the version history of node, including >> "jcr:baseVersion" ? >> >> 2. If it is impossible to delete them, what is the overhead (space and >> references wise) of leaving then hanging? >> >> 3. As per Cedric's reply, "jcr:baseVersion" should be auto deleted. When >> does the system actually delete it? During session.save() ? >> How to verify it? >> >> Pasted below is the note about auto deletion - >> http://web.archiveorange.com/archive/v/L1HBQ8pa9cRvxZlPyJ1C >> =================== >> >> Hi all, >> >> As of 1.6, empty and unused VersionHistory will be automatically removed >> after removal of the last Version (see >> https://issues.apache.org/jira/browse/JCR-134). >> This will ensure that the disk usage will not grow unnecessarily. >> >> Regards, >> Cédric >> >> =================== >> >> >> Related discussion - >> http://stackoverflow.com/questions/3531597/cant-remove-version-in-jackrabbit >> >> thanks & regards, >> Raj >> >> > -- Fabián Mandelbaum IS Engineer
