示例#1
0
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;
}
示例#2
0
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;
}