Esempio n. 1
0
MojErr PopBusDispatcher::AccountCreator::CreatePopAccountResponse(MojObject& response, MojErr err)
{
	MojLogInfo(m_log, "AccountCreator::CreatePopAccountResponse");

	MojLogTrace(m_log);
	if (err)
		return m_msg->replyError(err);

	MojString json;
	err = response.toJson(json);
	MojLogInfo(m_log, "%s", json.data());

	// put the id we have just gotten into the payload we send to smtp account
	MojObject resultArray;
	err = response.getRequired("results", resultArray);
	ErrorToException(err);
	MojObject result;
	resultArray.at(0, result);
	MojObject mailAccountId;
	err = result.getRequired("id", mailAccountId);
	ErrorToException(err);
	err = m_payload.put("mailAccountId", mailAccountId);
	ErrorToException(err);

	MojObject accountId;
	err = m_payload.getRequired("accountId", accountId);
	ErrorToException(err);

	ClientPtr client = m_dispatcher.GetOrCreateClient(accountId);
	client->SendRequest(m_smtpAccountCreatedSlot, "com.palm.smtp", "accountCreated", m_payload);

	return MojErrNone;
}
MojErr AccountFinderCommand::GetPopAccountResponse(MojObject& response, MojErr err)
{
	CommandTraceFunction();

	try {
		// check database result first
		ErrorToException(err);

		MojObject results;
		err = response.getRequired(_T("results"), results);
		ErrorToException(err);

		if (results.size() > 0) {
			MojObject transportObj;
			if (results.at(0, transportObj)) {
				PopAccountAdapter::GetPopAccount(m_accountObj, transportObj, *(m_account.get()));
			}
		}

		MojLogInfo(m_log, "Setting account to pop client");
		m_client.SetAccount(m_account);

		Complete();
	} catch (const std::exception& ex) {
		Failure(ex);
	} catch (...) {
		Failure(MailException("unknown exception", __FILE__, __LINE__));
	}

	return MojErrNone;
}
MojErr InsertEmailsCommand::ReserverEmailIdsResponse(MojObject& response, MojErr err)
{
	try
	{
		ErrorToException(err);

		MojLogDebug(m_log, "Got reserver ids response: %s", AsJsonString(response).c_str());
		MojObject idArray;
		err = response.getRequired("ids", idArray);
		ErrorToException(err);

		for (int ndx = 0; ndx < (int)m_emails->size(); ndx++) {
			MojObject id;
			idArray.at(ndx, id);

			PopEmail::PopEmailPtr emailPtr = m_emails->at(ndx);
			MojLogDebug(m_log, "Assigning id '%s' to email '%s'", AsJsonString(id).c_str(), emailPtr->GetServerUID().c_str());
			emailPtr->SetId(id);
		}

		SaveEmails();
	}
	catch (const std::exception& e) {
		MojLogError(m_log, "Exception in reserving email ID: '%s'", e.what());
		Failure(e);
	} catch (...) {
		MojLogError(m_log, "Unknown exception in reserving email ID");
		Failure(MailException("Unknown exception in reserving email ID", __FILE__, __LINE__));
		
	}

	return MojErrNone;
}
Esempio n. 4
0
MojErr MojDbIndexTest::assertCanAnswer(const MojChar* propsJson, const MojChar* queryJson,
		bool result, bool indexIncludeDeleted)
{
	MojObject propsObj;
	MojErr err = propsObj.fromJson(propsJson);
	MojTestErrCheck(err);
	MojObject queryObj;
	err = queryObj.fromJson(queryJson);
	MojTestErrCheck(err);

	MojDbIndex index(NULL, NULL);
	MojObject prop;
	MojSize i = 0;
	for (;;) {
		if(propsObj.at(i++, prop)) {
			err = index.addProp(prop);
			MojTestErrCheck(err);
		} else {
			break;
		}
	}
	index.incDel(indexIncludeDeleted);
	MojRefCountedPtr<MojDbStorageIndex> storageIndex(new TestIndex(false));
	MojAllocCheck(storageIndex.get());
	MojDbReq req;
	err = index.open(storageIndex.get(), (MojInt64) 0, req);
	MojTestErrCheck(err);

	MojDbQuery query;
	err = query.fromObject(queryObj);
	MojTestErrCheck(err);
	MojTestAssert(index.canAnswer(query) == result);

	return MojErrNone;
}
Esempio n. 5
0
MojErr MojDbQuery::addClauses(WhereMap& map, const MojObject& array)
{
	MojObject clause;
	MojSize i = 0;
	while (array.at(i++, clause)) {
		MojString prop;
		MojErr err = clause.getRequired(PropKey, prop);
		MojErrCheck(err);
		MojString opStr;
		err = clause.getRequired(OpKey, opStr);
		MojErrCheck(err);
		CompOp op = OpNone;
		err = stringToOp(opStr, op);
		MojErrCheck(err);
		MojObject val;
		err = clause.getRequired(ValKey, val);
		MojErrCheck(err);
		MojDbCollationStrength coll = MojDbCollationInvalid;
		MojString collateStr;
		bool found = false;
		err = clause.get(CollateKey, collateStr, found);
		MojErrCheck(err);
		if (found) {
			err = MojDbUtils::collationFromString(collateStr, coll);
			MojErrCheck(err);
		}
		err = addClause(map, prop, op, val, coll);
		MojErrCheck(err);
	}
	return MojErrNone;
}
Esempio n. 6
0
MojErr MojDbPerfUpdateTest::updateObjsViaPut(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numInsertForPut, createFn, objs);
	MojTestErrCheck(err);

	MojObject midObj;
	bool found = objs.at(numInsertForPut/2, midObj);
	MojTestAssert(found);

	MojTime objTime;
	err = putObj(db, midObj, objTime);
	MojTestErrCheck(err);
	MojUInt64 putTime = objTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   putting single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per put: %llu microsecs", (putTime) / (numPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Put single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numPutIterations, kindId, putTime, putTime/numPutIterations, putTime/(1*numPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime batchTime;
	MojObject::ArrayIterator beginArr;
	err = objs.arrayBegin(beginArr);
	MojErrCheck(err);
	err = batchPutObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
	putTime = batchTime.microsecs();
	MojTestErrCheck(err);
	err = MojPrintF("   putting batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch put: %llu microsecs\n", (putTime) / (numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (putTime) / (numInsertForPut/10 * numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Batch put %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchPutIterations, kindId, putTime, putTime/numBatchPutIterations, putTime/(numInsertForPut/10*numBatchPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
MojErr PopAccountUpdateCommand::GetAccountResponse(MojObject& response, MojErr err)
{
	try {
		ErrorToException(err);

		MojObject results;
		err = response.getRequired(_T("results"), results);
		ErrorToException(err);

		if (results.size() > 0 && results.at(0, m_transportObj)) {
			GetPassword();
		}
	} catch (const std::exception& ex) {
		Failure(ex);
	} catch (...) {
		Failure(MailException("unknown exception", __FILE__, __LINE__));
	}

	return MojErrNone;
}
Esempio n. 8
0
MojErr MojDbIndexTest::assertContains(TestIndex& ti, MojObject id, const MojChar* json)
{
	MojObject array;
	MojErr err = array.fromJson(json);
	MojTestErrCheck(err);
	MojObjectWriter(writer);
	MojObject val;
	MojSize idx = 0;
	while (array.at(idx++, val)) {
		err = val.visit(writer);
		MojTestErrCheck(err);
	}
	err = id.visit(writer);
	MojTestErrCheck(err);
	MojDbKey key;
	err = key.assign(writer.buf());
	MojTestErrCheck(err);
	err = assertContains(ti, id, key);
	MojTestErrCheck(err);

	return MojErrNone;
}
Esempio n. 9
0
MojErr SaveEmailCommand::PutDone(MojObject &response, MojErr err)
{
	try {
		ResponseToException(response, err);

		MojObject results;
		err = response.getRequired("results", results);
		ErrorToException(err);

		MojObject put;
		results.at(0, put);

		MojObject emailId;
		err = put.getRequired("id", emailId);
		ErrorToException(err);

		// create response that contains emailId
		MojObject response;
		
		err = response.putBool(MojServiceMessage::ReturnValueKey, true);
		ErrorToException(err);
		        
		err = response.put(DatabaseAdapter::ID, emailId);
		ErrorToException(err);

		err = m_message->reply(response);
		ErrorToException(err);

		m_client.CommandComplete(this);
	} catch(const std::exception& e) {
		Error(e);
	} catch(...) {
		Error( MailException("unknown", __FILE__, __LINE__) );
	}

	return MojErrNone;
}
Esempio n. 10
0
MojErr MojDbIndex::fromObject(const MojObject& obj, const MojString& locale) 
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	// check name
	MojString name;
	MojErr err = obj.getRequired(NameKey, name);
	MojErrCheck(err);
	err = validateName(name);
	MojErrCheck(err);
	m_name = name;
	m_locale = locale;
    if(m_locale == _T("en_CN"))
       m_locale = locale;

	// get deleted flag
	bool includeDel = false;
	if (obj.get(IncludeDeletedKey, includeDel)) {
		incDel(includeDel);
	}
	// add props
	MojObject props;
	err = obj.getRequired(PropsKey, props);
	MojErrCheck(err);
	MojObject propObj;
	MojSize j = 0;
	while (props.at(j++, propObj)) {
		err = addProp(propObj);
		MojErrCheck(err);
	}
	if (m_props.empty()) {
		MojErrThrowMsg(MojErrDbInvalidIndex, _T("db: no properties specified in index '%s'"), name.data());
	}
	m_obj = obj;

	return MojErrNone;
}
/*
 * Send one IMMessage that was in the outbox. See java code in TransportCallbackThread.sendImHelper()
 * Change the message status from pending to either successful or failed in the DB when done
 * Set timestamp on the message and save it.
 *
 * errors returned up to OutgoingIMHandler
 *
 *  send payload format:
 *  im.libpurple.palm	//sendMessage	string=“{"serviceName":"gmail","usernameTo":"*****@*****.**","messageText":"Test send from phone","username":"******"}”
 *  luna://im.libpurple.palm/sendMessage '{"serviceName":"aol","usernameTo":"palm","messageText":"test send IM","username":"******"}'
 *
 * @param imMsg - imMessage that was read out of the DB with status pending and folder set to outbox
 */
MojErr SendOneMessageHandler::doSend(const MojObject imMsg) {

	MojErr err = MojErrNone;

	// body
	// text should be saved unescaped in the DB
	bool found = false;
	err = imMsg.get(MOJDB_MSG_TEXT, m_messageText, found);
	MojErrCheck(err);

	// userNameTo - use "to" address
	MojObject addrArray; // array
	found = imMsg.get(MOJDB_TO, addrArray);

	// now read the address out of the object
	MojObject toAddrObject;
	if (found) {
		found = addrArray.at(0, toAddrObject);
		err = toAddrObject.get(MOJDB_ADDRESS, m_usernameTo, found);
		MojErrCheck(err);
	}

	// user = "******" address
	MojObject fromAddrObject;
	found = imMsg.get(MOJDB_FROM, fromAddrObject);
	if (found) {
		err = fromAddrObject.get(MOJDB_ADDRESS, m_username, found);
		MojErrCheck(err);
	}

	// serviceName
	err = imMsg.get(MOJDB_SERVICENAME, m_serviceName, found);
	MojErrCheck(err);

	// get the id so we can update the status in  the DB after sending
	err = imMsg.getRequired("_id", m_currentMsgdbId);
	MojErrCheck(err);

	// need to search buddy list to see if this user is on it.
	// first we have to figure out the accountId - query ImLoginState

	// construct our where clause - find by username and servicename
	MojDbQuery query;
	query.where("serviceName", MojDbQuery::OpEq, m_serviceName);
	query.where("username", MojDbQuery::OpEq, m_username);
	query.from(IM_LOGINSTATE_KIND);

	// call del
	// virtual MojErr del(Signal::SlotRef handler, const MojDbQuery& query,
	//					   MojUInt32 flags = MojDb::FlagNone);
	err = m_dbClient.find(this->m_findAccountIdSlot, query);
	if (err) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("doSend: dbClient.find() failed: error %d - %s"), err, error.data());
		// tell the outgoing Command handler we are done
		failMessage(ERROR_SEND_GENERIC_ERROR);
	}

	return MojErrNone;
}
MojErr SmtpSendMailCommand::GetEmailResponse(MojObject& response, MojErr err)
{
	try {
		ResponseToException(response, err);

		MojString json;
		response.toJson(json);
		MojLogInfo(m_log, "got Email response");
		MojLogDebug(m_log, "Response: %s", json.data());

		// check the database result first
		ErrorToException(err);

		MojObject results;
		err = response.getRequired(_T("results"), results);
		ErrorToException(err);
		
		if(results.size() == 0) {
			throw MailException("email not found", __FILE__, __LINE__);
		}
		
		// There should only be one email for a given id
		assert(results.size() == 1);

		MojObject emailObj;
		bool hasObject = results.at(0, emailObj);
		if(!hasObject) {
			throw MailException("error getting email from results", __FILE__, __LINE__);
		}

		EmailAdapter::ParseDatabaseObject(emailObj, m_email);
		
		m_toAddress.clear();
		
		if (m_email.GetTo()) {
			for (EmailAddressList::iterator i = m_email.GetTo()->begin();
				i != m_email.GetTo()->end();
				i++)
				m_toAddress.push_back((*i)->GetAddress());
		}
		if (m_email.GetCc()) {
			for (EmailAddressList::iterator i = m_email.GetCc()->begin();
				i != m_email.GetCc()->end();
				i++)
				m_toAddress.push_back((*i)->GetAddress());
		}
		if (m_email.GetBcc()) {
			for (EmailAddressList::iterator i = m_email.GetBcc()->begin();
				i != m_email.GetBcc()->end();
				i++)
				m_toAddress.push_back((*i)->GetAddress());
		}
		
		m_toIdx = 0;

		// FIXME: Subscribe to file cache to pin cache contents
		
		CalculateEmailSize();
		
	} catch (const std::exception& e) {
		HandleException(e, __func__, __FILE__, __LINE__);
	} catch (...) {
		HandleUnknownException();
	}

	return MojErrNone;
}
Esempio n. 13
0
MojErr MojObjectTest::typeTest()
{
    MojObject obj;
    MojObject obj2;
    MojString str1;
    MojString str2;
    MojHashMap<MojObject, MojObject> map;

    // null
    MojTestAssert(obj.type() == MojObject::TypeUndefined);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    MojErr err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("null"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    MojTestAssert(obj == obj2);
    MojTestAssert(obj.compare(obj2) == 0);
    err = obj.coerce(MojObject::TypeNull);
    MojTestErrCheck(err);
    MojTestAssert(obj.type() == MojObject::TypeNull);
    err = obj.coerce(MojObject::TypeString);
    MojTestErrCheck(err);
    MojTestAssert(obj == str1);
    err = obj.coerce(MojObject::TypeBool);
    MojTestErrCheck(err);
    MojTestAssert(obj == true);
    err = obj.coerce(MojObject::TypeInt);
    MojTestErrCheck(err);
    MojTestAssert(obj == 1);
    err = obj.coerce(MojObject::TypeDecimal);
    MojTestErrCheck(err);
    MojTestAssert(obj.type() == MojObject::TypeDecimal && obj == MojDecimal(1, 0));
    err = obj.coerce(MojObject::TypeObject);
    MojTestErrCheck(err);
    MojTestAssert(obj.type() == MojObject::TypeObject);
    err = obj.coerce(MojObject::TypeArray);
    MojTestErrCheck(err);
    MojTestAssert(obj.type() == MojObject::TypeArray);

    // object
    err = obj.put(_T("hello"), 5);
    MojTestErrCheck(err);
    MojTestAssert(obj.type() == MojObject::TypeObject);
    MojTestAssert(obj.size() == 1);
    MojTestAssert(!obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("{\"hello\":5}"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    obj.clear(MojObject::TypeObject);
    MojTestAssert(obj.type() == MojObject::TypeObject);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("{}"));
    // array
    for (int i = 0; i < 1000; ++i) {
        err = obj.push(i);
        MojTestErrCheck(err);
    }
    MojTestAssert(obj.type() == MojObject::TypeArray);
    MojTestAssert(obj.size() == 1000);
    MojTestAssert(!obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    for (int i = 0; i < 1000; ++i) {
        MojTestAssert(obj.at(i, obj2));
        MojTestAssert(obj2 == i);
    }
    MojTestAssert(!obj.at(1000, obj2));
    err = obj.setAt(1001, 1001);
    MojTestErrCheck(err);
    MojTestAssert(obj.size() == 1002);
    MojTestAssert(obj.at(1000, obj2));
    MojTestAssert(obj2.type() == MojObject::TypeUndefined);
    obj.clear(MojObject::TypeArray);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("[]"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    // string
    err = str1.assign(_T("yo"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.type() == MojObject::TypeString);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str2);
    MojTestErrCheck(err);
    MojTestAssert(str1 == str2);
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    obj.clear(MojObject::TypeString);
    MojTestAssert(obj.boolValue() == false);
    err = str1.assign(_T("12345"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == 12345);
    MojTestAssert(obj.decimalValue() == MojDecimal(12345, 0));
    err = str1.assign(_T("-67890"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == -67890);
    MojTestAssert(obj.decimalValue() == MojDecimal(-67890, 0));
    err = str1.assign(_T("12345000000000"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == 12345000000000LL);
    err = str1.assign(_T("12345.6789"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == 12345);
    MojTestAssert(obj.decimalValue() == MojDecimal(12345, 678900));
    err = str1.assign(_T("1.0e3"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == 1);
    MojTestAssert(obj.decimalValue() == MojDecimal(1000, 0));
    err = str1.assign(_T("45hello"));
    MojTestErrCheck(err);
    obj = str1;
    MojTestAssert(obj.intValue() == 45);
    MojTestAssert(obj.decimalValue() == MojDecimal(45, 0));
    // bool
    obj = true;
    MojTestAssert(obj.type() == MojObject::TypeBool);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == 1);
    MojTestAssert(obj.decimalValue() == MojDecimal(1, 0));
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("true"));
    obj.clear(MojObject::TypeBool);
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("false"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    // MojDecimal
    obj = MojDecimal(3, 140000);
    MojTestAssert(obj.type() == MojObject::TypeDecimal);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == 3);
    MojTestAssert(obj.decimalValue() == MojDecimal(3.14));
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("3.14"));
    obj.clear(MojObject::TypeDecimal);
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("0.0"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));
    // MojDecimal
    obj = -987654321;
    MojTestAssert(obj.type() == MojObject::TypeInt);
    MojTestAssert(obj.size() == 0);
    MojTestAssert(obj.empty());
    MojTestAssert(obj.boolValue() == true);
    MojTestAssert(obj.intValue() == -987654321);
    MojTestAssert(obj.decimalValue() == MojDecimal(-987654321, 0));
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("-987654321"));
    obj.clear(MojObject::TypeInt);
    MojTestAssert(obj.boolValue() == false);
    MojTestAssert(obj.intValue() == 0);
    MojTestAssert(obj.decimalValue() == MojDecimal());
    err = obj.stringValue(str1);
    MojTestErrCheck(err);
    MojTestAssert(str1 == _T("0"));
    err = map.put(obj, obj);
    MojTestErrCheck(err);
    MojTestAssert(map.contains(obj));

    return MojErrNone;
}
Esempio n. 14
0
MojErr MojDbPerfUpdateTest::updateObjsViaMerge(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numInsertForPut, createFn, objs);
	MojTestErrCheck(err);

	MojObject midObj;
	bool found = objs.at(numInsertForPut/2, midObj);
	MojTestAssert(found);

	MojTime objTime;
	err = mergeObj(db, midObj, objTime);
	MojTestErrCheck(err);
	MojUInt64 mergeTime = objTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   merging single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per merge: %llu microsecs", (mergeTime) / (numMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Merge single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numMergeIterations, kindId, mergeTime, mergeTime/numMergeIterations, mergeTime/(1*numMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime batchTime;
	MojObject::ArrayIterator beginArr;
	err = objs.arrayBegin(beginArr);
	MojErrCheck(err);
	err = batchMergeObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
	MojTestErrCheck(err);
	mergeTime = batchTime.microsecs();
	err = MojPrintF("   merging batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (mergeTime) / (numInsertForPut/10 * numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Batch merge %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(numInsertForPut/10*numBatchMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime mergeQueryTime;
	MojTestErrCheck(err);
	MojDbQuery query;
	err = query.from(kindId);
	MojTestErrCheck(err);
	query.limit(numInsertForPut/5);
	query.desc(true);

	MojObject queryObj;
	err = query.toObject(queryObj);
	MojTestErrCheck(err);
	MojString queryStr;
	err = queryObj.stringValue(queryStr);
	MojTestErrCheck(err);

	MojObject props;
	err = props.putString(_T("newKey"), _T("here's a new value"));
	MojTestErrCheck(err);
	MojUInt32 count;
	err = queryMergeObj(db, query, props, count, mergeQueryTime);
	MojTestErrCheck(err);
	mergeTime = mergeQueryTime.microsecs();
	err = MojPrintF("   merging with query - %d objects - of kind %s %llu times took: %llu microsecs\n", count, kindId, numBatchMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (mergeTime) / (count * numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Merge with query %s,,,,,\nMerge with query - %d objects - %llu times,%s,%llu,%llu,%llu,\n", queryStr.data(), count, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(count*numBatchMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Esempio n. 15
0
MojErr MojDbQuery::fromObject(const MojObject& obj)
{
	// TODO: validate against query schema

	bool found;
	MojErr err;
	MojObject array;
	MojString str;

	// distinct
	found = false;
	err = obj.get(DistinctKey, str, found);
	MojErrCheck(err);
	if (found) {
		err = distinct(str);
		MojErrCheck(err);
		// if "distinct" is set, force "distinct" column into "select".
		err = select(str);
		MojErrCheck(err);
		// order
		err = order(str);
		MojErrCheck(err);
	} else {
		// select
		if (obj.get(SelectKey, array)) {
			if(array.empty()) {
				MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: select clause but no selected properties"));
			}
			MojObject prop;
			MojSize i = 0;
			while (array.at(i++, prop)) {
				MojErr err = prop.stringValue(str);
				MojErrCheck(err);
				err = select(str);
				MojErrCheck(err);
			}
		}
		// order
		found = false;
		err = obj.get(OrderByKey, str, found);
		MojErrCheck(err);
		if (found) {
			err = order(str);
			MojErrCheck(err);
		}
	}
	// from
	err = obj.getRequired(FromKey, str);
	MojErrCheck(err);
	err = from(str);
	MojErrCheck(err);
	// where
	if (obj.get(WhereKey, array)) {
		err = addClauses(m_whereClauses, array);
		MojErrCheck(err);
	}
	// filter
	if (obj.get(FilterKey, array)) {
		err = addClauses(m_filterClauses, array);
		MojErrCheck(err);
	}
	// desc
	bool descVal;
	if (obj.get(DescKey, descVal)) {
		desc(descVal);
	}
	// limit
	MojInt64 lim;
	if (obj.get(LimitKey, lim)) {
		if (lim < 0)
			MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: negative query limit"));
	} else {
		lim = LimitDefault;
	}
	limit((MojUInt32) lim);
	// page
	MojObject pageObj;
	if (obj.get(PageKey, pageObj)) {
		Page pagec;
		err = pagec.fromObject(pageObj);
		MojErrCheck(err);
		page(pagec);
	}
	bool incDel = false;
	if (obj.get(IncludeDeletedKey, incDel) && incDel) {
		err = includeDeleted();
		MojErrCheck(err);
	}
	return MojErrNone;
}