当前位置: 首页>>代码示例>>C++>>正文


C++ MojDbQuery类代码示例

本文整理汇总了C++中MojDbQuery的典型用法代码示例。如果您正苦于以下问题:C++ MojDbQuery类的具体用法?C++ MojDbQuery怎么用?C++ MojDbQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MojDbQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

MojErr MojDbQueryPlan::init(const MojDbQuery& query, const MojDbIndex& index)
{
	m_query = query;
	m_locale = index.locale();
	m_idPropIndex = index.idIndex();
	m_ranges.clear();

	MojErr err = MojErrNone;
	if (index.includeDeleted() && !m_query.where().contains(MojDb::DelKey)) {
		err = m_query.where(MojDb::DelKey, MojDbQuery::OpEq, false);
		MojErrCheck(err);
	}
	// build ranges from where clauses
	err = buildRanges(index);
	MojErrCheck(err);
	if (query.desc()) {
		// reverse ranges if descending
		err = m_ranges.reverse();
		MojErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:BigBlueHat,项目名称:db8,代码行数:22,代码来源:MojDbQueryPlan.cpp

示例2: ErrorToException

void MojoDatabase::GetEmails(Signal::SlotRef slot, const MojObject& folderId, MojInt32 limit)
{
	MojDbQuery q;
	MojErr err = q.from(PopEmailAdapter::POP_EMAIL_KIND);
	ErrorToException(err);

	err = q.where(EmailSchema::FOLDER_ID, MojDbQuery::OpEq, folderId);
	ErrorToException(err);

	err = q.order(EmailSchema::TIMESTAMP);
	ErrorToException(err);

	q.limit(limit);
	q.desc(true);

	err = m_dbClient.find(slot, q);
	ErrorToException(err);
}
开发者ID:Garfonso,项目名称:app-services,代码行数:18,代码来源:MojoDatabase.cpp

示例3: MojTestErrCheck

MojErr MojDbSearchTest::initQuery(MojDbQuery& query, const MojChar* queryStr, const MojChar* orderBy, const MojObject& barVal, bool desc)
{
	query.clear();
	MojErr err = query.from(_T("SearchTest:1"));
	MojTestErrCheck(err);
	MojString val;
	err = val.assign(queryStr);
	MojTestErrCheck(err);
	err = query.where(_T("foo"), MojDbQuery::OpSearch, val, MojDbCollationPrimary);
	MojTestErrCheck(err);
	query.desc(desc);
	if (!barVal.undefined()) {
		err = query.where(_T("bar"), MojDbQuery::OpEq, barVal);
		MojTestErrCheck(err);
	}
	if (orderBy) {
		err = query.order(orderBy);
		MojTestErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:ctbrowser,项目名称:db8,代码行数:21,代码来源:MojDbSearchTest.cpp

示例4: MojTestErrCheck

MojErr MojDbPurgeTest::run()
{
	MojDb db;
	MojErr err = db.open(MojDbTestDir);
	MojTestErrCheck(err);

	// put type
	MojObject obj;
	err = obj.fromJson(MojKindStr);
	MojTestErrCheck(err);
	err = db.putKind(obj);
	MojTestErrCheck(err);

	MojObject revNums[10];
	MojObject ids[10];
	//put 10 objects in the db
	for(int i = 0; i < 10; i++) {
		err = obj.fromJson(MojTestObjStr1);
		MojTestErrCheck(err);
		err = db.put(obj);
		MojTestErrCheck(err);
		// get _rev and id
		MojObject rev;
		err = obj.getRequired(MojDb::RevKey, rev);
		MojTestErrCheck(err);
		revNums[i] = rev;
		MojObject id;
		err = obj.getRequired(MojDb::IdKey, id);
		MojTestErrCheck(err);
		ids[i] = id;
	}

	//purge now, there are no RevTimestamp entries
	MojUInt32 count = 0;
	err = db.purge(count, 30);
	MojTestErrCheck(err);

	err = checkObjectsPurged(db, count, 0, 10, 1, -1);
	MojTestErrCheck(err);

	//create a RevTimestamp entry - that's not more than PurgeNumDays days ago
	MojTime time;
	err = MojGetCurrentTime(time);
	MojTestErrCheck(err);
	err = createRevTimestamp(db, revNums[0], time.microsecs());
	MojTestErrCheck(err);

	//purge now, there are no RevTimestamp entries that are more than
	//PurgeNumDays ago, so nothing should be purged
	count = 0;
	err = db.purge(count, 30);
	MojTestErrCheck(err);

	err = checkObjectsPurged(db, count, 0, 10, 3, -1);
	MojTestErrCheck(err);

	//create a RevTimestamp entry for more than PurgeNumDays days ago
	err = MojGetCurrentTime(time);
	MojTestErrCheck(err);
	err = createRevTimestamp(db, revNums[9], time.microsecs() - (((MojInt64)40) * MojTime::UnitsPerDay));
	MojTestErrCheck(err);

	//purge now, since nothing has been deleted, nothing should be purged,
	//but the RevTimestamp object should be deleted
	count = 0;
	err = db.purge(count, 30);
	MojTestErrCheck(err);

	err = checkObjectsPurged(db, count, 0, 10, 4, -1);
	MojTestErrCheck(err);

	//delete something - this will set its revision number higher
	bool found;
	err = db.del(ids[0], found);
	MojTestErrCheck(err);
	MojTestAssert(found == true);

	//purge now, since nothing has been deleted prior to the revision
	//number, nothing should be purged
	count = 0;
	err = db.purge(count, 30);
	MojTestErrCheck(err);

	err = checkObjectsPurged(db, count, 0, 9, 5, -1);
	MojTestErrCheck(err);

	//delete another object
	err = db.del(ids[1], found);
	MojTestErrCheck(err);
	MojTestAssert(found == true);

	//create a RevTimestamp entry for more than PurgeNumDays days ago,
	//with the rev number of the 1st obj we deleted
	MojDbQuery query;
	err = query.from(_T("PurgeTest:1"));
	MojTestErrCheck(err);
	err = query.where(MojDb::IdKey, MojDbQuery::OpEq, ids[0]);
	MojTestErrCheck(err);
	err = query.includeDeleted();
	MojTestErrCheck(err);
//.........这里部分代码省略.........
开发者ID:ctbrowser,项目名称:db8,代码行数:101,代码来源:MojDbPurgeTest.cpp

示例5: MojTestErrCheck

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"));
//.........这里部分代码省略.........
开发者ID:feniksa,项目名称:indb8,代码行数:101,代码来源:MojDbTxnTest.cpp

示例6: MojTestErrCheck

MojErr MojDbWatchTest::eqTest(MojDb& db)
{
    MojDbQuery query;
    MojErr err = query.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = query.where(_T("foo"), MojDbQuery::OpEq, 1);
    MojTestErrCheck(err);
    MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
    MojTestAssert(watcher.get());
    MojDbCursor cursor;
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojRefCountedPtr<TestWatcher> watcher2(new TestWatcher);
    MojTestAssert(watcher2.get());
    bool fired = false;
    err = db.watch(query, cursor, watcher2->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    // puts
    MojObject id;
    err = put(db, 0, 0, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    err = put(db, 2, 2, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    // put, changing property not in index
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    err = put(db, 1, 2, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    // dels
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    watcher2.reset(new TestWatcher);
    MojTestAssert(watcher2.get());
    MojDbQuery queryWithRev;
    err = queryWithRev.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("foo"), MojDbQuery::OpEq, 1);
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("_rev"), MojDbQuery::OpGreaterThan, m_rev);
    MojTestErrCheck(err);
    err = queryWithRev.includeDeleted();
    MojTestErrCheck(err);
    fired = false;
    err = db.watch(queryWithRev, cursor, watcher2->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    bool found;
    err = db.del(id, found);
    MojTestErrCheck(err);
    MojTestAssert(found);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    // ordering
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);

    return MojErrNone;
}
开发者ID:halfhalo,项目名称:db8,代码行数:97,代码来源:MojDbWatchTest.cpp

示例7: MojLogTrace

/*
 * Disabling an account means doing the following
 *     delete com.palm.imloginstate.libpurple record
 *     delete com.palm.immessage.libpurple records
 *     delete com.palm.imcommand.libpurple records
 *     delete com.palm.contact.libpurple records
 *     delete com.palm.imbuddystatus.libpurple records
 *     delete com.palm.imgroupchat.libpurple records -- groupchats not currently supported
 * Note: the ChatThreader service takes care of removing empty chats
 */
MojErr OnEnabledHandler::accountDisabled()
{
	MojLogTrace(IMServiceApp::s_log);
	MojLogInfo(IMServiceApp::s_log, _T("accountDisabled id=%s, serviceName=%s"), m_accountId.data(), m_serviceName.data());

	// delete com.palm.imloginstate.libpurple record
	MojDbQuery queryLoginState;
	queryLoginState.from(IM_LOGINSTATE_KIND);

	// we can get multiple calls to onEnabled(false) even after we have deleted the account records, so search by account Id so
	// we don't delete a new account with same username/servicename (see DFISH-16682)
//	queryLoginState.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
//	queryLoginState.where(_T("username"), MojDbQuery::OpEq, m_username);
	queryLoginState.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
	MojErr err = m_dbClient.del(m_deleteImLoginStateSlot, queryLoginState);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imloginstate) failed: error %d - %s"), err, error.data());
	}

	// delete com.palm.immessage.libpurple records
	//TODO: need to query both from & recipient addresses. Simplify this???
	MojDbQuery queryMessage;
	queryMessage.from(IM_IMMESSAGE_KIND);
	queryMessage.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
	queryMessage.where(_T("username"), MojDbQuery::OpEq, m_username);
	err = m_dbClient.del(m_deleteImMessagesSlot, queryMessage);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(immessage) failed: error %d - %s"), err, error.data());
	}

	// delete com.palm.imcommand.libpurple records
	MojDbQuery queryCommand;
	queryCommand.from(IM_IMCOMMAND_KIND);
	queryCommand.where(_T("serviceName"), MojDbQuery::OpEq, m_serviceName);
	queryCommand.where(_T("fromUsername"), MojDbQuery::OpEq, m_username);
	err = m_dbClient.del(m_deleteImCommandsSlot, queryCommand);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imcommand) failed: error %d - %s"), err, error.data());
	}

	// delete com.palm.contact.libpurple record
	MojDbQuery queryContact;
	queryContact.from(IM_CONTACT_KIND);
	queryContact.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
	err = m_dbClient.del(m_deleteContactsSlot, queryContact);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(contact) failed: error %d - %s"), err, error.data());
	}

	// delete com.palm.imbuddystatus.libpurple record
	MojDbQuery queryBuddyStatus;
	queryBuddyStatus.from(IM_BUDDYSTATUS_KIND);
	queryBuddyStatus.where(_T("accountId"), MojDbQuery::OpEq, m_accountId);
	err = m_tempdbClient.del(m_deleteImBuddyStatusSlot, queryBuddyStatus);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.del(imbuddystatus) failed: error %d - %s"), err, error.data());
	}

	// now we need to tell libpurple to disconnect the account so we don't get more messages for it
	// LoginCallbackInterface is null because we don't need to do any processing on the callback - all the DB kinds are already gone.
	LibpurpleAdapter::logout(m_serviceName, m_username, NULL);

	return MojErrNone;
}
开发者ID:webOS-ports,项目名称:imlibpurpleservice,代码行数:84,代码来源:OnEnabledHandler.cpp

