Lock lock = null; try { lock = collectionsDb.getLock(); lock.acquire(Lock.WRITE_LOCK);
	public void moveCollection(Collection collection, Collection destination, String newName) 	throws PermissionDeniedException, LockException {	    if (readOnly)			throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);	    if(collection.getId() == destination.getId())	    	throw new PermissionDeniedException("Cannot move collection to itself");	    if(collection.getName().equals(ROOT_COLLECTION))	        throw new PermissionDeniedException("Cannot move the db root collection");	    if(!collection.getPermissions().validate(user, Permission.WRITE))	        throw new PermissionDeniedException("Insufficient privileges to move collection " +	                collection.getName());	    if(!destination.getPermissions().validate(user, Permission.WRITE))	        throw new PermissionDeniedException("Insufficient privileges on target collection " +	                destination.getName());	    if(newName == null) {            int p = collection.getName().lastIndexOf('/');            newName = collection.getName().substring(p + 1);        }	    if(newName.indexOf('/') > -1)	        throw new PermissionDeniedException("New collection name is illegal (may not contain a '/')");	    Lock lock = null;	    try {	        lock = collectionsDb.getLock();	        lock.acquire(Lock.WRITE_LOCK);	        // check if another collection with the same name exists at the destination		    Collection old = getCollection(destination.getName() + '/' + newName);		    if(old != null)		        removeCollection(old.getName());		    	        String name = collection.getName();	        Collection parent = collection.getParent(this);	        if(parent != null)	            parent.removeCollection(name.substring(name.lastIndexOf("/") + 1));		    	        collectionsDb.getCollectionCache().remove(collection);		    Value key;			try {				key = new Value(name.getBytes("UTF-8"));			} catch (UnsupportedEncodingException uee) {				key = new Value(name.getBytes());			}				collectionsDb.remove(key);					    collection.setName(destination.getName() + '/' + newName);		    collection.setCreationTime(System.currentTimeMillis());		    		    destination.addCollection(collection);		    if(parent != null)		        saveCollection(parent);		    if(parent != destination)		        saveCollection(destination);		    saveCollection(collection);		    		    String childName;		    Collection child;		    for(Iterator i = collection.collectionIterator(); i.hasNext(); ) {		        childName = (String)i.next();		        child = getCollection(name + '/' + childName);		        if(child == null)		            LOG.warn("Child collection " + childName + " not found");		        else		            moveCollection(child, collection, childName);		    }	    } catch (ReadOnlyException e) {            throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);        } finally {	        lock.release();	    }	}