Exemplo n.º 1
0
MojErr MojDbPerfUpdateTest::timeUpdateKind(MojDb& db, const MojChar* kindJson, MojObject& kindObj, MojTime& addIndexTime, MojTime& dropIndexTime)
{
	MojTime startTime;
	MojTime endTime;
	MojObject origKindObj;
	MojErr err = origKindObj.fromJson(kindJson);
	MojTestErrCheck(err);

	for (MojUInt64 i = 0; i < numUpdateKindIterations; i++) {
		err = MojGetCurrentTime(startTime);
		MojTestErrCheck(err);
		bool found;
		err = kindObj.del(MojDb::RevKey, found);
		MojTestErrCheck(err);
		err = db.putKind(kindObj);
		MojTestErrCheck(err);
		err = MojGetCurrentTime(endTime);
		MojTestErrCheck(err);
		addIndexTime += (endTime - startTime);
		totalTestTime += (endTime - startTime);

		err = MojGetCurrentTime(startTime);
		MojTestErrCheck(err);
		err = origKindObj.del(MojDb::RevKey, found);
		MojTestErrCheck(err);
		err = db.putKind(origKindObj);
		MojTestErrCheck(err);
		err = MojGetCurrentTime(endTime);
		MojTestErrCheck(err);
		dropIndexTime += (endTime - startTime);
		totalTestTime += (endTime - startTime);
	}

	return MojErrNone;
}
Exemplo n.º 2
0
MojErr MojObjectTest::emptyTest(MojObject& obj)
{
    MojObject obj2;
    MojString str1;
    MojString str2;

    bool found = false;

    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());

    MojTestAssert(obj.begin() == obj.end());
    MojTestAssert(!obj.contains(_T("hello")));
    MojTestAssert(!obj.get(_T("hi"), obj2));
    MojErr err = obj.del(_T("hello"), found);
    MojTestErrCheck(err);

    obj2.assign(obj);
    MojTestAssert(obj2.type() == obj.type());
    MojTestAssert(obj2 == obj);
    MojTestAssert(!(obj2 != obj));

    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    err = obj2.stringValue(str2);
    MojTestErrCheck(err);
    MojTestAssert(str1 == str2);

    return MojErrNone;
}
Exemplo n.º 3
0
MojErr MojDbSearchCache::QueryKey::setQuery(const MojDbQuery& query)
{
    MojObject obj;
    MojErr err = query.toObject(obj);
    MojErrCheck(err);

    bool foundOut=false;
    obj.del(MojDbQuery::PageKey, foundOut);
    obj.del(MojDbQuery::LimitKey, foundOut);

    err = obj.toJson(m_query);
    MojErrCheck(err);

    setKind(query.from());
    return err;
}
    MojErr Response(MojObject& response, MojErr err)
    {
        bool success = true;
        bool getSuccess = response.get("returnValue", success);

        if (err || !getSuccess || !success) {
            // unfortunately file cache doesn't use regular C++ mojo error codes
            // & more unfortunately all the various failure reasons for define are hidden
            // behind 1 error code
            MojInt64 errorCode;
            if (response.get("errorCode", errorCode)) {
                FileCacheFailure failure = (FileCacheFailure)errorCode;
                // be generous in the error code that can be used
                if (failure == FCDefineError || failure == FCExistsError) {
                    MojString mojErrorText;
                    string errorText;
                    std::string nakOkSuffix = "' already exists.";

                    response.getRequired("errorText", mojErrorText);
                    errorText = mojErrorText.data();

                    if (endsWith(errorText, nakOkSuffix)) {
                        LOG_DEBUG("caching negative response for %s", m_config.c_str());
                        bool found = false;
                        response.del("errorCode", found);
                        response.del("errorText", found);
                        err = response.putBool("returnValue", true);
                        MarkConfigured();
                    } else {
                        LOG_WARNING(MSGID_FILE_CACHE_CONFIG_WARNING, 2,
                                    PMLOGKS("error", errorText.c_str()),
                                    PMLOGKS("suffix", nakOkSuffix.c_str()),
                                    "File cache failed to register type (`%s' doesn't end with `%s'", errorText.c_str(), nakOkSuffix.c_str());
                    }
                } else {
                    LOG_WARNING(MSGID_FILE_CACHE_CONFIG_WARNING, 1,
                                PMLOGKFV("error", "%d", (int)errorCode),
                                "Unrecognized errorCode %d", (int)errorCode);
                }
            } else {
                LOG_WARNING(MSGID_FILE_CACHE_CONFIG_WARNING, 0, "errorCode not provided in request failure");
            }
        } else {
            LOG_DEBUG("FileCacheConfigurator response for %s contained no problems", m_config.c_str());
        }
        return DelegateResponse(response, err);
    }
