*/
public void removeVersionHistory(String vhID, QPath containingHistory, QPath ancestorToSave)
throws RepositoryException, ConstraintViolationException, VersionException
{
NodeData vhnode = (NodeData)getItemData(vhID);
if (vhnode == null)
{
ItemState vhState = changesLog.getItemState(vhID);
if (vhState != null && vhState.isDeleted())
{
// [PN] TODO check why we here if VH already isn't exists.
// usecase: child version remove when child versionable node is located
// as child
// of its containing history versionable node.
// We may check this case in ChildVersionRemoveVisitor.
return;
}
throw new RepositoryException("Version history is not found. UUID: " + vhID
+ ". Context item (ancestor to save) " + ancestorToSave.getAsString());
}
// mix:versionable
// we have to be sure that any versionable node somewhere in repository
// doesn't refers to a VH of the node being deleted.
RepositoryImpl rep = (RepositoryImpl)session.getRepository();
for (String wsName : rep.getWorkspaceNames())
{
SessionImpl wsSession =
session.getWorkspace().getName().equals(wsName) ? session : (SessionImpl)rep.getSystemSession(wsName);
try
{
for (PropertyData sref : wsSession.getTransientNodesManager().getReferencesData(vhID, false))
{
// Check if this VH isn't referenced from somewhere in workspace
// or isn't contained in another one as a child history.
// Ask ALL references incl. properties from version storage.
if (sref.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
{
if (!sref.getQPath().isDescendantOf(vhnode.getQPath())
&& (containingHistory != null ? !sref.getQPath().isDescendantOf(containingHistory) : true))
{
// has a reference to the VH in version storage,
// it's a REFERENCE property jcr:childVersionHistory of
// nt:versionedChild
// i.e. this VH is a child history in an another history.
// We can't remove this VH now.
return;
}
}
else if (wsSession != session)
{
// has a reference to the VH in traversed workspace,
// it's not a version storage, i.e. it's a property of versionable
// node somewhere in ws.
// We can't remove this VH now.
return;
} // else -- if we has a references in workspace where the VH is being
// deleted we can remove VH now.
}
}
finally
{
if (wsSession != session)
{
wsSession.logout();
}
}
}
// remove child versions from VH (if found)
ChildVersionRemoveVisitor cvremover =
new ChildVersionRemoveVisitor(session.getTransientNodesManager(), session.getWorkspace().getNodeTypesHolder(),
vhnode.getQPath(), ancestorToSave);
vhnode.accept(cvremover);
// remove VH
delete(vhnode, ancestorToSave, true);
}