示例8: MojLogTrace

MojErr MojDbKind::updateSupers(const KindMap& map, const StringVec& superIds, bool updating, MojDbReq& req)
{
	MojLogTrace(s_log);
	MojInt32 indexes = 0;
	if (updating) {
		KindVec addedSupers;
		MojErr err = diffSupers(map, superIds, m_superIds, addedSupers);
		MojErrCheck(err);
		KindVec removedSupers;
		err = diffSupers(map, m_superIds, superIds, removedSupers);
		MojErrCheck(err);

		// remove/add our objects from new/removed supers
		if (!addedSupers.empty() || !removedSupers.empty()) {
			MojDbQuery query;
			err = query.from(m_id);
			MojErrCheck(err);
			err = query.includeDeleted(true);
			MojErrCheck(err);
			MojDbCursor cursor;
			cursor.kindEngine(m_kindEngine);
			err = find(cursor, NULL, req, OpKindUpdate);
			MojErrCheck(err);
			for (;;) {
				MojObject obj;
				bool found = false;
				err = cursor.get(obj, found);
				MojErrCheck(err);
				if (!found)
					break;

				for (KindVec::ConstIterator i = addedSupers.begin(); i != addedSupers.end(); ++i) {
					err = (*i)->updateOwnIndexes(&obj, NULL, req, indexes);
					MojErrCheck(err);
				}
				for (KindVec::ConstIterator i = removedSupers.begin(); i != removedSupers.end(); ++i) {
					err = (*i)->updateOwnIndexes(NULL, &obj, req, indexes);
					MojErrCheck(err);
				}
			}
		}
	}

	// remove old supers
	m_superIds = superIds;
	MojErr err = clearSupers();
	MojErrCheck(err);
	// look for new supers
	for (StringVec::ConstIterator i = m_superIds.begin(); i != m_superIds.end(); ++i) {
		KindMap::ConstIterator mapIter = map.find(*i);
		if (mapIter != map.end()) {
			err = addSuper(mapIter->get());
			MojErrCheck(err);
		}
	}
	// look for kinds that extend us
	for (KindMap::ConstIterator i = map.begin(); i != map.end(); ++i) {
		if ((*i)->m_superIds.find(m_id) != MojInvalidIndex) {
			err = (*i)->addSuper(this);
			MojErrCheck(err);
		}
	}
	// add root kind if we have no supers
	if (m_supers.empty()) {
		KindMap::ConstIterator mapIter = map.find(MojDbKindEngine::RootKindId);
		if (mapIter != map.end()) {
			err = addSuper(mapIter->get());
			MojErrCheck(err);
		}
	}
	return MojErrNone;
}
开发者ID:webOS101,项目名称:db8,代码行数:72,代码来源:MojDbKind.cpp

