本文整理汇总了C++中MojDbCursor::txn方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbCursor::txn方法的具体用法?C++ MojDbCursor::txn怎么用?C++ MojDbCursor::txn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDbCursor
的用法示例。
在下文中一共展示了MojDbCursor::txn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: merge
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;
}
示例3: delImpl
MojErr MojDb::delImpl(const MojDbQuery& quer, MojUInt32& countOut, MojDbReq& req, MojUInt32 flags)
{
MojLogTrace(s_log);
countOut = 0;
MojInt32 warns = 0;
MojDbQuery newQuery = quer;
MojUInt32 queryLimit = newQuery.limit();
if(newQuery.limit() == MojDbQuery::LimitDefault)
newQuery.limit(AutoBatchSize);
while(queryLimit > 0)
{
MojDbCursor cursor;
MojErr err = findImpl(newQuery, cursor, NULL, req, OpDelete);
MojErrCheck(err);
MojAssert(cursor.txn());
MojUInt32 count = 0;
MojUInt32 numberInBatch = 0;
bool found = false;
MojObject obj;
for (;;) {
MojDbStorageItem* item = NULL;
err = cursor.get(item, found);
// We simply skip ghost keys and continue; A warning is already written to the system log earlier
if (err == MojErrInternalIndexOnFind) {
warns++;
numberInBatch++;
continue;
}
MojErrCheck(err);
if (!found)
break;
err = item->toObject(obj, m_kindEngine);
MojErrCheck(err);
const MojObject& id = item->id();
MojObject deleted;
err = delObj(id, obj, item, deleted, req, flags);
MojErrCheck(err);
++count;
numberInBatch++;
}
if (warns > 0)
MojLogInfo(s_log, _T("delquery index_warnings: %s, count: %d\n"), newQuery.from().data(), warns);
countOut += count;
err = cursor.close();
MojErrCheck(err);
if(numberInBatch >= AutoBatchSize) // sing > - just in case something messed up
{
err = commitBatch(req);
MojErrCheck(err);
}
if(count == 0)
break;
queryLimit -= newQuery.limit();
if(queryLimit > AutoBatchSize)
newQuery.limit(AutoBatchSize);
else
newQuery.limit(queryLimit);
}
return MojErrNone;
}