if (!name.equals(ROOT_COLLECTION)) collectionsCache.remove(collection);
	public boolean removeCollection(Collection collection) throws PermissionDeniedException {	    if (readOnly)	        throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);	    	    if (!collection.getPermissions().validate(user, Permission.WRITE))	    	throw new PermissionDeniedException("not allowed to remove collection");	    	    final CollectionCache collectionsCache = pool.getCollectionsCache();	    synchronized(collectionsCache) {		    String name = collection.getName();		    // remove from parent collection		    Collection parent = openCollection(collection.getParentPath(), Lock.WRITE_LOCK);		    if (parent != null) {		    	try {		    		parent.removeCollection(name.substring(name.lastIndexOf("/") + 1));		    		saveCollection(parent);		    	} catch (LockException e) {		    		LOG.warn("LockException while removing collection " + name);		    	} finally {		    		parent.getLock().release();		    	}		    }		    		    // remove child collections		    String childName;		    Collection childCollection;		    LOG.debug("removing sub-collections");		    for (Iterator i = collection.collectionIterator(); i.hasNext();) {		    	childName = (String) i.next();		    	childCollection = openCollection(name + '/' + childName, Lock.WRITE_LOCK);		    	try {		    		removeCollection(childCollection);		    	} finally {		    		childCollection.getLock().release();		    	}		    }		    		    Lock lock = collectionsDb.getLock();		    try {		    	lock.acquire(Lock.WRITE_LOCK);		    			    	// if this is not the root collection remove it completely		    	if (name.equals(ROOT_COLLECTION))		    		saveCollection(collection);		    	else {		    		Value key;		    		try {		    			key = new Value(name.getBytes("UTF-8"));		    		} catch (UnsupportedEncodingException uee) {		    			key = new Value(name.getBytes());		    		}			    		collectionsDb.remove(key);		    	}		    	if (!name.equals(ROOT_COLLECTION))		    		collectionsCache.remove(collection);		    } catch (LockException e) {		    	LOG.warn("Failed to acquire lock on collections.dbx");		    } catch (ReadOnlyException e) {		    	throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);		    } finally {		    	lock.release();		    }	    		    freeCollection(collection.getId());	    		    textEngine.dropIndex(collection);		    elementIndex.dropIndex(collection);		    		    LOG.debug("removing resources ...");		    for (Iterator i = collection.iterator(this); i.hasNext();) {		    	final DocumentImpl doc = (DocumentImpl) i.next();		    	LOG.debug("removing document " + doc.getFileName());		    	new DOMTransaction(this, domDb, Lock.WRITE_LOCK) {		    		public Object start() {		    			if(doc.getResourceType() == DocumentImpl.BINARY_FILE) {		    				domDb.remove(doc.getAddress());		    				domDb.removeOverflowValue(((BinaryDocument)doc).getPage());		    			} else {		    				NodeImpl node = (NodeImpl)doc.getFirstChild();		    				domDb.removeAll(node.getInternalAddress());		    			}		    			return null;		    		}		    	}		    	.run();		    	new DOMTransaction(this, domDb, Lock.WRITE_LOCK) {		    		public Object start() {		    			try {		    				Value ref = new NodeRef(doc.getDocId());		    				IndexQuery query =		    					new IndexQuery(IndexQuery.TRUNC_RIGHT, ref);		    				domDb.remove(query, null);		    				domDb.flush();		    			} catch (BTreeException e) {		    				LOG.warn("btree error while removing document", e);		    			} catch (DBException e) {		    				LOG.warn("db error while removing document", e);		    			} catch (IOException e) {		    				LOG.warn("io error while removing document", e);		    			} catch (TerminatedException e) {		    				LOG.warn("method terminated", e);		    			}		    			return null;		    		}		    	}		    	.run();		    	freeDocument(doc.getDocId());		    }		    return true;	    }	}