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


C++ MojDbQuery::fromObject方法代码示例

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


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

示例1: assertCanAnswer

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;
}
开发者ID:BigBlueHat,项目名称:db8,代码行数:35,代码来源:MojDbIndexTest.cpp

示例2: handleWatch

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

示例3: handleMerge

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

	MojErr err = MojErrNone;
	MojUInt32 count = 0;
	MojObject obj;
	

	if (payload.get(MojDbServiceDefs::ObjectsKey, obj)) {
		if (payload.contains(MojDbServiceDefs::QueryKey))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: cannot have both an objects param and a query param"));
		MojObject::ArrayIterator begin;
		bool ignoreM = false;
		payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM);
		MojUInt32 mflags = MojDb::FlagNone;
		if (ignoreM)
			mflags = mflags | MojDb::FlagIgnoreMissing;
		err = obj.arrayBegin(begin);
		MojErrCheck(err);
		MojObject::ConstArrayIterator end = obj.arrayEnd();
		err = m_db.merge(begin, end, mflags, req);
		MojErrCheck(err);
		err = formatPut(msg, begin, end); // TO DO: we need to drop non-existing objects
		MojErrCheck(err);
	}
	else if (payload.get(MojDbServiceDefs::QueryKey, obj)) {
		MojObject props;
		err = payload.getRequired(MojDbServiceDefs::PropsKey, props);
		MojErrCheck(err);
		bool ignoreM = false;
		if (payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: ignoreMissing - invalid option for merge query"));

		MojDbQuery query;
		err = query.fromObject(obj);
		MojErrCheck(err);
		MojUInt32 queryCount = 0;
		err = m_db.merge(query, props, queryCount, MojDb::FlagNone, req);
		MojErrCheck(err);
		count += queryCount;
		err = formatCount(msg, count);
		MojErrCheck(err);
	}
	else {
		MojErrThrowMsg(MojErrInvalidArg, _T("db: either objects or query param required for merge"));
	}

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

示例4: handleDel

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

	MojErr err = MojErrNone;
	MojUInt32 count = 0;
	MojUInt32 flags = MojDb::FlagNone;

	bool purge = false;
	if (payload.get(MojDbServiceDefs::PurgeKey, purge) && purge) {
		flags |= MojDb::FlagPurge;
	}

	MojObject obj;
	if (payload.get(MojDbServiceDefs::IdsKey, obj)) {
		if (payload.contains(MojDbServiceDefs::QueryKey))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: cannot have both an objects argument and a query argument"));
		MojObject deletedObjects;
		err = m_db.del(obj.arrayBegin(), obj.arrayEnd(), count, deletedObjects, flags, req);
		MojErrCheck(err);
		err = formatPut(msg, deletedObjects.arrayBegin(), deletedObjects.arrayEnd());
		MojErrCheck(err);
	}
	else if (payload.get(MojDbServiceDefs::QueryKey, obj)) {
		MojDbQuery query;
		err = query.fromObject(obj);
		MojErrCheck(err);
		MojUInt32 queryCount = 0;
		err = m_db.del(query, queryCount, flags, req);
		MojErrCheck(err);
		count += queryCount;
		err = formatCount(msg, count);
		MojErrCheck(err);
	}
	return MojErrNone;
}
开发者ID:anttiharju-owo,项目名称:db8,代码行数:37,代码来源:MojDbServiceHandler.cpp

示例5: findImpl

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