本文整理汇总了C++中MojDb::purge方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDb::purge方法的具体用法?C++ MojDb::purge怎么用?C++ MojDb::purge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDb
的用法示例。
在下文中一共展示了MojDb::purge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
MojErr MojDbPurgeTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// put type
MojObject obj;
err = obj.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojObject revNums[10];
MojObject ids[10];
//put 10 objects in the db
for(int i = 0; i < 10; i++) {
err = obj.fromJson(MojTestObjStr1);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
// get _rev and id
MojObject rev;
err = obj.getRequired(MojDb::RevKey, rev);
MojTestErrCheck(err);
revNums[i] = rev;
MojObject id;
err = obj.getRequired(MojDb::IdKey, id);
MojTestErrCheck(err);
ids[i] = id;
}
//purge now, there are no RevTimestamp entries
MojUInt32 count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 10, 1, -1);
MojTestErrCheck(err);
//create a RevTimestamp entry - that's not more than PurgeNumDays days ago
MojTime time;
err = MojGetCurrentTime(time);
MojTestErrCheck(err);
err = createRevTimestamp(db, revNums[0], time.microsecs());
MojTestErrCheck(err);
//purge now, there are no RevTimestamp entries that are more than
//PurgeNumDays ago, so nothing should be purged
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 10, 3, -1);
MojTestErrCheck(err);
//create a RevTimestamp entry for more than PurgeNumDays days ago
err = MojGetCurrentTime(time);
MojTestErrCheck(err);
err = createRevTimestamp(db, revNums[9], time.microsecs() - (((MojInt64)40) * MojTime::UnitsPerDay));
MojTestErrCheck(err);
//purge now, since nothing has been deleted, nothing should be purged,
//but the RevTimestamp object should be deleted
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 10, 4, -1);
MojTestErrCheck(err);
//delete something - this will set its revision number higher
bool found;
err = db.del(ids[0], found);
MojTestErrCheck(err);
MojTestAssert(found == true);
//purge now, since nothing has been deleted prior to the revision
//number, nothing should be purged
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 9, 5, -1);
MojTestErrCheck(err);
//delete another object
err = db.del(ids[1], found);
MojTestErrCheck(err);
MojTestAssert(found == true);
//create a RevTimestamp entry for more than PurgeNumDays days ago,
//with the rev number of the 1st obj we deleted
MojDbQuery query;
err = query.from(_T("PurgeTest:1"));
MojTestErrCheck(err);
err = query.where(MojDb::IdKey, MojDbQuery::OpEq, ids[0]);
MojTestErrCheck(err);
err = query.includeDeleted();
MojTestErrCheck(err);
//.........这里部分代码省略.........
示例2: delKindTest
MojErr MojDbPurgeTest::delKindTest(MojDb& db)
{
// start from scratch - purge everything
MojUInt32 count = 0;
MojErr err = db.purge(count, 0);
MojTestErrCheck(err);
MojTestAssert(count > 0);
// purge again, make sure nothing is left
err = db.purge(count, 0);
MojTestErrCheck(err);
MojTestAssert(count == 0);
// make sure at least 2 objects exist
MojDbQuery q;
err = q.from(_T("PurgeTest:1"));
MojTestErrCheck(err);
MojDbCursor cursor;
err = db.find(q, cursor);
MojTestErrCheck(err);
MojUInt32 objCount;
err = cursor.count(objCount);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
if (objCount <= 1) {
for (int i = objCount; i < 2; i++) {
MojObject obj;
err = obj.fromJson(MojTestObjStr1);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
objCount++;
}
}
// delete half the objects
q.limit(objCount / 2);
MojUInt32 delCount;
err = db.del(q, delCount);
MojTestErrCheck(err);
// delete the kind
MojString idStr;
err = idStr.assign(_T("PurgeTest:1"));
MojTestErrCheck(err);
MojObject id(idStr);
bool found;
err = db.delKind(id, found);
MojTestErrCheck(err);
MojTestAssert(found);
/*MojUInt32 deletedObjCount;
err = q.where(_T("_del"), MojDbQuery::OpEq, true);
MojTestErrCheck(err);
q.includeDeleted(true);
err = db.find(q, cursor);
MojTestErrCheck(err);
err = cursor.count(deletedObjCount);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
// now all the objects should be deleted
MojTestAssert(deletedObjCount == objCount);*/
// purge now
err = db.purge(count, 0);
MojTestErrCheck(err);
return MojErrNone;
}