collection.saveCollection();
broker.storeDocument(transaction, doc); transact.commit(transaction);
	public void lockResource(Resource res, User u) throws XMLDBException {		DocumentImpl doc = null;		DBBroker broker = null;		try {			broker = pool.get(user);			doc = ((AbstractEXistResource) res).openDocument(broker, Lock.WRITE_LOCK);			if (!doc.getPermissions().validate(user, Permission.UPDATE))				throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, 						"User is not allowed to lock resource " + res.getId());			org.exist.security.SecurityManager manager = pool.getSecurityManager();			if(!(user.equals(u) || manager.hasAdminPrivileges(user))) {				throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,						"User " + user.getName() + " is not allowed to lock resource for " +						"user " + u.getName());			}			User lockOwner = doc.getUserLock();			if(lockOwner != null) {				if(lockOwner.equals(u))					return;				else if(!manager.hasAdminPrivileges(user))					throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,							"Resource is already locked by user " + lockOwner.getName());			}			doc.setUserLock(u);			collection.saveCollection();		} catch (EXistException e) {			throw new XMLDBException(ErrorCodes.VENDOR_ERROR,					e.getMessage(), e);		} finally {			((AbstractEXistResource) res).closeDocument(doc, Lock.WRITE_LOCK);			pool.release(broker);		}	}