本文整理汇总了C++中MojDb::watch方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDb::watch方法的具体用法?C++ MojDb::watch怎么用?C++ MojDb::watch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDb
的用法示例。
在下文中一共展示了MojDb::watch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cancelTest
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;
}
示例2: eqTest
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;
}