new DOMTransaction(this, domDb) {
LOG.debug("removing document " + doc.getFileName()); new DOMTransaction(this, domDb, Lock.WRITE_LOCK) {
	public boolean removeCollection(String name) throws PermissionDeniedException {		if (readOnly)			throw new PermissionDeniedException("database is read-only");		try {			if (!name.startsWith("/db"))				name = "/db" + name;			Collection collection = getCollection(name);			if (collection == null) {				LOG.debug("collection " + name + " not found!");				return false;			}			if (!collection.getPermissions().validate(user, Permission.WRITE))				throw new PermissionDeniedException("not allowed to remove collection");			String childCollection;			LOG.debug("removing sub-collections");			for (Iterator i = collection.collectionIterator(); i.hasNext();) {				childCollection = (String) i.next();				removeCollection(					(name.equals("/")						? "/" + childCollection						: name + "/" + childCollection));			}			// if this is not the root collection remove it completely			if (name.equals("/db"))				saveCollection(collection);			else {				Value key;				try {					key = new Value(name.getBytes("UTF-8"));				} catch (UnsupportedEncodingException uee) {					key = new Value(name.getBytes());				}				Lock lock = collectionsDb.getLock();				try {					lock.acquire(Lock.WRITE_LOCK);					collectionsDb.remove(key);				} catch (LockException e) {					LOG.warn("failed to acquire lock on collections store", e);				} finally {					lock.release();				}			}			Lock lock = collectionsDb.getLock();			try {				lock.acquire();				if (!name.equals("/db"))					collectionsDb.getCollectionCache().remove(collection);				Collection parent = collection.getParent(this);				if (parent != null) {					parent.removeCollection(name.substring(name.lastIndexOf("/") + 1));					saveCollection(parent);					for (Iterator i = parent.collectionIterator(); i.hasNext();)						System.out.println(i.next());				}			} catch (LockException e) {				LOG.warn("failed to acquire lock on collections store", e);			} finally {				lock.release();			}			((NativeTextEngine) textEngine).removeCollection(collection);			LOG.debug("removing elements ...");			short collectionId = collection.getId();			Value ref = new ElementValue(collectionId);			IndexQuery query = new IndexQuery(IndexQuery.TRUNC_RIGHT, ref);			lock = elementsDb.getLock();			try {				lock.acquire(Lock.WRITE_LOCK);				elementsDb.removeAll(query);			} catch (LockException e) {				LOG.error("could not acquire lock on elements index", e);			} finally {				lock.release();			}			elementPool.clear();			LOG.debug("removed collection ...");			LOG.debug("removing dom ...");			for (Iterator i = collection.iterator(); i.hasNext();) {				final DocumentImpl doc = (DocumentImpl) i.next();				new DOMTransaction(this, domDb) {					public Object start() {						NodeList children = doc.getChildNodes();						NodeImpl node;						for (int j = 0; j < children.getLength(); j++) {							node = (NodeImpl) children.item(j);							Iterator k =								getDOMIterator(									new NodeProxy(										doc,										node.getGID(),										node.getInternalAddress()));							removeNodes(k);						}						domDb.remove(doc.getAddress());						return null;					}				}				.run();				new DOMTransaction(this, domDb) {					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);						}						return null;					}				}				.run();			}			return true;		} catch (IOException ioe) {			LOG.warn(ioe);		} catch (BTreeException bte) {			LOG.warn(bte);		} catch (ReadOnlyException e) {			LOG.warn("database is read-only");		}		return false;	}