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


C++ MojDbCursor类代码示例

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


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

示例1: MojAssert

MojErr MojDbServiceHandler::handleWatch(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojObject queryObj;
	MojErr err = payload.getRequired(MojDbServiceDefs::QueryKey, queryObj);
	MojErrCheck(err);
	
	MojRefCountedPtr<Watcher> watcher(new Watcher(msg));
	MojAllocCheck(watcher.get());

	MojDbQuery query;
	err = query.fromObject(queryObj);
	MojErrCheck(err);
	bool fired = false;
	MojDbCursor cursor;
	err = m_db.watch(query, cursor, watcher->m_watchSlot, fired, req);
	MojErrCheck(err);

	MojLogInfo(s_log, _T("handleWatch: %s, err: (%d); sender= %s;\n fired=%d; \n"),
				msg->method(), (int)err, msg->senderName(), (int)fired);

	if (!fired) {
		err = msg->replySuccess();
		MojErrCheck(err);
	}

	err = cursor.close();
	MojErrCheck(err);

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

示例2: watch

MojErr MojDb::watch(const MojDbQuery& query, MojDbCursor& cursor, WatchSignal::SlotRef watchHandler, bool& firedOut, MojDbReqRef req)
{
	MojLogTrace(s_log);

	firedOut = false;

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

	MojRefCountedPtr<MojDbWatcher> watcher(new MojDbWatcher(watchHandler));
	MojAllocCheck(watcher.get());

	MojDbQuery limitedQuery = query;
	limitedQuery.limit(1);
	err = findImpl(limitedQuery, cursor, watcher.get(), req, OpRead);
	MojErrCheck(err);

	MojDbStorageItem* item = NULL;
	bool found = false;
	cursor.verifymode(false);
	err = cursor.get(item, found);
	MojErrCheck(err);

	if (found) {
       const MojDbKey& key = cursor.storageQuery()->endKey();
       err = watcher->fire(key);
       MojErrCheck(err);
       firedOut = true;
	}

	err = req->end(false);
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:35,代码来源:MojDb.cpp

示例3: LOG_TRACE

MojErr MojDbPutHandler::open(const MojObject& conf, MojDb* db, MojDbReq& req)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
    MojAssertWriteLocked(db->schemaLock());

    m_db = db;
    // configure
    MojErr err = configure(conf, req);
    MojErrCheck(err);
    // load permissions from db
    MojDbQuery query;
    err = query.from(m_kindId);
    MojErrCheck(err);
    MojDbCursor cursor;
    err = db->find(query, cursor, req);
    MojErrCheck(err);
    for (;;) {
        bool found = false;
        MojObject perm;
        err = cursor.get(perm, found);
        MojErrCheck(err);
        if (!found)
            break;
        err = put(perm, req, false);
        MojErrCheck(err);
    }
    return MojErrNone;
}
开发者ID:webOS-ports,项目名称:db8,代码行数:28,代码来源:MojDbPutHandler.cpp

示例4: verifyRecords

/**
 * verifyRecords
 */
MojErr MojDbShardManagerTest::verifyRecords (const MojChar* strKind, MojDb& db, const MojDbShardInfo&, MojUInt32& count)
{
    MojDbQuery query;
    MojDbCursor cursor;
    count = 0;

    MojErr err = query.from(strKind);
    MojErrCheck(err);

    err = db.find(query, cursor);
    MojErrCheck(err);

    while (true)
    {
        bool found;
        MojObject dbObj;

        err = cursor.get(dbObj, found);
        MojErrCheck(err);
        if (!found)
            break;

        ++count;
    }

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

示例5: checkCount

    void checkCount()
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("LoadTest:1")) );

        MojDbCursor cursor;
        MojAssertNoErr( db.find(query, cursor) );

        MojUInt32 count = 0;
        MojAssertNoErr( cursor.count(count) );

        EXPECT_EQ( 10LL, count );
    }
开发者ID:pombredanne,项目名称:db8,代码行数:13,代码来源:DumpLoadTest.cpp

示例6: MojLogTrace