Exemplo n.º 5
0
MojErr MojDbKindState::delIndex(const MojChar* indexName, MojDbReq& req)
{
	MojAssert(indexName);
	MojThreadGuard guard(m_lock);

	MojObject obj;
	MojRefCountedPtr<MojDbStorageItem> item;
	MojErr err = readIds(IndexIdsKey, req, obj, item);
	MojErrCheck(err);
	bool found = false;
	err = obj.del(indexName, found);
    MojErrCheck(err);
	MojAssert(found);
	err = writeIds(IndexIdsKey, obj, req, item);
	MojErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 6
0
void SaveEmailCommand::WriteToFileCache(MojObject &part, const MojString &pathName)
{
	MojErr err;
	MojString content;
	err = part.getRequired("content", content);
	ErrorToException(err);
	
	// FIXME: make this async
	FILE *fp = fopen(pathName.data(), "w");
	if(fp) {
		fwrite(content.data(), sizeof(MojChar), content.length(), fp);
		fclose(fp);
	} else {
		throw MailException("error opening file cache path", __FILE__, __LINE__);
	}
	
	// Cancel subscription to signal that we're done writing
	m_fileCacheInsertedSlot.cancel();

	MojString type;
	err = part.getRequired(EmailSchema::Part::TYPE, type);
	ErrorToException(err);

	if (type == EmailSchema::Part::Type::BODY) {
		std::string previewText = PreviewTextGenerator::GeneratePreviewText(content.data(), MAX_SUMMARY_LENGTH, true);
		err = m_email.putString(EmailSchema::SUMMARY, previewText.c_str());
		ErrorToException(err);
	}

	// Delete content field so it doesn't get written to the database
	bool wasDeleted;
	part.del("content", wasDeleted);
	
	// Next step
	if(m_partsIt == m_partsArray.arrayEnd())
		PersistToDatabase(); // done
	else
		CreateNextCacheObject(); // more parts remaining
	
	return;
}
Exemplo n.º 7
0
/**
 * Log the json for an incoming IM payload so we can troubleshoot errors in the field in
 * non debug builds.
 *
 * removes "private" data - ie. message body
 */
MojErr IMServiceHandler::privatelogIMMessage(const MojChar* format, MojObject IMObject, const MojChar* messageTextKey) {

	MojString mojStringJson;
	MojString msgText;

	// replace the message body
	// not much we can do about errors here...

	bool found = false;
	MojErr err = IMObject.del(messageTextKey, found);
	MojErrCheck(err);
	if (found) {
		msgText.assign(_T("***IM Body Removed***"));
		IMObject.put(messageTextKey, msgText);
	}

	// log it (non debug)
	IMObject.toJson(mojStringJson);
	MojLogNotice(IMServiceApp::s_log, format, mojStringJson.data());

	return MojErrNone;
}
Exemplo n.º 8
0
MojErr MojDb::dumpObj(MojFile& file, MojObject obj, MojSize& bytesWrittenOut, MojUInt32 maxBytes)
{
	// remove the rev key before dumping the object
	bool found = false;
	MojErr err = obj.del(RevKey, found);
	MojErrCheck(err);

	MojString str;
	err = obj.toJson(str);
	MojErrCheck(err);
	err = str.append(_T("\n"));
	MojErrCheck(err);
	MojSize len = str.length() * sizeof(MojChar);
	// if writing this object will put us over the max length, throw an error
	if (maxBytes && bytesWrittenOut + len > maxBytes) {
		MojErrThrow(MojErrDbBackupFull);
	}
	err = file.writeString(str, bytesWrittenOut);
	MojErrCheck(err);

	return MojErrNone;
}
	MojErr Response(MojObject& response, MojErr err)
	{
		bool success = true;
		response.get("returnValue", success);

		if (err || !success) {
			MojInt64 errorCode;
			if (response.get("errorCode", errorCode)) {
				if (errorCode == MojErrExists) {
					MojLogInfo(Logger(), "caching ok negative response for %s", m_config.c_str());
					bool found = false;
					response.del("errorCode", found);
					response.del("errorText", found);
					err = response.putBool("returnValue", true);
					MarkConfigured();
				} else {
					MojLogWarning(Logger(), "Unrecognized errorCode %d", (int)errorCode);
				}
			} else {
				MojLogWarning(Logger(), "errorCode not provided in request failure");
			}
		}
		return DelegateResponse(response, err);
	}
Exemplo n.º 10
0
static void RemoveKey(MojObject& object, const MojChar *key)
{
	bool keydeleted;
	object.del(key, keydeleted);
}