Value key; try { key = new Value(name.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException uee) { key = new Value(name.toString().getBytes()); }
Value key = new CollectionStore.CollectionKey(name.toString());
    public void moveCollection(Txn transaction, Collection collection, Collection destination, XmldbURI newName)     throws PermissionDeniedException, LockException {        if (readOnly)            throw new PermissionDeniedException(DATABASE_IS_READ_ONLY); 	   if(newName!=null && newName.numSegments()!=1) {		   throw new PermissionDeniedException("New collection name must have one segment!");	   }        if(collection.getId() == destination.getId())            throw new PermissionDeniedException("Cannot move collection to itself");        if(collection.getURI().equals(XmldbURI.ROOT_COLLECTION_URI))            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.getURI());        if(!destination.getPermissions().validate(user, Permission.WRITE))            throw new PermissionDeniedException("Insufficient privileges on target collection " +                    destination.getURI());            // check if another collection with the same name exists at the destination        Collection old = openCollection(destination.getURI().append(newName), Lock.WRITE_LOCK);        if(old != null) {            try {                removeCollection(transaction, old);            } finally {                old.release();            }        }        XmldbURI name = collection.getURI();        final CollectionCache collectionsCache = pool.getCollectionsCache();        synchronized(collectionsCache) {            Collection parent = openCollection(collection.getParentURI(), Lock.WRITE_LOCK);            if(parent != null) {                try {                    parent.removeCollection(name.lastSegment());                } finally {                    parent.release();                }            }            Lock lock = null;            try {                lock = collectionsDb.getLock();                lock.acquire(Lock.WRITE_LOCK);                                collectionsCache.remove(collection);                Value key;                try {                    key = new Value(name.toString().getBytes("UTF-8"));                } catch (UnsupportedEncodingException uee) {                    key = new Value(name.toString().getBytes());                }                   collectionsDb.remove(transaction, key);                collection.setPath(destination.getURI().append(newName));                collection.setCreationTime(System.currentTimeMillis());                                destination.addCollection(this, collection, false);                if(parent != null)                    saveCollection(transaction, parent);                if(parent != destination)                    saveCollection(transaction, destination);                saveCollection(transaction, collection);            } catch (ReadOnlyException e) {                throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);            } finally {                lock.release();            }                        XmldbURI childName;            Collection child;            for(Iterator i = collection.collectionIterator(); i.hasNext(); ) {                childName = (XmldbURI)i.next();                child = openCollection(name.append(childName), Lock.WRITE_LOCK);                if(child == null)                    LOG.warn("Child collection " + childName + " not found");                else {                    try {                        moveCollection(transaction, child, collection, childName);                    } finally {                        child.release();                    }                }            }        }    }    