Trimming down or capping max version history for Apache Jackrabbit JCR -
in application uses apache jackrabbit jcr backend there versionable nodes in repository (mostly text content). seems version history nodes grows "in perpetuity".
what best/correct way configure max number of versions in version history (per workspace?) - future history entries , "trim down" existing version histories arbitrary max number of entries per history?
we set property, limit on number of versions want keep delete excess.
here's untested idea of how it...
public void deleteoldversions(session session, string abspath, int limit) throws repositoryexception { versionmanager versionmanager = session.getworkspace().getversionmanager(); versionhistory versionhistory = versionmanager.getversionhistory(abspath); versioniterator versioniterator = versionhistory.getalllinearversions(); // gets history in order long numbertodelete = versioniterator.getsize() - limit; while (numbertodelete-- > 0) { string versionname = versioniterator.nextversion().getname(); versionhistory.removeversion(versionname); } }
Comments
Post a Comment