LOG.debug("new doc address = " + StorageAddress.toString(doc.getAddress()));
	public void defrag(final DocumentImpl doc) {		LOG.debug("============> Defragmenting document " + 		        doc.getCollection().getName() + '/' + doc.getFileName());		final long start = System.currentTimeMillis();		try {		    final NodeImpl firstChild = (NodeImpl)doc.getFirstChild();		    			// dropping old structure index			elementIndex.dropIndex(doc);						// dropping dom index			NodeRef ref = new NodeRef(doc.getDocId());			final IndexQuery idx = new IndexQuery(IndexQuery.TRUNC_RIGHT, ref);			new DOMTransaction(this, domDb) {				public Object start() {					try {						domDb.remove(idx, null);						domDb.flush();					} catch (BTreeException e) {			            LOG.warn("start() - " + "error while removing doc", e);					} catch (DBException e) {			            LOG.warn("start() - " + "error while removing doc", e);					} catch (IOException e) {			            LOG.warn("start() - " + "error while removing doc", e);					} catch (TerminatedException e) {			            LOG.warn("method terminated", e);			        }					return null;				}			}			.run();						// create a copy of the old doc to copy the nodes into it			DocumentImpl tempDoc = new DocumentImpl(this, doc.getFileName(), doc.getCollection());			tempDoc.copyOf(doc);			tempDoc.setDocId(doc.getDocId());						// copy the nodes			Iterator iterator;			NodeList nodes = doc.getChildNodes();			NodeImpl n;			for (int i = 0; i < nodes.getLength(); i++) {			    n = (NodeImpl) nodes.item(i);			    iterator =			        getNodeIterator(			                new NodeProxy(doc, n.getGID(), n.getInternalAddress()));			    iterator.next();			    copyNodes(iterator, n, new NodePath(), tempDoc, false);			}			flush();						// remove the old nodes			new DOMTransaction(this, domDb) {				public Object start() {				    domDb.remove(doc.getAddress());					domDb.removeAll(firstChild.getInternalAddress());					return null;				}			}			.run();						doc.copyChildren(tempDoc);			doc.setSplitCount(0);			doc.setAddress(-1);			doc.setPageCount(tempDoc.getPageCount());			storeDocument(doc);			closeDocument();						saveCollection(doc.getCollection());			LOG.debug("Defragmentation took " + (System.currentTimeMillis() - start) + "ms.");		} catch (ReadOnlyException e) {			LOG.warn(DATABASE_IS_READ_ONLY, e);		} catch (PermissionDeniedException e) {		    LOG.warn(DATABASE_IS_READ_ONLY, e);        }	}