示例9: verifyIndex

MojErr MojDbKind::verifyIndex(MojDbIndex *pIndex, MojObject &iinfo, MojDbReq& req)
{
	// Goes throudh each index entry and verifies that it points to a valid object
	// For debugging purposes as stats for indexes does not access the target objects
	// Index->stats function does not have enough context to find the object
	// db/stats usage '{"verify":true,"kind":"xyz"}' - each optional
	
	MojDbQuery query;
	MojErr err = query.from(m_id);
	MojErrCheck(err);
	err = query.includeDeleted(true);
	MojErrCheck(err);
	MojDbCursor cursor;
	query.m_forceIndex = pIndex;		// Important: Otherwise, it will pick the default index
	cursor.verifymode(true);		// to get the errors
	err = m_kindEngine->find(query, cursor, NULL, req, OpRead);
	MojLogInfo(s_log, _T("Kind_verifyIndex: Kind: %s; Index: %s; idIndex: %zX; size: %zu; CursorIndex: %s \n"), m_name.data(), 
					pIndex->name().data(), pIndex->idIndex(), pIndex->size(), cursor.m_dbIndex->name().data());
	MojErrCheck(err);
	MojSize count = 0;
	MojSize delCount = 0;
	MojSize warnCount = 0;
	char s[1024];
	for (;;) {
		MojDbStorageItem* item = NULL;
		bool found = false;
		err = cursor.get(item, found);
		if (err == MojErrInternalIndexOnFind) {
			warnCount++;
			MojDbIsamQuery *iquery = (MojDbIsamQuery *)cursor.m_storageQuery.get();
			MojErr err2 =  MojByteArrayToHex(iquery->m_keyData, iquery->m_keySize, s); 
			MojErrCheck(err2);
			MojChar *ids = (iquery->m_keySize > 18) ? (MojChar *)(iquery->m_keyData + iquery->m_keySize - 17) : NULL; 
			MojLogInfo(s_log, _T("VerifyIndex Warning: %s; KeySize: %zu; %s ;id: %s \n"), 
					cursor.m_dbIndex->name().data(), iquery->m_keySize, s, ids);
			continue;
		}
		MojErrCheck(err);
		if (!found)
			break;
		MojObject obj;
		err = item->toObject(obj, *m_kindEngine, true);
		MojErrCheck(err);
		bool deleted = false;
		if (obj.get(MojDb::DelKey, deleted) && deleted) {
			delCount++;
		} else {
			count++;
		}
	}

	MojLogInfo(s_log, _T("Kind_verifyIndex Counts: Kind: %s; Index: %s; count: %zu; delcount: %zu; warnings: %zu \n"), m_name.data(), 
					pIndex->name().data(), count, delCount, warnCount);
	
	err = iinfo.put(VerifyCountKey, (MojInt64)count);
	MojErrCheck(err);
	err = iinfo.put(VerifyWarnCountKey, (MojInt64) warnCount);
	MojErrCheck(err);
	err = iinfo.put(VerifyDelCountKey, (MojInt64) delCount);
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:webOS101,项目名称:db8,代码行数:63,代码来源:MojDbKind.cpp

示例10: MojLogTrace

MojErr MojDb::purgeImpl(MojObject& obj, MojUInt32& countOut, MojDbReq& req)
{
	MojLogTrace(s_log);

	MojObject val;
	MojErr err = obj.getRequired(RevNumKey, val);
	MojErrCheck(err);
	MojObject timestamp;
	err = obj.getRequired(TimestampKey, timestamp);
	MojErrCheck(err);

	// purge all objects that were deleted on or prior to this rev num

	// query for objects in two passes - once where backup is true and once where backup is false
	MojDbQuery objQuery;
	err = objQuery.from(MojDbKindEngine::RootKindId);
	MojErrCheck(err);
	err = objQuery.where(DelKey, MojDbQuery::OpEq, true);
	MojErrCheck(err);
	err = objQuery.where(SyncKey, MojDbQuery::OpEq, true);
	MojErrCheck(err);
	err = objQuery.where(RevKey, MojDbQuery::OpLessThanEq, val);
	MojErrCheck(err);

	MojUInt32 backupCount = 0;
	req.autobatch(true);
	req.fixmode(true);
	objQuery.limit(AutoBatchSize);
	err = delImpl(objQuery, backupCount, req, FlagPurge);
	MojErrCheck(err);

	MojDbQuery objQuery2;
	err = objQuery2.from(MojDbKindEngine::RootKindId);
	MojErrCheck(err);
	err = objQuery2.where(DelKey, MojDbQuery::OpEq, true);
	MojErrCheck(err);
	err = objQuery2.where(SyncKey, MojDbQuery::OpEq, false);
	MojErrCheck(err);
	err = objQuery2.where(RevKey, MojDbQuery::OpLessThanEq, val);
	MojErrCheck(err);
	MojUInt32 count = 0;
	MojUInt32 batchRemain = 0;
	if (backupCount <= AutoBatchSize)
		batchRemain = AutoBatchSize - backupCount;
	req.autobatch(true);		// enable auto batch
	req.fixmode(true);		// force deletion of bad entries

	if (batchRemain > 0) {
		objQuery2.limit(batchRemain);
		err = delImpl(objQuery2, count, req, FlagPurge);
		MojErrCheck(err);
	}

	countOut = count + backupCount;

	req.autobatch(false);

	// if we actually deleted objects, store this rev num as the last purge rev
	if (countOut > 0) {
		err = updateState(LastPurgedRevKey, val, req);
		MojErrCheck(err);
	}

	// delete all the RevTimestamp entries prior to this one
	MojDbQuery revTimestampQuery;
	err = revTimestampQuery.from(MojDbKindEngine::RevTimestampId);
	MojErrCheck(err);
	err = revTimestampQuery.where(TimestampKey, MojDbQuery::OpLessThanEq, timestamp);
	MojErrCheck(err);

	count = 0;
	err = delImpl(revTimestampQuery, count, req, FlagPurge);
	MojErrCheck(err);


	return MojErrNone;
}
开发者ID:feniksa,项目名称:indb8,代码行数:77,代码来源:MojDbAdmin.cpp

示例11: MojErrCheck

MojErr MojDb::dumpImpl(MojFile& file, bool backup, bool incDel, const MojObject& revParam, const MojObject& delRevParam, bool skipKinds, MojUInt32& countOut, MojDbReq& req,
		MojObject* response, const MojChar* keyName, MojSize& bytesWritten, MojSize& warns, MojUInt32 maxBytes)
{
	// query for objects, adding the backup key and rev key if necessary
	MojDbQuery query;
	MojErr err = query.from(MojDbKindEngine::RootKindId);
	MojErrCheck(err);
	err = query.where(MojDb::DelKey, MojDbQuery::OpEq, incDel);
	MojErrCheck(err);
	if (backup) {
		err = query.where(MojDb::SyncKey, MojDbQuery::OpEq, true);
		MojErrCheck(err);
		if (incDel) {
			err = query.where(MojDb::RevKey, MojDbQuery::OpGreaterThan, delRevParam);
			MojErrCheck(err);
		} else {
			err = query.where(MojDb::RevKey, MojDbQuery::OpGreaterThan, revParam);
			MojErrCheck(err);
		}
	}

	MojDbCursor cursor;
	err = findImpl(query, cursor, NULL, req, OpRead);
	MojErrCheck(err);
	warns = 0;

	MojObject curRev;
	for(;;) {
		bool found = false;
		MojObject obj;
		err = cursor.get(obj, found);
		// So that we can get as much data as possible from a corrupt database
		// We simply skip ghost keys and continue
		if (err == MojErrInternalIndexOnFind) {
			warns++;
			continue;
		}
		MojErrCheck(err);
		if (!found)
			break;

		if (skipKinds) {
			MojString kind;
			err = obj.getRequired(KindKey, kind);
			MojErrCheck(err);
			if (kind == MojDbKindEngine::KindKindId) {
				continue;
			}
		}

		// write out each object, if the backup is full, insert the appropriate incremental key
		err = dumpObj(file, obj, bytesWritten, maxBytes);
		MojErrCatch(err, MojErrDbBackupFull) {
			if (response) {
				MojErr errBackup = MojErrNone;
				if (!curRev.undefined()) {
					errBackup = insertIncrementalKey(*response, keyName, curRev);
					MojErrCheck(errBackup);
				} else {
					errBackup = insertIncrementalKey(*response, keyName, incDel ? delRevParam: revParam);
					MojErrCheck(errBackup);
				}
				errBackup = handleBackupFull(revParam, delRevParam, *response, keyName);
				MojErrCheck(errBackup);
			}
			return MojErrNone;
		}
		MojErrCheck(err);
		err = obj.getRequired(MojDb::RevKey, curRev);
		MojErrCheck(err);
		countOut++;
	}
	err = cursor.close();
	MojErrCheck(err);

    if (warns > 0) {
        MojLogWarning(s_log, _T("Finished Backup with %d warnings \n"), (int)warns);
    } else {
        MojLogDebug(s_log, _T("Finished Backup with no warnings \n"));
    }

	// construct the next incremental key
	if (response && !curRev.undefined()) {
		err = insertIncrementalKey(*response, keyName, curRev);
		MojErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:feniksa,项目名称:indb8,代码行数:88,代码来源:MojDbAdmin.cpp

示例12: MojAssert

MojErr MojDb::dump(const MojChar* path, MojUInt32& countOut, bool incDel, MojDbReqRef req, bool backup,
		MojUInt32 maxBytes, const MojObject* incrementalKey, MojObject* backupResponse)
{
	MojAssert(path);
	MojLogTrace(s_log);

	MojErr err = beginReq(req);
	MojErrCheck(err);

	if (!req->admin()) {
		MojLogError(s_log, _T("access denied: '%s' cannot dump db to path: '%s'"), req->domain().data(), path);
		MojErrThrow(MojErrDbAccessDenied);
	}

	MojFile file;
	err = file.open(path, MOJ_O_WRONLY | MOJ_O_CREAT | MOJ_O_TRUNC, MOJ_S_IRUSR | MOJ_S_IWUSR);
	MojErrCheck(err);

	// write out kinds first, then existing objects, then deleted objects
	MojSize bytesWritten = 0;
	MojSize totalwarns = 0;
	MojSize newwarns = 0;
	MojDbQuery objQuery;
	MojVector<MojObject> kindVec;
	MojObject revParam = -1;
	MojObject delRevParam = -1;

	// if we were given an incremental key, pull out the revs now
	if (incrementalKey) {
		incrementalKey->get(MojDbServiceDefs::RevKey, revParam);
		incrementalKey->get(MojDbServiceDefs::DeletedRevKey, delRevParam);
	}

	err = m_kindEngine.getKinds(kindVec);
	MojErrCheck(err);

	// write kinds - if incremental, only write the kinds that have changed since the respective revs
	MojString countStr;
	for (MojVector<MojObject>::ConstIterator i = kindVec.begin(); i != kindVec.end(); ++i) {
		if (backup) {
			bool backupKind = false;
			i->get(MojDbKind::SyncKey, backupKind);
			if (!backupKind)
				continue;
			MojString id;
			err = i->getRequired(MojDbServiceDefs::IdKey, id);
			MojErrCheck(err);
			MojDbQuery countQuery;
			err = countQuery.from(id);
			MojErrCheck(err);
			MojDbCursor cursor;
			err = find(countQuery, cursor, req);
			MojErrCheck(err);
			MojUInt32 count = 0;
			err = cursor.count(count);
			MojErrCheck(err);
			if (count > 0) {
				if (i != kindVec.begin()) {
					err = countStr.appendFormat(_T(", "));
					MojErrCheck(err);
				}
				err = countStr.appendFormat("%s=%u", id.data(), count);
				MojErrCheck(err);
			}
		}
		bool deleted = false;
		i->get(DelKey, deleted);
		MojObject kindRev;
		err = i->getRequired(RevKey, kindRev);
		MojErrCheck(err);
		if ((deleted && kindRev > delRevParam) || (!deleted && kindRev > revParam)) {
			err = dumpObj(file, (*i), bytesWritten, maxBytes);
			MojErrCheck(err);
			countOut++;
		}
	}

	// dump all the non-deleted objects
	err = dumpImpl(file, backup, false, revParam, delRevParam, true, countOut, req, backupResponse, MojDbServiceDefs::RevKey, bytesWritten, newwarns, maxBytes);
	MojErrCheck(err);
	totalwarns += newwarns;
	// If we're supposed to include deleted objects, dump the deleted objects now.
	// There's a chance that we may have run out of space in our backup.  If that's the case,
	// we don't want to try to dump deleted objects - we can detect this by looking for the HasMoreKey
	if (incDel && backupResponse && !backupResponse->contains(MojDbServiceDefs::HasMoreKey)) {
		err = dumpImpl(file, backup, true, revParam, delRevParam, false, countOut, req, backupResponse, MojDbServiceDefs::DeletedRevKey, bytesWritten, newwarns, maxBytes);
		MojErrCheck(err);
	}
	totalwarns += newwarns;

	// Add the Full and Version keys
	if (backup && backupResponse) {
		bool incremental = (incrementalKey != NULL);
		err = backupResponse->putBool(MojDbServiceDefs::FullKey, !incremental);
		MojErrCheck(err);
		err = backupResponse->put(MojDbServiceDefs::VersionKey, DatabaseVersion);
		MojErrCheck(err);
		err = backupResponse->put(MojDbServiceDefs::WarningsKey, (MojInt32)totalwarns);
		MojErrCheck(err);
		MojString description;
//.........这里部分代码省略.........
开发者ID:feniksa,项目名称:indb8,代码行数:101,代码来源:MojDbAdmin.cpp

示例13: ErrorToException

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);
}
开发者ID:hatsada1,项目名称:app-services,代码行数:73,代码来源:SyncStateUpdater.cpp

示例14: check

MojErr MojDbSearchTest::simpleTest(MojDb& db)
{
	// just foo
	MojErr err = check(db, _T("bogus"), _T("[]"));
	MojTestErrCheck(err);
	err = check(db, _T("f"), _T("[1,2,3,4]"));
	MojTestErrCheck(err);
	err = check(db, _T("F"), _T("[1,2,3,4]"));
	MojTestErrCheck(err);
	err = check(db, _T("fo"), _T("[1,2,3,4]"));
	MojTestErrCheck(err);
	err = check(db, _T("four"), _T("[1,3,4]"));
	MojTestErrCheck(err);
	err = check(db, _T("score"), _T("[1]"));
	MojTestErrCheck(err);
	err = check(db, _T("four years"), _T("[1]"));
	MojTestErrCheck(err);
	err = check(db, _T("Four Years"), _T("[1]"));
	MojTestErrCheck(err);
	err = check(db, _T("four decades"), _T("[]"));
	MojTestErrCheck(err);
	err = check(db, _T("fathers forth"), _T("[2,3]"));
	MojTestErrCheck(err);
	err = check(db, _T("four f"), _T("[1,3,4]"));
	MojTestErrCheck(err);
	err = check(db, _T("four f fo fou"), _T("[1,3,4]"));
	MojTestErrCheck(err);
	// bar and foo
	err = check(db, _T("f"), _T("[3]"), NULL, 2);
	MojTestErrCheck(err);
	// order by bar
	err = check(db, _T("f"), _T("[4,3,2,1]"), _T("bar"));
	MojTestErrCheck(err);
	err = check(db, _T("f"), _T("[1,2,3,4]"), _T("bar"), MojObject::Undefined, true);
	MojTestErrCheck(err);
	err = check(db, _T("f"), _T("[4,3,1,2]"), _T("foo"));
	MojTestErrCheck(err);
	// array value for bar
	MojObject array;
	err = array.push(1);
	MojErrCheck(err);
	err = array.push(2);
	MojErrCheck(err);
	err = check(db, _T("f"), _T("[4,3]"), _T("bar"), array);
	MojTestErrCheck(err);

	// limit
	MojDbQuery query;
	err = initQuery(query, _T("f"));
	MojTestErrCheck(err);
	query.limit(2);
	err = check(db, query, _T("[1,2]"));
	MojTestErrCheck(err);
	err = initQuery(query, _T("f"), _T("bar"));
	MojTestErrCheck(err);
	query.limit(2);
	err = check(db, query, _T("[4,3]"));
	MojTestErrCheck(err);

	// accent insensitivity
	err = check(db, _T("COTE"), _T("[5,6,7,8,9]"));
	MojTestErrCheck(err);

	// case-insensitive ordering
	err = check(db, _T("a"), _T("[12,13,11]"), _T("foo"));
	MojTestErrCheck(err);

	// multi-prop
	query.clear();
	err = query.from(_T("SearchTest:1"));
	MojTestErrCheck(err);
	MojString val;
	err = val.assign(_T("test"));
	MojTestErrCheck(err);
	err = query.where(_T("multiprop"), MojDbQuery::OpSearch, val, MojDbCollationPrimary);
	MojTestErrCheck(err);
	err = check(db, query, _T("[14,15]"));
	MojTestErrCheck(err);

	return MojErrNone;
}
开发者ID:ctbrowser,项目名称:db8,代码行数:81,代码来源:MojDbSearchTest.cpp

示例15: MojAssert

MojErr MojDbServiceHandler::findImpl(MojServiceMessage* msg, MojObject& payload, MojDbReq& req, MojDbCursor& cursor, bool doCount)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojObject queryObj;
	MojErr err = payload.getRequired(MojDbServiceDefs::QueryKey, queryObj);
	MojErrCheck(err);
	bool doWatch = false;
	payload.get(MojDbServiceDefs::WatchKey, doWatch);

	MojDbQuery query;
	err = query.fromObject(queryObj);
	MojErrCheck(err);
	MojUInt32 limit = query.limit();
	if (limit == MojDbQuery::LimitDefault){
		query.limit(MaxQueryLimit);
	} else if (limit > MaxQueryLimit) {
		MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: limit greater than %d not allowed"), MaxQueryLimit);
	}

	if (doWatch) {
		MojRefCountedPtr<Watcher> watcher(new Watcher(msg));
		MojAllocCheck(watcher.get());
		err = m_db.find(query, cursor, watcher->m_watchSlot, req);
		MojErrCheck(err);
	} else {
		err = m_db.find(query, cursor, req);
		MojErrCheck(err);
	}

	// append results
	MojObjectVisitor& writer = msg->writer();
	err = writer.beginObject();
	MojErrCheck(err);
	err = writer.boolProp(MojServiceMessage::ReturnValueKey, true);
	MojErrCheck(err);
	err = writer.propName(MojDbServiceDefs::ResultsKey);
	MojErrCheck(err);
	err = writer.beginArray();
	MojErrCheck(err);
	err = cursor.visit(writer);
	MojErrCheck(err);
	err = writer.endArray();
	MojErrCheck(err);

	// append next page
	MojDbQuery::Page page;
	err = cursor.nextPage(page);
	MojErrCheck(err);
	if (!page.empty()) {
		MojObject pageObj;
		err = page.toObject(pageObj);
		MojErrCheck(err);
		err = writer.objectProp(MojDbServiceDefs::NextKey, pageObj);
		MojErrCheck(err);
	}

	// append count
	if (doCount) {
		MojUInt32 count = 0;
		err = cursor.count(count);
		MojErrCheck(err);
		err = writer.intProp(MojDbServiceDefs::CountKey, (MojInt64) count);
		MojErrCheck(err);
	}

	err = writer.endObject();
	MojErrCheck(err);

	if (doWatch) {
		// if this is a watched query, it cannot be part of a batch so it's safe to reply here
		err = msg->reply();
		MojErrCheck(err);
	}

	// notifications can fire any time after the cursor is closed,
	// so don't close it until after sending the reply.
	err = cursor.close();
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:anttiharju-owo,项目名称:db8,代码行数:83,代码来源:MojDbServiceHandler.cpp


注:本文中的MojDbQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。