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


C++ MojDb::watch方法代码示例

本文整理汇总了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;
}
开发者ID:halfhalo,项目名称:db8,代码行数:48,代码来源:MojDbWatchTest.cpp

示例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;
}
开发者ID:halfhalo,项目名称:db8,代码行数:97,代码来源:MojDbWatchTest.cpp


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