本文整理汇总了C++中MojDb::putKind方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDb::putKind方法的具体用法?C++ MojDb::putKind怎么用?C++ MojDb::putKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDb
的用法示例。
在下文中一共展示了MojDb::putKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testKindPermissions
MojErr MojDbPermissionTest::testKindPermissions(MojDb& db)
{
MojObject kind;
MojErr err = kind.fromJson(MojTestKind1);
MojTestErrCheck(err);
// new kind, mismatched owner and caller
MojDbReq req(false);
err = req.domain(_T("com.bar"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// new kind, matched owner and caller
err = req.domain(_T("com.foo"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrCheck(err);
// existing kind, matched owner and caller
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrCheck(err);
// existing kind, mismatched owner and caller
err = req.domain(_T("com.bar"));
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
// delKind, mismatched owner and caller
MojString id;
err = id.assign(_T("PermissionTest:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(id, found, MojDb::FlagNone, req);
MojTestErrExpected(err, MojErrDbPermissionDenied);
return MojErrNone;
}
示例2: testAdminPermissions
MojErr MojDbPermissionTest::testAdminPermissions(MojDb& db)
{
MojObject permission;
MojErr err = permission.fromJson(MojTestAdminPermission1);
MojTestErrCheck(err);
err = db.putPermissions(&permission, &permission + 1);
MojTestErrCheck(err);
MojDbReq reqAdmin(false);
err = reqAdmin.domain(_T("com.admin"));
MojTestErrCheck(err);
// put kind with non-matching owner with admin role
MojObject kind;
err = kind.fromJson(MojTestKind1);
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
MojTestErrCheck(err);
err = kind.fromJson(MojTestKind2);
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
MojTestErrCheck(err);
return MojErrNone;
}
示例3: timeUpdateKind
MojErr MojDbPerfUpdateTest::timeUpdateKind(MojDb& db, const MojChar* kindJson, MojObject& kindObj, MojTime& addIndexTime, MojTime& dropIndexTime)
{
MojTime startTime;
MojTime endTime;
MojObject origKindObj;
MojErr err = origKindObj.fromJson(kindJson);
MojTestErrCheck(err);
for (MojUInt64 i = 0; i < numUpdateKindIterations; i++) {
err = MojGetCurrentTime(startTime);
MojTestErrCheck(err);
bool found;
err = kindObj.del(MojDb::RevKey, found);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
err = MojGetCurrentTime(endTime);
MojTestErrCheck(err);
addIndexTime += (endTime - startTime);
totalTestTime += (endTime - startTime);
err = MojGetCurrentTime(startTime);
MojTestErrCheck(err);
err = origKindObj.del(MojDb::RevKey, found);
MojTestErrCheck(err);
err = db.putKind(origKindObj);
MojTestErrCheck(err);
err = MojGetCurrentTime(endTime);
MojTestErrCheck(err);
dropIndexTime += (endTime - startTime);
totalTestTime += (endTime - startTime);
}
return MojErrNone;
}
示例4: run
MojErr MojDbSearchTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(MojSearchKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojSearchTestObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchTestObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = simpleTest(db);
MojTestErrCheck(err);
err = filterTest(db);
MojTestErrCheck(err);
// add kind for page test
err = kindObj.fromJson(MojSearchKindStr2);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects for page test
for (MojSize i = 0; i < sizeof(MojSearchTestObjects2) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchTestObjects2[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = pageTest(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例5: run
MojErr MojDbDistinctTest::run()
{
// TODO : description, youngseung.ji
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(MojDistinctKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojDistinctTestObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojDistinctTestObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
// Start testing
err = simpleTest(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例6: testErrors
MojErr MojDbQuotaTest::testErrors()
{
#ifdef MOJ_USE_BDB
MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbBerkeleyEngine());
#elif MOJ_USE_LDB
MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbLevelEngine());
#else
MojRefCountedPtr<MojDbStorageEngine> engine;
#endif
MojAllocCheck(engine.get());
MojRefCountedPtr<MojDbTestStorageEngine> testEngine(new MojDbTestStorageEngine(engine.get()));
MojAllocCheck(testEngine.get());
MojErr err = testEngine->open(MojDbTestDir);
MojTestErrCheck(err);
MojDb db;
err = db.open(MojDbTestDir, testEngine.get());
MojTestErrCheck(err);
// test that failed put does not affect quota
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage1);
MojTestErrCheck(err);
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
err = put(db, MojTestKind3Objects[1]);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage2 == quotaUsage1);
// test that failed putQuota has no effect
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
MojObject obj;
err = obj.fromJson(_T("{\"owner\":\"com.foo.boo\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage3);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 == quotaUsage1);
// test that failed putKind has no effect
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
err = obj.fromJson(MojTestKind3Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage4 == quotaUsage1);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例7: run
MojErr MojDbQuotaTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
MojObject obj;
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = testUsage(db);
MojTestErrCheck(err);
err = testMultipleQuotas(db);
MojTestErrCheck(err);
err = testEnforce(db);
MojTestErrCheck(err);
err = db.close();
MojErrCheck(err);
err = testErrors();
MojTestErrCheck(err);
return MojErrNone;
}
示例8: addKind
/**
* addKind
*/
MojErr MojDbShardManagerTest::addKind (const MojChar* strKind, MojDb& db)
{
MojObject kind;
MojErr err = kind.fromJson(strKind);
MojErrCheck(err);
err = db.putKind(kind);
MojErrCheck(err);
return MojErrNone;
}
示例9: SetUp
void SetUp()
{
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
path = std::string(tempFolder) + '/'
+ test_info->test_case_name() + '-' + test_info->name();
// open
MojAssertNoErr( db.open(path.c_str()) );
// add type
MojObject obj;
MojAssertNoErr( obj.fromJson(MojKindStr) );
MojAssertNoErr( db.putKind(obj) );
}
示例10: run
MojErr MojDbWatchTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
MojObject type;
err = type.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(type);
MojTestErrCheck(err);
// eq
err = eqTest(db);
MojTestErrCheck(err);
// gt
err = gtTest(db);
MojTestErrCheck(err);
// lt
err = ltTest(db);
MojTestErrCheck(err);
// cancel
err = cancelTest(db);
MojTestErrCheck(err);
// range
err = rangeTest(db);
MojTestErrCheck(err);
// pages
err = pageTest(db);
MojTestErrCheck(err);
// make sure we're not hanging onto watcher references
MojTestAssert(TestWatcher::s_instanceCount == 0);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例11: run
MojErr MojDbSearchCacheTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(SearchCacheKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojSearchCacheObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchCacheObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = testQueryKey();
MojTestErrCheck(err);
err = operatorTest(db);
MojTestErrCheck(err);
/*** :: TODO :: make query scenario
err = queryTest(db);
MojTestErrCheck(err);
***/
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例12: 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);
//.........这里部分代码省略.........
示例13: testMultipleQuotas
MojErr MojDbQuotaTest::testMultipleQuotas(MojDb& db)
{
// quota for com.foo.baz
MojObject obj;
MojErr err = obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
// register kinds
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = obj.fromJson(MojTestKind2Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
// put object of kind1 and kind2
err = put(db, MojTestKind1Objects[0]);
MojTestErrCheck(err);
err = put(db, MojTestKind2Objects[0]);
MojTestErrCheck(err);
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage1 > 0);
MojTestAssert(quotaUsage2 == 0);
// change owner of kind2 to com.foo.baz
err = obj.fromJson(MojTestKind2Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3);
MojTestErrCheck(err);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 > 0);
MojTestAssert(quotaUsage3 == quotaUsage4);
// make kind2 inherit from kind1
err = obj.fromJson(MojTestKind2Str3);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 quotaUsage5 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5);
MojTestErrCheck(err);
MojInt64 quotaUsage6 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage6);
MojTestErrCheck(err);
MojTestAssert(quotaUsage5 > quotaUsage1);
MojTestAssert(quotaUsage6 == 0);
// kind3 and object
err = obj.fromJson(MojTestKind3Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = put(db, MojTestKind3Objects[0]);
MojTestErrCheck(err);
MojInt64 quotaUsage7 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7);
MojTestErrCheck(err);
MojTestAssert(quotaUsage7 == quotaUsage5);
// wildcard
err = obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
MojInt64 quotaUsage8 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8);
MojTestErrCheck(err);
MojInt64 quotaUsage9 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage9);
MojTestErrCheck(err);
MojTestAssert(quotaUsage8 == quotaUsage5);
MojTestAssert(quotaUsage9 > 0);
return MojErrNone;
}
示例14: testUsage
MojErr MojDbQuotaTest::testUsage(MojDb& db)
{
// put quota
MojObject obj;
MojErr err = obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
// empty
MojInt64 kindUsage = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage);
MojTestErrCheck(err);
MojTestAssert(kindUsage == 0);
MojInt64 quotaUsage = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage);
MojTestErrCheck(err);
MojTestAssert(quotaUsage == 0);
// new obj
err = put(db, MojTestKind1Objects[0]);
MojTestErrCheck(err);
MojInt64 kindUsage1 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage1);
MojTestErrCheck(err);
MojTestAssert(kindUsage1 > 0);
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojTestAssert(quotaUsage1 > 0);
// add prop to existing obj
err = obj.fromJson(MojTestKind1Objects[0]);
MojTestErrCheck(err);
err = obj.put(_T("bar"), 2);
MojTestErrCheck(err);
err = db.put(obj, MojDb::FlagForce);
MojTestErrCheck(err);
MojInt64 kindUsage2 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage2);
MojTestErrCheck(err);
MojTestAssert(kindUsage2 > kindUsage1);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage2 > quotaUsage1);
// add 2nd obj
err = put(db, MojTestKind1Objects[1]);
MojTestErrCheck(err);
MojInt64 kindUsage3 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage3);
MojTestErrCheck(err);
MojTestAssert(kindUsage3 > kindUsage2);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 > quotaUsage2);
// del first obj
bool found = false;
err = db.del(1, found, MojDb::FlagPurge);
MojTestErrCheck(err);
MojTestAssert(found);
MojInt64 kindUsage4 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage4);
MojTestErrCheck(err);
MojTestAssert(kindUsage4 == kindUsage3 - kindUsage2);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage4 == quotaUsage3 - quotaUsage2);
// add index
err = obj.fromJson(MojTestKind1Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 kindUsage5 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage5);
MojTestErrCheck(err);
MojTestAssert(kindUsage5 > kindUsage4);
MojInt64 quotaUsage5 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5);
MojTestErrCheck(err);
MojTestAssert(quotaUsage5 > quotaUsage4);
// update locale
err = db.updateLocale(_T("FR_fr"));
MojTestErrCheck(err);
err = db.updateLocale(_T("EN_us"));
MojTestErrCheck(err);
MojInt64 kindUsage6 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage6);
MojTestErrCheck(err);
MojTestAssert(kindUsage6 == kindUsage5);
MojInt64 quotaUsage6 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage6);
MojTestErrCheck(err);
MojTestAssert(quotaUsage6 == quotaUsage5);
// drop index
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 kindUsage7 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage7);
//.........这里部分代码省略.........
示例15: run
MojErr MojDbTxnTest::run()
{
MojErr err;
MojDb db;
err = MojDbTestEnv::run(MojDbTestDir);
MojTestErrCheck(err);
// open
err = db.open(MojDbTestDir, env());
MojTestErrCheck(err);
// add type
MojObject obj;
err = obj.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
for (int i = 0; i < 100; ++i) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, _T("Test:1"));
MojTestErrCheck(err);
err = obj.put(_T("foo"), (i + 25) % 100);
MojTestErrCheck(err);
err = obj.put(_T("bar"), i % 3);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
// db: x0 = (25, 0), (26, 1), (27, 2), (28, 0) .. x74 = (99,2), x75 = (0,0) .. x99 = (24,0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("foo"), MojDbQuery::OpLessThan, 50);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -1);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// db: x0 = (25, -1) .. x24 = (49,-1), x25 = (50,1)i .. x74 = (99,2), x75 = (0,-1) .. x99 = (24, -1)
// test visibility with update
{
MojDbReq req;
// start transaction
req.begin(&db, false);
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -1);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
// txn: x0 = (25, -2) .. x24 = (49,-2), x25 = (50,1) .. x74 = (99,2), x75 = (0,-2) .. x99 = (24, -2)
// visible within transaction
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
}
// With BerkeleyDB parallel transaction is locked
// invisible outside of transaction
if (engineName().compare(_T("leveldb")) == 0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
//.........这里部分代码省略.........