jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anja86 <anja....@gmail.com>
Subject cannot delete base version
Date Mon, 16 Jul 2007 08:24:57 GMT

i'm still new in repository..
i want to delete all version, but my base version and root version cannot be
delete.. please help me.. 
this is my code.. i do something wrong?

public void deleteAllVersion(Node node) throws VersionException,
LockException, ConstraintViolationException, RepositoryException {
		
		Node resNode = node.getNode("jcr:content");
		VersionHistory versionHistory = resNode.getVersionHistory();
		//VersionIterator versionIterator = versionHistory.getAllVersions();
		String baseVersion = resNode.getBaseVersion().getName();
		resNode.checkout();
		for(VersionIterator versionIterator = versionHistory.getAllVersions();
versionIterator.hasNext();){
			Version currentVersion = versionIterator.nextVersion();
			String versionName = currentVersion.getName();
			if (!versionName.equals("jcr:rootVersion") &&
!versionName.equals(baseVersion)) {
		        
		        versionHistory.removeVersion(versionName);
		        
			}
			
		}
		
		jcrSession.save();
	}

	public void removeVersion(Node node, String versionLabel) throws
RepositoryException, ReferentialIntegrityException, AccessDeniedException,
    UnsupportedRepositoryOperationException, VersionException {
		Node resNode = node.getNode("jcr:content");
		
		VersionHistory versionHistory = resNode.getVersionHistory();
		String baseVersion = resNode.getBaseVersion().getName();
		
		if(versionLabel == "jcr:rootVersion"){
			
			//versionHistory.getRootVersion().getNodes().remove();
			
			NodeIterator ni = resNode.getNodes();
			
			while(ni.hasNext()){
					ni.nextNode().remove();
			}
			
			resNode.remove();
			node.save();
			
		}
		
		else if(versionLabel.equals(baseVersion)){

			resNode.getBaseVersion().removeMixin("mix:versionable");
			resNode.getBaseVersion().remove();
		}
		
		else{
			versionHistory.removeVersion(versionLabel);
		}
		resNode.save();
	}
-- 
View this message in context: http://www.nabble.com/cannot-delete-base-version-tf4085123.html#a11610950
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message