MojErr MojDb::merge(const MojDbQuery& query, const MojObject& props, MojUInt32& countOut, MojUInt32 flags, MojDbReqRef req)
{
	MojLogTrace(s_log);

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

	MojDbCursor cursor;
	err = findImpl(query, cursor, NULL, req, OpUpdate);
	MojErrCheck(err);
	MojAssert(cursor.txn());

	MojUInt32 count = 0;
	MojUInt32 warns = 0;
	bool found = false;
	MojObject prev;
	for (;;) {
		// get prev rev from cursor
		MojDbStorageItem* prevItem = NULL;
		err = cursor.get(prevItem, found);
		if (err == MojErrInternalIndexOnFind) {
			warns++;
			continue;
		}
		MojErrCheck(err);
		if (!found)
			break;
		err = prevItem->toObject(prev, m_kindEngine);
		MojErrCheck(err);
		// merge obj into prev
		MojObject merged;
		err = mergeInto(merged, props, prev);
		MojErrCheck(err);
		// and update the db
		const MojObject& id = prevItem->id();
		err = putObj(id, merged, &prev, prevItem, req, OpUpdate);
		MojErrCheck(err);
		++count;
	}
	if (warns > 0)
		MojLogWarning(s_log, _T("Merge index_warnings: %s; count: %d\n"), query.from().data(), warns);
	err = cursor.close();
	MojErrCheck(err);
	err = req->end();
	MojErrCheck(err);

	countOut = count;

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:51,代码来源:MojDb.cpp

示例7: MojTestErrCheck

MojErr MojDbWatchTest::cancelTest(MojDb& db)
{
    // cancel find
    MojDbQuery query;
    MojErr err = query.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = query.where(_T("foo"), MojDbQuery::OpLessThanEq, 45);
    MojTestErrCheck(err);
    MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
    MojTestAssert(watcher.get());
    watcher->m_slot.cancel();
    MojDbCursor cursor;
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    watcher->m_slot.cancel();
    MojTestAssert(watcher->m_count == 0);
    MojObject id;
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    // cancel watch
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    MojDbQuery queryWithRev;
    err = queryWithRev.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("foo"), MojDbQuery::OpEq, 45);
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("_rev"), MojDbQuery::OpGreaterThan, m_rev);
    MojTestErrCheck(err);
    bool fired = false;
    err = db.watch(queryWithRev, cursor, watcher->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    MojTestAssert(watcher->m_count == 0);
    watcher->m_slot.cancel();
    MojTestAssert(watcher->m_count == 0);
    err = put(db, 45, 45, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);

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

示例8: searchCursor

MojErr MojDbDistinctTest::simpleTest(MojDb& db)
{
	MojErr err;
	MojDbQuery query;
	const MojChar* queryString;
	const MojChar* expectedIdsJson;
    MojString str;
    MojDbSearchCursor searchCursor(str);
    MojDbCursor cursor;

	//1st test
	queryString = _T("bar");
	expectedIdsJson = _T("[\"a\",\"b\",\"c\",\"d\"]");
	err = initQuery(query, queryString);
	MojTestErrCheck(err);
    err = check(db, query, searchCursor, queryString, expectedIdsJson);
	MojTestErrCheck(err);
    searchCursor.close();

	//test for find
    err = check(db, query, cursor, queryString, expectedIdsJson);
    MojTestErrCheck(err);
    cursor.close();

	//2nd test
	queryString = _T("foo");
	expectedIdsJson = _T("[\"e\",\"f\",\"g\"]");
	err = initQuery(query, queryString);
	MojTestErrCheck(err);

    err = check(db, query, searchCursor, queryString, expectedIdsJson);
    MojTestErrCheck(err);
    searchCursor.close();

	//test for find
    err = check(db, query, cursor, queryString, expectedIdsJson);
    MojTestErrCheck(err);
    cursor.close();

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:41,代码来源:MojDbDistinctTest.cpp

示例9: findImpl

MojErr MojDb::findImpl(const MojDbQuery& query, MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req, MojDbOp op)
{
	MojLogTrace(s_log);

	if (cursor.isOpen())
		MojErrThrow(MojErrDbCursorAlreadyOpen);

	MojErr err = m_kindEngine.find(query, cursor, watcher, req, op);
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:12,代码来源:MojDb.cpp

示例10: find

MojErr MojDbIndex::find(MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
	MojAssert(isOpen());

	MojAutoPtr<MojDbQueryPlan> plan(new MojDbQueryPlan(*m_kindEngine));
	MojAllocCheck(plan.get());
	MojErr err = plan->init(cursor.query(), *this);
	MojErrCheck(err);
	if (watcher) {
		// we have to add the watch before beginning the txn or we may miss events
		MojAssert(cursor.txn() == NULL);
		err = addWatch(*plan, cursor, watcher, req);
		MojErrCheck(err);
	}
	if (!cursor.txn()) {
		MojDbStorageTxn* txn = req.txn();
		bool cursorOwnsTxn = !(req.batch() || txn);
		if (txn) {
			cursor.txn(txn, cursorOwnsTxn);
		} else {
			MojRefCountedPtr<MojDbStorageTxn> localTxn;
			err = m_collection->beginTxn(localTxn);
			MojErrCheck(err);
			cursor.txn(localTxn.get(), cursorOwnsTxn);
			req.txn(localTxn.get());
		}
	}
	cursor.m_dbIndex = this;	// for debugging
	err = m_collection->find(plan, cursor.txn(), cursor.m_storageQuery);
	MojErrCheck(err);
	cursor.m_watcher = watcher;
	
	return MojErrNone;
}
开发者ID:sailesharya,项目名称:db8,代码行数:35,代码来源:MojDbIndex.cpp

示例11: find

MojErr MojDbKindEngine::find(const MojDbQuery& query, MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req, MojDbOp op)
{
	MojAssert(isOpen());
	MojLogTrace(s_log);

	MojErr err = query.validate();
	MojErrCheck(err);
    // In order to find collate index, cursor needs kindEngine
    cursor.kindEngine(this);
	err = cursor.init(query);
	MojErrCheck(err);

	MojDbKind* kind = NULL;
	err = getKind(query.from().data(), kind);
	MojErrCheck(err);
	MojAssert(kind);
	err = kind->find(cursor, watcher, req, op);
	MojErrCheck(err);
	cursor.kindEngine(this);

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

示例12: LOG_TRACE

MojErr MojDbIndex::build(MojDbStorageTxn* txn)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
	MojAssert(isOpen());
	MojAssert(m_kind && m_kindEngine);
	MojAssert(m_props.size() > 1);

	// query for all existing objects of this type and add them to the index.
	MojDbQuery query;
	MojErr err = query.from(m_kind->id());
	MojErrCheck(err);
	if (m_includeDeleted) {
		err = query.includeDeleted();
		MojErrCheck(err);
	}

	MojDbCursor cursor;
	MojDbReq adminRequest(true);
	adminRequest.txn(txn);
	err = m_kindEngine->find(query, cursor, NULL, adminRequest, OpRead);
	MojErrCheck(err);

	for (;;) {
		MojObject obj;
		bool found = false;
		err = cursor.get(obj, found);
		MojErrCheck(err);
		if (!found)
			break;
		// add this object to the index
		err = update(&obj, NULL, txn, false);
		MojErrCheck(err);
	}
	err = cursor.close();
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:sailesharya,项目名称:db8,代码行数:38,代码来源:MojDbIndex.cpp

示例13: check

MojErr MojDbDistinctTest::check(MojDb& db, const MojDbQuery& query, MojDbCursor& cursor, const MojChar* queryString, const MojChar* expectedIdsJson)
{
	MojErr err = db.find(query, cursor);
	MojTestErrCheck(err);

	MojObjectBuilder builder;
	err = builder.beginArray();
	MojTestErrCheck(err);
	err = cursor.visit(builder);
	MojTestErrCheck(err);
	err = cursor.close();
	MojTestErrCheck(err);
	err = builder.endArray();
	MojTestErrCheck(err);
	MojObject results = builder.object();

	MojString json;
	err = results.toJson(json);
	MojTestErrCheck(err);

	MojObject expected;
	err = expected.fromJson(expectedIdsJson);
	MojTestErrCheck(err);

	// size check
	MojTestAssert(expected.size() == results.size());

	// value check
	MojObject::ConstArrayIterator j = results.arrayBegin();
	for (MojObject::ConstArrayIterator i = expected.arrayBegin();
			i != expected.arrayEnd(); ++i, ++j) {
		MojObject value;
		err = j->getRequired(queryString, value);
		MojTestErrCheck(err);
		MojTestAssert(*i == value);
	}
	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:38,代码来源:MojDbDistinctTest.cpp

示例14: MojAssert

MojErr MojDbKindEngine::loadKinds(MojDbReq& req)
{
	MojAssert(isOpen());
	MojAssertWriteLocked(m_db->m_schemaLock);
	MojLogTrace(s_log);

	MojDbQuery query;
	MojErr err = query.from(KindKindId);
	MojErrCheck(err);
	MojDbCursor cursor;
	err = m_db->find(query, cursor, req);
	MojErrCheck(err);

	for (;;) {
		MojObject obj;
		bool found = false;
		err = cursor.get(obj, found);
		MojErrCheck(err);
		if (!found)
			break;
		// load kind
		MojErr loadErr = err = putKind(obj, req);
		MojErrCatchAll(err) {
			MojString id;
			bool found = false;
			MojErr err = obj.get(MojDbServiceDefs::IdKey, id, found);
			MojErrCheck(err);
			MojString errStr;
			MojErrToString(loadErr, errStr);
			MojLogError(s_log, _T("error loading kind '%s' - %s"), id.data(), errStr.data());
		}
	}
	err = cursor.close();
	MojErrCheck(err);

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

示例15: find

MojErr MojDbKind::find(MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req, MojDbOp op)
{
	MojLogTrace(s_log);

	MojErr err = checkPermission(op, req);
	MojErrCheck(err);
	const MojDbQuery& query = cursor.query();
	MojDbIndex* index = indexForQuery(query);
	if (index == NULL)
		MojErrThrow(MojErrDbNoIndexForQuery);

	cursor.m_dbIndex = index;
	MojLogInfo(s_log, _T("Dbkind_find: Kind: %s, UsingIndex: %s, order: %s, limit: %d \n"), m_id.data(), index->name().data(), 
				query.order().data(), (int)query.limit());
	err = index->find(cursor, watcher, req);
	MojErrCheck(err);

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


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