本文整理汇总了C++中MojObject::putString方法的典型用法代码示例。如果您正苦于以下问题:C++ MojObject::putString方法的具体用法?C++ MojObject::putString怎么用?C++ MojObject::putString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojObject
的用法示例。
在下文中一共展示了MojObject::putString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetPopAccountFromPayload
void PopAccountAdapter::GetPopAccountFromPayload(MojLogger& log, const MojObject& payload, MojObject& popAccount)
{
MojErr err = popAccount.putString(KIND, POP_ACCOUNT_KIND);
ErrorToException(err);
MojObject accountId;
err = payload.getRequired(ACCOUNT_ID, accountId);
ErrorToException(err);
err = popAccount.put(ACCOUNT_ID, accountId);
ErrorToException(err);
MojObject config;
err = payload.getRequired(CONFIG, config);
ErrorToException(err);
MojObject hostname;
err = config.getRequired(HOST_NAME, hostname);
ErrorToException(err);
err = popAccount.put(HOST_NAME, hostname);
ErrorToException(err);
MojObject port;
err = config.getRequired(PORT, port);
ErrorToException(err);
err = popAccount.put(PORT, port);
ErrorToException(err);
MojObject encryption;
err = config.getRequired(ENCRYPTION, encryption);
ErrorToException(err);
err = popAccount.put(ENCRYPTION, encryption);
ErrorToException(err);
MojObject username;
err = config.getRequired(USERNAME, username);
ErrorToException(err);
err = popAccount.put(USERNAME, username);
ErrorToException(err);
// Set 'deleteFromServer' flag
bool deleteFromServer = true;
if (!config.get(DELETE_FROM_SERVER, deleteFromServer)) {
// default value is true if this field doesn't exist
deleteFromServer = true;
}
err = popAccount.putBool(DELETE_FROM_SERVER, deleteFromServer);
ErrorToException(err);
// Set 'deleteOnDevice' flag
bool deleteOnDevice = false;
if (!config.get(DELETE_ON_DEVICE, deleteOnDevice)) {
// defaul value is false if this field doesn't exist
deleteOnDevice = false;
}
err = popAccount.putBool(DELETE_ON_DEVICE, deleteOnDevice);
ErrorToException(err);
// Set sync window
MojInt64 syncWindow;
if (!config.get(EmailAccountAdapter::SYNC_WINDOW_DAYS, syncWindow)) {
// set default value if this field doesn't exist
syncWindow = PopAccount::DEFAULT_SYNC_WINDOW;
}
err = popAccount.putInt(EmailAccountAdapter::SYNC_WINDOW_DAYS, syncWindow);
ErrorToException(err);
// Set sync frequency
MojInt64 syncFreq;
if (!config.get(SYNC_FREQUENCY_MINS, syncFreq)) {
syncFreq = PopAccount::DEFAULT_SYNC_FREQUENCY_MINS;
}
err = popAccount.putInt(SYNC_FREQUENCY_MINS, syncFreq);
ErrorToException(err);
}
示例2: UpdateSyncState
void SyncStateUpdater::UpdateSyncState(MojSignal<>::SlotRef slot, const SyncState& syncState, bool clearSyncState)
{
m_doneSignal.connect(slot);
MojErr err;
MojObject batchPayload;
MojObject batchOperations;
// Delete old sync state
MojObject delPayload;
MojDbQuery query;
err = query.from(SyncStateAdapter::SYNC_STATE_KIND);
ErrorToException(err);
MojString capabilityProvider;
capabilityProvider.assign(m_capabilityProvider.c_str());
err = query.where(SyncStateAdapter::CAPABILITY_PROVIDER, MojDbQuery::OpEq, capabilityProvider);
ErrorToException(err);
err = query.where(SyncStateAdapter::ACCOUNT_ID, MojDbQuery::OpEq, syncState.GetAccountId());
ErrorToException(err);
err = query.where(SyncStateAdapter::COLLECTION_ID, MojDbQuery::OpEq, syncState.GetCollectionId());
ErrorToException(err);
MojObject queryObj;
err = query.toObject(queryObj);
ErrorToException(err);
err = delPayload.put("query", queryObj);
ErrorToException(err);
MojObject delOperation;
err = delOperation.putString("method", "del");
ErrorToException(err);
err = delOperation.put("params", delPayload);
ErrorToException(err);
err = batchOperations.push(delOperation);
ErrorToException(err);
if(!clearSyncState) { // Store new sync state
MojObject putPayload;
MojObject syncStateObj;
SyncStateAdapter::SerializeToDatabaseObject(syncState, syncStateObj, m_capabilityProvider.c_str(), m_busAddress.c_str());
MojObject objects;
err = objects.push(syncStateObj);
ErrorToException(err);
err = putPayload.put("objects", objects);
ErrorToException(err);
MojObject putOperation;
err = putOperation.putString("method", "put");
ErrorToException(err);
err = putOperation.put("params", putPayload);
ErrorToException(err);
err = batchOperations.push(putOperation);
ErrorToException(err);
}
err = batchPayload.put("operations", batchOperations);
ErrorToException(err);
// Note: batch operations are not atomic, this is just for convenience and performance
m_busClient.SendRequest(m_updateSlot, "com.palm.tempdb", "batch", batchPayload);
}
示例3: ActivityLoadResults
//.........这里部分代码省略.........
continue;
}
}
try {
m_am->RegisterActivityName(act);
} catch (...) {
LOG_ERROR(MSGID_ACTIVITY_NAME_REG_FAIL, 3, PMLOGKFV("Activity","%llu",act->GetId()),
PMLOGKS("Creator_name",act->GetCreator().GetString().c_str()),
PMLOGKS("Register_name",act->GetName().c_str()), "");
/* Another Activity is already registered. Determine which
* is newer, and kill the older one. */
boost::shared_ptr<Activity> old = m_am->GetActivity(
act->GetName(), act->GetCreator());
boost::shared_ptr<MojoDBPersistToken> oldPt =
boost::dynamic_pointer_cast<MojoDBPersistToken,
PersistToken>(old->GetPersistToken());
if (pt->GetRev() > oldPt->GetRev()) {
LOG_WARNING(MSGID_ACTIVITY_REPLACED, 4, PMLOGKFV("Activity","%llu",act->GetId()),
PMLOGKFV("revision","%llu",(unsigned long long)pt->GetRev()),
PMLOGKFV("old_Activity","%llu",old->GetId()),
PMLOGKFV("old_revision","%llu",(unsigned long long)oldPt->GetRev()), "");
m_oldTokens.push_back(oldPt);
m_am->UnregisterActivityName(old);
m_am->ReleaseActivity(old);
m_am->RegisterActivityName(act);
} else {
LOG_WARNING(MSGID_ACTIVITY_NOT_REPLACED, 4, PMLOGKFV("Activity","%llu",act->GetId()),
PMLOGKFV("revision","%llu",(unsigned long long)pt->GetRev()),
PMLOGKFV("old_Activity","%llu",old->GetId()),
PMLOGKFV("old_revision","%llu",(unsigned long long)oldPt->GetRev()), "");
m_oldTokens.push_back(pt);
m_am->ReleaseActivity(act);
continue;
}
}
LOG_DEBUG("[Activity %llu] (\"%s\"): _id %s, rev %llu loaded",
act->GetId(), act->GetName().c_str(), id.data(),
(unsigned long long)rev);
/* Request Activity be scheduled. It won't transition to running
* until after the MojoDB load finishes (and the Activity Manager
* moves to the ready() and start()ed states). */
m_am->StartActivity(act);
}
}
MojString page;
err2 = response.get(_T("page"), page, found);
if (err2) {
LOG_ERROR(MSGID_GET_PAGE_FAIL, 0, "Error getting page parameter in MojoDB query response");
return;
}
if (found) {
LOG_DEBUG("Preparing to request next page (\"%s\") of Activities",
page.data());
MojObject query;
query.putString(_T("from"), ActivityKind);
query.putString(_T("page"), page);
MojObject params;
params.put(_T("query"), query);
m_call = boost::make_shared<MojoWeakPtrCall<MojoDBProxy> >(
boost::dynamic_pointer_cast<MojoDBProxy, PersistProxy>
(shared_from_this()),
&MojoDBProxy::ActivityLoadResults,
m_service, "palm://com.palm.db/find", params);
m_call->Call();
} else {
LOG_DEBUG("All Activities successfully loaded from MojoDB");
if (!m_oldTokens.empty()) {
LOG_DEBUG("Beginning purge of old Activities from database");
PreparePurgeCall();
m_call->Call();
} else {
#ifdef ACTIVITYMANAGER_CALL_CONFIGURATOR
PrepareConfiguratorCall();
m_call->Call();
#else
m_call.reset();
m_am->Enable(ActivityManager::CONFIGURATION_LOADED);
#endif
}
m_app->ready();
}
}
示例4: LoginSuccess
void SmtpValidator::LoginSuccess()
{
if (m_timeoutId) {
g_source_remove(m_timeoutId);
m_timeoutId = 0;
}
//MojLogInfo(m_log, "SmtpValidator %p LoginSuccess, was trying to connect to %s:%d", this, m_account->GetHostname().c_str(), m_account->GetPort());
MojLogInfo(m_log, "SmtpValidator %p LoginSuccess", this);
try {
MojObject reply;
MojErr err;
err = reply.putBool(MojServiceMessage::ReturnValueKey, true);
ErrorToException(err);
if(m_account->GetEncryption() == SmtpAccount::Encrypt_TLSIfAvailable) {
// Update protocol settings
MojObject config;
if(m_protocolSettings.get(SmtpAccountAdapter::CONFIG, config) && !config.null()) {
err = config.putString(SmtpAccountAdapter::ENCRYPTION,
m_tlsSupported ? SmtpAccountAdapter::TLS : SmtpAccountAdapter::NO_SSL);
ErrorToException(err);
err = m_protocolSettings.put(SmtpAccountAdapter::CONFIG, config);
ErrorToException(err);
}
}
err = reply.put("protocolSettings", m_protocolSettings);
ErrorToException(err);
// create credentials object
MojObject password;
err = password.putString("password", m_account->GetPassword().c_str());
ErrorToException(err);
MojObject smtp;
err = smtp.put("smtp", password);
ErrorToException(err);
err = reply.put("credentials", smtp);
ErrorToException(err);
if (!m_replied) {
// if we already replied due to a timeout, don't reply again.
err = m_msg->reply(reply);
ErrorToException(err);
m_replied = true;
}
} catch (const exception& e) {
if (!m_replied) {
// if we already replied due to a timeout, don't reply again.
m_msg->replyError(MojErrInternal);
m_replied = true;
}
}
RunState(State_SendQuitCommand);
return;
}
示例5: getProtocolOptions
MojObject getProtocolOptions(MojString prpl)
{
MojObject result;
PurplePluginProtocolInfo* info = getProtocolInfo(prpl.data());
for(GList* l = info->protocol_options; l != NULL; l = l->next)
{
PurpleAccountOption* option = (PurpleAccountOption*)l->data;
MojObject node;
MojObject choices;
node.putString("text", purple_account_option_get_text(option));
switch(purple_account_option_get_type(option))
{
case PURPLE_PREF_BOOLEAN:
node.putString("type", "bool");
node.putBool("default_value",
purple_account_option_get_default_bool(option)
);
break;
case PURPLE_PREF_INT:
node.putString("type", "int");
node.putInt("default_value",
purple_account_option_get_default_int(option)
);
break;
case PURPLE_PREF_STRING:
node.putString("type", "string");
{
const char* def
= purple_account_option_get_default_string(option);
node.putString("default_value", def ? def : "");
}
break;
case PURPLE_PREF_STRING_LIST:
node.putString("type", "list");
{
MojObject choices;
for (GList* list = purple_account_option_get_list(option);
list != NULL; list = list->next)
{
PurpleKeyValuePair* kvp = (PurpleKeyValuePair*)list->data;
// XXX: Dangerous!
if (kvp->key && kvp->value)
choices.putString((const char*)kvp->value,
(const char*)kvp->key);
}
node.put("choices", choices);
const char* def
= purple_account_option_get_default_list_value(option);
node.putString("default_value", def ? def : "");
}
break;
default:
continue;
};
result.put(purple_account_option_get_setting(option), node);
}
return result;
}
示例6: checkPermissions
MojErr MojDbPermissionTest::checkPermissions(MojDb& db)
{
MojDbReq reqOwner(false);
MojErr err = reqOwner.domain(_T("com.foo"));
MojTestErrCheck(err);
MojDbReq reqFooBar(false);
err = reqFooBar.domain(_T("com.foo.bar"));
MojTestErrCheck(err);
MojDbReq reqFooBarBad(false);
err = reqFooBarBad.domain(_T("com.foobar"));
MojTestErrCheck(err);
MojDbReq reqGranted(false);
err = reqGranted.domain("com.granted");
MojTestErrCheck(err);
MojDbReq reqEmpty(false);
MojDbReq reqBad(false);
err = reqBad.domain("com.bad");
MojTestErrCheck(err);
MojObject objNoId;
err = objNoId.putString(MojDb::KindKey, _T("PermissionTest:1"));
MojTestErrCheck(err);
MojObject obj2NoId;
err = obj2NoId.putString(MojDb::KindKey, _T("PermissionTest2:1"));
MojTestErrCheck(err);
// put new obj
MojObject obj1 = objNoId;
err = db.put(obj1, MojDb::FlagNone, reqOwner);
MojTestErrCheck(err);
MojObject obj2 = objNoId;
err = db.put(obj2, MojDb::FlagNone, reqGranted);
MojTestErrCheck(err);
MojObject obj3 = objNoId;
err = db.put(obj3, MojDb::FlagNone, reqBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
obj3 = objNoId;
err = db.put(obj3, MojDb::FlagNone, reqFooBarBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
obj3 = objNoId;
err = db.put(obj3, MojDb::FlagNone, reqFooBar);
MojTestErrCheck(err);
err = db.put(obj2NoId, MojDb::FlagNone, reqEmpty);
MojTestErrCheck(err);
// put existing obj
err = obj1.put(_T("foo"), 1);
MojTestErrCheck(err);
err = db.put(obj1, MojDb::FlagNone, reqOwner);
MojTestErrCheck(err);
err = obj2.put(_T("foo"), 2);
MojTestErrCheck(err);
err = db.put(obj2, MojDb::FlagNone, reqGranted);
MojTestErrCheck(err);
err = obj2.put(_T("foo"), 3);
MojTestErrCheck(err);
err = db.put(obj2, MojDb::FlagNone, reqBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// find
MojDbQuery query;
err = query.from(_T("PermissionTest:1"));
MojTestErrCheck(err);
MojDbCursor cursor;
err = db.find(query, cursor, reqOwner);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = db.find(query, cursor, reqGranted);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = db.find(query, cursor, reqBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
err = cursor.close();
MojTestErrCheck(err);
// get
MojObject id1;
MojTestAssert(obj1.get(MojDb::IdKey, id1));
bool found = false;
MojObject gotten;
err = db.get(id1, gotten, found, reqOwner);
MojTestErrCheck(err);
err = db.get(id1, gotten, found, reqGranted);
MojTestErrCheck(err);
err = db.get(id1, gotten, found, reqBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// del by id
err = db.del(id1, found, MojDb::FlagNone, reqBad);
MojTestErrExpected(err, MojErrDbPermissionDenied);
MojTestAssert(!found);
err = db.del(id1, found, MojDb::FlagNone, reqOwner);
MojTestErrCheck(err);
MojTestAssert(found);
MojObject id2;
MojTestAssert(obj2.get(MojDb::IdKey, id2));
err = db.del(id2, found, MojDb::FlagNone, reqGranted);
MojTestErrCheck(err);
MojTestAssert(found);
//.........这里部分代码省略.........
示例7: run
MojErr MojDbTxnTest::run()
{
MojErr err;
MojDb db;
err = MojDbTestEnv::run(MojDbTestDir);
MojTestErrCheck(err);
// open
err = db.open(MojDbTestDir, env());
MojTestErrCheck(err);
// add type
MojObject obj;
err = obj.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
for (int i = 0; i < 100; ++i) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, _T("Test:1"));
MojTestErrCheck(err);
err = obj.put(_T("foo"), (i + 25) % 100);
MojTestErrCheck(err);
err = obj.put(_T("bar"), i % 3);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
// db: x0 = (25, 0), (26, 1), (27, 2), (28, 0) .. x74 = (99,2), x75 = (0,0) .. x99 = (24,0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("foo"), MojDbQuery::OpLessThan, 50);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -1);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// db: x0 = (25, -1) .. x24 = (49,-1), x25 = (50,1)i .. x74 = (99,2), x75 = (0,-1) .. x99 = (24, -1)
// test visibility with update
{
MojDbReq req;
// start transaction
req.begin(&db, false);
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -1);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
// txn: x0 = (25, -2) .. x24 = (49,-2), x25 = (50,1) .. x74 = (99,2), x75 = (0,-2) .. x99 = (24, -2)
// visible within transaction
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// With BerkeleyDB parallel transaction is locked
// invisible outside of transaction
if (engineName().compare(_T("leveldb")) == 0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
//.........这里部分代码省略.........
示例8: SerializeToDatabaseObject
// NOTE: This should currently only be used for new emails
void EmailAdapter::SerializeToDatabaseObject(const Email& email, MojObject& obj)
{
MojErr err;
// Set the object kind
err = obj.putString(KIND, Kind::EMAIL);
ErrorToException(err);
// FIXME object ID
// Set the folder ID
err = obj.put(FOLDER_ID, email.GetFolderId());
ErrorToException(err);
// Set flags
MojObject flags;
SerializeFlags(email, flags);
err = obj.put(FLAGS, flags);
ErrorToException(err);
// The following fields only exist for a new e-mail to be added to the DB
// If the e-mail object already exists in the DB, we shouldn't overwrite these fields
// FIXME: Except for drafts. Maybe this logic should be moved elsewhere?
if (true /*!obj.Exists()*/) {
// Subject
err = obj.putString(SUBJECT, email.GetSubject().c_str());
ErrorToException(err);
// Preview text
err = obj.putString(SUMMARY, email.GetPreviewText().c_str());
ErrorToException(err);
// Timestamp in UTC milliseconds
err = obj.put(TIMESTAMP, email.GetDateReceived());
ErrorToException(err);
// From address
MojObject from;
if(email.GetFrom().get()) // may not have a from address
SerializeAddress(Address::Type::FROM, email.GetFrom(), from);
err = obj.put(FROM, from);
ErrorToException(err);
// Reply-To address
MojObject replyTo;
if(email.GetReplyTo().get()) { // may not have a reply-to address
SerializeAddress(Address::Type::REPLY_TO, email.GetReplyTo(), replyTo);
err = obj.put(REPLY_TO, replyTo);
ErrorToException(err);
}
// Recipients
MojObject recipients;
SerializeRecipients(Address::Type::TO, email.GetTo(), recipients);
SerializeRecipients(Address::Type::CC, email.GetCc(), recipients);
SerializeRecipients(Address::Type::BCC, email.GetBcc(), recipients);
err = obj.put(RECIPIENTS, recipients);
ErrorToException(err);
// Parts
MojObject parts;
SerializeParts(email.GetPartList(), parts);
err = obj.put(PARTS, parts);
ErrorToException(err);
// MessageId and InReplyTo
DatabaseAdapter::PutOptionalString(obj, MESSAGE_ID, email.GetMessageId());
DatabaseAdapter::PutOptionalString(obj, IN_REPLY_TO, email.GetInReplyTo());
// Priority
Email::Priority priority = email.GetPriority();
if(priority == Email::Priority_High) {
err = obj.putString(PRIORITY, PRIORITY_HIGH);
ErrorToException(err);
} else if(priority == Email::Priority_Low) {
err = obj.putString(PRIORITY, PRIORITY_LOW);
ErrorToException(err);
}
}
}
示例9: IMSendCmd
/**
* Send IM Command handler.
* callback Used by Activity Manager - gets fired from a DB watch
*
* parms from activity manager:
* {"$activity":{"activityId":1,"trigger":{"fired":true,"returnValue":true}}}
*/
MojErr IMServiceHandler::IMSendCmd(MojServiceMessage* serviceMsg, const MojObject parms)
{
MojLogInfo(IMServiceApp::s_log, _T("IMSendCmd request received."));
// log the parameters
logMojObjectJsonString(_T("IMSendCmd parameters: %s"), parms);
// if we were called by the activity manager we will get an activity id here to adopt
// get the $activity object
MojObject activityObj;
MojInt64 activityId = 0;
bool found = parms.get(_T("$activity"), activityObj);
if (found)
found = activityObj.get(_T("activityId"), activityId);
if (!found) {
MojString msg;
msg.format(_T("IMSendCmd failed: parameter has no activityId"));
MojLogError(IMServiceApp::s_log, "%s", msg.data());
// send error back to caller
serviceMsg->replyError(MojErrInvalidArg, msg);
return MojErrInvalidArg;
}
// check for returnValue = false in trigger parameter
MojObject trigger;
bool retVal = false;
found = activityObj.get(_T("trigger"), trigger);
if (found)
found = trigger.get(_T("returnValue"), retVal);
if (!found || !retVal) {
MojString msg;
msg.format(_T("IMSendCmd failed: trigger does not have returnValue: true"));
MojLogError(IMServiceApp::s_log, "%s", msg.data());
// send error back to caller
serviceMsg->replyError(MojErrInvalidArg, msg);
return MojErrInvalidArg;
}
// create the outgoing command handler
// This object is ref counted and will be deleted after the slot is invoked
// Therefore we don't need to hold on to it or worry about deleting it
MojRefCountedPtr<OutgoingIMCommandHandler> handler(new OutgoingIMCommandHandler(m_service, activityId));
// query the DB for outgoing commands and send them
MojErr err = handler->start();
if (err) {
MojString error;
MojString msg;
MojErrToString(err, error);
msg.format(_T("OutgoingIMCommandHandler.start() failed: error %d - %s"), err, error.data());
MojLogError(IMServiceApp::s_log, _T("%s"), msg.data());
// send error back to caller
serviceMsg->replyError(err, msg);
return MojErrInternal;
}
// Reply to caller
MojObject reply;
reply.putString(_T("response"), _T("IMService processing command list"));
serviceMsg->replySuccess(reply);
return MojErrNone;
}
示例10: compoundTest
MojErr MojDbIndexTest::compoundTest()
{
MojDbIndex index(NULL, NULL);
MojRefCountedPtr<TestIndex> storageIndex(new TestIndex(false));
MojAllocCheck(storageIndex.get());
TestIndex& ti = *storageIndex;
MojObject prop;
MojErr err = prop.putString(MojDbIndex::NameKey, _T("foo"));
MojTestErrCheck(err);
err = index.addProp(prop);
MojTestErrCheck(err);
err = prop.putString(MojDbIndex::NameKey, _T("bar"));
MojTestErrCheck(err);
err = index.addProp(prop);
MojTestErrCheck(err);
err = prop.putString(MojDbIndex::NameKey, _T("baz"));
MojTestErrCheck(err);
err = index.addProp(prop);
MojTestErrCheck(err);
MojDbReq req;
err = index.open(storageIndex.get(), (MojInt64) 0, req);
MojTestErrCheck(err);
err = put(index, 1, _T("{\"foo\":1}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 0 && ti.m_delCount == 0 && ti.m_set.size() == 0);
err = put(index, 1, _T("{\"foo\":1,\"bar\":2}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 0 && ti.m_delCount == 0 && ti.m_set.size() == 0);
err = put(index, 1, _T("{\"foo\":1,\"baz\":2}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 0 && ti.m_delCount == 0 && ti.m_set.size() == 0);
err = put(index, 1, _T("{\"foo\":1,\"bar\":2,\"baz\":3}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 1 && ti.m_delCount == 0 && ti.m_set.size() == 1);
err = assertContains(ti, 1, _T("[1,2,3]"));
MojTestErrCheck(err);
err = put(index, 1, _T("{\"foo\":1,\"bar\":-2,\"baz\":3}"), _T("{\"foo\":1,\"bar\":2,\"baz\":3}"));
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 2 && ti.m_delCount == 1 && ti.m_set.size() == 1);
err = assertContains(ti, 1, _T("[1,-2,3]"));
MojTestErrCheck(err);
err = del(index, 1, _T("{\"foo\":1,\"bar\":-2,\"baz\":3}"));
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 2 && ti.m_delCount == 2 && ti.m_set.size() == 0);
err = put(index, 1, _T("{\"foo\":1,\"bar\":[2,-2],\"baz\":3}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 4 && ti.m_delCount == 2 && ti.m_set.size() == 2);
err = assertContains(ti, 1, _T("[1,2,3]"));
MojTestErrCheck(err);
err = assertContains(ti, 1, _T("[1,-2,3]"));
MojTestErrCheck(err);
err = del(index, 1, _T("{\"foo\":1,\"bar\":[2,-2],\"baz\":3}"));
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 4 && ti.m_delCount == 4 && ti.m_set.size() == 0);
err = put(index, 1, _T("{\"foo\":1,\"bar\":[2,2,2],\"baz\":3}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 5 && ti.m_delCount == 4 && ti.m_set.size() == 1);
err = assertContains(ti, 1, _T("[1,2,3]"));
MojTestErrCheck(err);
err = put(index, 1, _T("{\"foo\":1,\"bar\":[2,8],\"baz\":[3,4]}"), _T("{\"foo\":1,\"bar\":[2,2,2],\"baz\":3}"));
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 8 && ti.m_delCount == 4 && ti.m_set.size() == 4);
err = assertContains(ti, 1, _T("[1,2,3]"));
MojTestErrCheck(err);
err = assertContains(ti, 1, _T("[1,2,4]"));
MojTestErrCheck(err);
err = assertContains(ti, 1, _T("[1,8,3]"));
MojTestErrCheck(err);
err = assertContains(ti, 1, _T("[1,8,4]"));
MojTestErrCheck(err);
err = index.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例11: defaultValuesTest
MojErr MojDbIndexTest::defaultValuesTest()
{
MojDbIndex index(NULL, NULL);
MojRefCountedPtr<TestIndex> storageIndex(new TestIndex(false));
MojAllocCheck(storageIndex.get());
TestIndex& ti = *storageIndex;
MojObject prop;
MojErr err = prop.putString(MojDbIndex::NameKey, _T("foo"));
MojTestErrCheck(err);
err = prop.putInt(MojDbIndex::DefaultKey, 100);
MojTestErrCheck(err);
err = index.addProp(prop);
MojTestErrCheck(err);
MojDbReq req;
err = index.open(storageIndex.get(), (MojInt64) 0, req);
MojTestErrCheck(err);
err = put(index, 1, _T("{\"bar\":1}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 1 && ti.m_delCount == 0 && ti.m_set.size() == 1);
err = put(index, 1, _T("{\"foo\":5}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 2 && ti.m_delCount == 0 && ti.m_set.size() == 2);
err = put(index, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti.m_putCount == 3 && ti.m_delCount == 0 && ti.m_set.size() == 3);
err = index.close();
MojTestErrCheck(err);
MojDbIndex index2(NULL, NULL);
MojRefCountedPtr<TestIndex> storageIndex2(new TestIndex(false));
MojAllocCheck(storageIndex2.get());
TestIndex& ti2 = *storageIndex2;
MojObject prop2;
err = prop2.putString(MojDbIndex::NameKey, _T("bar"));
MojTestErrCheck(err);
err = index2.addProp(prop2);
MojTestErrCheck(err);
err = index2.open(storageIndex2.get(), (MojInt64) 0, req);
MojTestErrCheck(err);
err = put(index2, 1, _T("{\"bar\":1}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);
err = put(index2, 1, _T("{\"foo\":5}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);
err = put(index2, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);
err = index2.close();
MojTestErrCheck(err);
MojDbIndex index3(NULL, NULL);
MojRefCountedPtr<TestIndex> storageIndex3(new TestIndex(false));
MojAllocCheck(storageIndex3.get());
TestIndex& ti3 = *storageIndex3;
MojObject prop3;
err = prop3.putString(MojDbIndex::NameKey, _T("bar"));
MojTestErrCheck(err);
err = index3.addProp(prop3);
MojTestErrCheck(err);
err = prop3.putString(MojDbIndex::NameKey, _T("foo"));
MojTestErrCheck(err);
err = prop3.putInt(MojDbIndex::DefaultKey, 100);
MojTestErrCheck(err);
err = index3.addProp(prop3);
MojTestErrCheck(err);
err = index3.open(storageIndex3.get(), (MojInt64) 0, req);
MojTestErrCheck(err);
err = put(index3, 1, _T("{\"bar\":1}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
err = put(index3, 1, _T("{\"foo\":5}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
err = put(index3, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
err = put(index3, 1, _T("{\"foo\":5, \"bar\":5}"), NULL);
MojTestErrCheck(err);
MojTestAssert(ti3.m_putCount == 2 && ti3.m_delCount == 0 && ti3.m_set.size() == 2);
err = index3.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例12: InfoToJson
MojErr ActivityManager::InfoToJson(MojObject& rep) const
{
MojLogTrace(s_log);
MojErr err = MojErrNone;
/* Scan the various run queues of the Activity Manager */
MojObject queues(MojObject::TypeArray);
for (int i = 0; i < RunQueueMax; i++) {
if (!m_runQueue[i].empty()) {
MojObject activities(MojObject::TypeArray);
std::for_each(m_runQueue[i].begin(), m_runQueue[i].end(),
boost::bind(&Activity::PushIdentityJson, _1,
boost::ref(activities)));
MojObject queue;
err = queue.putString(_T("name"), RunQueueNames[i]);
MojErrCheck(err);
err = queue.put(_T("activities"), activities);
MojErrCheck(err);
err = queues.push(queue);
MojErrCheck(err);
}
}
if (!queues.empty()) {
err = rep.put(_T("queues"), queues);
MojErrCheck(err);
}
std::vector<boost::shared_ptr<const Activity> > leaked;
std::set_difference(
boost::make_transform_iterator(m_idTable.cbegin(),
boost::bind<boost::shared_ptr<const Activity> >
(&Activity::shared_from_this, _1)),
boost::make_transform_iterator(m_idTable.cend(),
boost::bind<boost::shared_ptr<const Activity> >
(&Activity::shared_from_this, _1)),
boost::make_transform_iterator(m_activities.begin(),
boost::bind(&ActivityMap::value_type::second, _1)),
boost::make_transform_iterator(m_activities.end(),
boost::bind(&ActivityMap::value_type::second, _1)),
std::back_inserter(leaked));
if (!leaked.empty()) {
MojObject leakedActivities(MojObject::TypeArray);
std::for_each(leaked.begin(), leaked.end(),
boost::bind(&Activity::PushIdentityJson, _1,
boost::ref(leakedActivities)));
err = rep.put(_T("leakedActivities"), leakedActivities);
MojErrCheck(err);
}
return MojErrNone;
}
示例13: configureIndexes
MojErr MojDbKind::configureIndexes(const MojObject& obj, const MojString& locale, MojDbReq& req)
{
MojLogTrace(s_log);
// make sure indexes changes count against our usage
MojErr err = req.curKind(this);
MojErrCheck(err);
// add default id index to set
MojObject idIndex;
err = idIndex.fromJson(IdIndexJson);
MojErrCheck(err);
ObjectSet newIndexObjects;
err = newIndexObjects.put(idIndex);
MojErrCheck(err);
// change back to a set and use contains
MojSet<MojString> indexNames;
MojString defaultIdxName;
err = defaultIdxName.assign(IdIndexName);
MojErrCheck(err);
err = indexNames.put(defaultIdxName);
MojErrCheck(err);
// add indexes to set to uniquify and order them
MojObject indexArray;
if (obj.get(IndexesKey, indexArray)) {
MojObject::ConstArrayIterator end = indexArray.arrayEnd();
for (MojObject::ConstArrayIterator i = indexArray.arrayBegin(); i != end; ++i) {
MojString indexName;
err = i->getRequired(MojDbIndex::NameKey, indexName);
MojErrCheck(err);
err = indexName.toLower();
MojErrCheck(err);
if (!indexNames.contains(indexName)) {
MojObject idx = *i;
// make sure we keep the lower-cased index name
err = idx.putString(MojDbIndex::NameKey, indexName);
MojErrCheck(err);
err = newIndexObjects.put(idx);
MojErrCheck(err);
err = indexNames.put(indexName);
MojErrCheck(err);
} else {
MojErrThrowMsg(MojErrDbInvalidIndexName, _T("db: cannot repeat index name: '%s'"), indexName.data());
}
}
}
// figure out what to add and what to delete
ObjectSet toDrop;
err = m_indexObjects.diff(newIndexObjects, toDrop);
MojErrCheck(err);
ObjectSet toAdd;
err = newIndexObjects.diff(m_indexObjects, toAdd);
MojErrCheck(err);
// drop deleted indexes
IndexVec newIndexes;
for (IndexVec::ConstIterator i = m_indexes.begin(); i != m_indexes.end(); ++i) {
if (toDrop.contains((*i)->object())) {
err = dropIndex(i->get(), req);
MojErrCheck(err);
} else {
err = newIndexes.push(*i);
MojErrCheck(err);
}
}
// add new indexes
for (ObjectSet::ConstIterator i = toAdd.begin(); i != toAdd.end(); ++i) {
// create index
MojRefCountedPtr<MojDbIndex> index(new MojDbIndex(this, m_kindEngine));
MojAllocCheck(index.get());
err = index->fromObject(*i, locale);
MojErrCheck(err);
// open index
err = openIndex(index.get(), req);
MojErrCheck(err);
err = newIndexes.push(index);
MojErrCheck(err);
}
// sort indexes by the prop vec so that for indexes that share prop prefixes, the shortest one comes first
err = newIndexes.sort();
MojErrCheck(err);
// update members
m_indexObjects = newIndexObjects;
m_indexes = newIndexes;
return MojErrNone;
}
示例14: purge
MojErr MojDb::purge(MojUInt32& countOut, MojInt64 numDays, MojDbReqRef req)
{
MojLogTrace(s_log);
countOut = 0;
if (numDays <= -1) {
numDays = m_purgeWindow;
}
MojErr err = beginReq(req);
MojErrCheck(err);
MojLogDebug(s_log, _T("purging objects deleted more than %lld days ago..."), numDays);
MojTime time;
err = MojGetCurrentTime(time);
MojErrCheck(err);
// store the revision number to current timestamp mapping
MojObject revTimeMapping;
MojInt64 rev;
err = nextId(rev);
MojErrCheck(err);
err = revTimeMapping.put(RevNumKey, rev);
MojErrCheck(err);
err = revTimeMapping.put(TimestampKey, time.microsecs());
MojErrCheck(err);
err = revTimeMapping.putString(KindKey, MojDbKindEngine::RevTimestampId);
MojErrCheck(err);
err = putImpl(revTimeMapping, MojDb::FlagNone, req);
MojErrCheck(err);
// find the revision number for numDays prior to now
MojInt64 purgeTime = time.microsecs() - (MojTime::UnitsPerDay * numDays);
MojDbQuery query;
err = query.from(MojDbKindEngine::RevTimestampId);
MojErrCheck(err);
query.limit(1);
err = query.where(TimestampKey, MojDbQuery::OpLessThanEq, purgeTime);
MojErrCheck(err);
err = query.order(TimestampKey);
MojErrCheck(err);
query.desc(true);
MojDbCursor cursor;
err = findImpl(query, cursor, NULL, req, OpDelete);
MojErrCheck(err);
bool found = false;
MojObject obj;
err = cursor.get(obj, found);
MojErrCheck(err);
err = cursor.close();
MojErrCheck(err);
MojUInt32 batchCount = 0;
MojUInt32 totalCount = 0;
while ((found))
{
// Do it in AutoBatchSize batches
batchCount = 0;
req->fixmode(true); // purge even if index mis-matches
err = purgeImpl(obj, batchCount, req);
MojLogDebug(s_log, _T("purge batch processed: batch: %d; total: %d; err = %d\n"),
batchCount, (totalCount + batchCount), err);
MojErrCheck(err);
totalCount += batchCount;
countOut = totalCount;
if (batchCount < AutoBatchSize) // last batch
break;
err = commitBatch(req);
MojErrCheck(err);
continue;
}
// end request
err = req->end();
MojErrCheck(err);
MojLogDebug(s_log, _T("purged %d objects"), countOut);
return MojErrNone;
}
示例15: SerializeToDatabasePopObject
void PopAccountAdapter::SerializeToDatabasePopObject(const PopAccount& accnt, MojObject& obj)
{
MojErr err;
// Set the object kind
err = obj.putString(KIND, POP_ACCOUNT_KIND);
ErrorToException(err);
// Set ID
err = obj.put(ID, accnt.GetId());
ErrorToException(err);
// Set account ID
err = obj.put(ACCOUNT_ID, accnt.GetAccountId());
ErrorToException(err);
// Set host name
err = obj.putString(HOST_NAME, accnt.GetHostName().c_str());
ErrorToException(err);
// Set port
err = obj.putInt(PORT, accnt.GetPort());
ErrorToException(err);
// Set encryption
err = obj.putString(ENCRYPTION, accnt.GetEncryption().c_str());
ErrorToException(err);
// Set user name
err = obj.putString(USERNAME, accnt.GetUsername().c_str());
ErrorToException(err);
// Set 'initialSynced' flag
err = obj.putBool(INITIAL_SYNC, accnt.IsInitialSync());
ErrorToException(err);
// Set 'deleteFromServer' flag
err = obj.putBool(DELETE_FROM_SERVER, accnt.IsDeleteFromServer());
ErrorToException(err);
// Set 'deleteOnDevice' flag
err = obj.putBool(DELETE_ON_DEVICE, accnt.IsDeleteOnDevice());
ErrorToException(err);
// Set sync window
err = obj.putInt(EmailAccountAdapter::SYNC_WINDOW_DAYS, accnt.GetSyncWindowDays());
ErrorToException(err);
// Set sync frequency
err = obj.putInt(SYNC_FREQUENCY_MINS, accnt.GetSyncFrequencyMins());
ErrorToException(err);
if (accnt.IsError()) {
MojObject mojErr;
err = mojErr.putInt(EmailAccountAdapter::ERROR_CODE, (int)accnt.GetError().errorCode);
ErrorToException(err);
err = mojErr.putString(EmailAccountAdapter::ERROR_TEXT, accnt.GetError().errorText.c_str());
ErrorToException(err);
err = obj.put(EmailAccountAdapter::ERROR, mojErr);
ErrorToException(err);
} else {
err = obj.put(EmailAccountAdapter::ERROR, MojObject::Null);
}
SerializeSpecialFolders(accnt, obj);
}