MojErr MojDbQuotaEngine::quotaForKind(const MojDbKind* kind, MojRefCountedPtr<Quota>& quotaOut) { // prefer to use super's quota const MojDbKind::KindVec& supers = kind->supers(); for (MojDbKind::KindVec::ConstIterator i = supers.begin(); i != supers.end(); ++i) { // don't want to inherit admin quota, so don't check root kind if ((*i)->id() != MojDbKindEngine::RootKindId) { MojErr err = quotaForKind(*i, quotaOut); MojErrCheck(err); if (quotaOut.get()) return MojErrNone; } } // check for quota that matches owner of this kindS const MojString& owner = kind->owner(); QuotaMap::ConstIterator iter = m_quotas.find(owner); if (iter == m_quotas.end()) { for (iter = m_quotas.begin(); iter != m_quotas.end(); ++iter) { if (matchWildcard(iter.key(), owner, owner.length())) break; } } if (iter != m_quotas.end()) { quotaOut = *iter; } return MojErrNone; }
MojErr MojDbQuotaEngine::quotaUsage(const MojChar* owner, MojInt64& sizeOut, MojInt64& usageOut) { sizeOut = 0; usageOut = 0; QuotaMap::ConstIterator iter = m_quotas.find(owner); if (iter == m_quotas.end()) { MojErrThrow(MojErrNotFound); } sizeOut = iter.value()->size(); usageOut = iter.value()->usage(); return MojErrNone; }
MojErr MojDbQuotaEngine::quotaUsage(const MojChar* owner, MojInt64& sizeOut, MojInt64& usageOut) { LOG_TRACE("Entering function %s", __FUNCTION__); sizeOut = 0; usageOut = 0; QuotaMap::ConstIterator iter = m_quotas.find(owner); if (iter == m_quotas.end()) { MojErrThrow(MojErrNotFound); } sizeOut = iter.value()->size(); usageOut = iter.value()->usage(); return MojErrNone; }
MojErr MojDbQuotaEngine::stats(MojObject& objOut, MojDbReq& req) { // check for admin permission if (!req.admin()) { MojErrThrow(MojErrDbPermissionDenied); } for (QuotaMap::ConstIterator i = m_quotas.begin(); i != m_quotas.end(); ++i) { MojObject quota; MojErr err = quota.put(MojDbServiceDefs::SizeKey, i.value()->size()); MojErrCheck(err); err = quota.put(MojDbServiceDefs::UsedKey, i.value()->usage()); MojErrCheck(err); err = objOut.put(i.key(), quota); MojErrCheck(err); } return MojErrNone; }