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


C++ MojDbReq::begin方法代码示例

本文整理汇总了C++中MojDbReq::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbReq::begin方法的具体用法?C++ MojDbReq::begin怎么用?C++ MojDbReq::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MojDbReq的用法示例。


在下文中一共展示了MojDbReq::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildSample

TEST_F(ReqSuite, original)
{
    buildSample();
    mark1();

    // test visibility with update
    {
        MojDbReq req;

        // start transaction
        req.begin(&db, false);
        mark2(req);

        // visible within transaction
        checkMarkWithUpdate(50ul, -2, req);
    }

    // invisible after aborted transaction
    checkMarkWithUpdate(0ul, -2);

    // test visibility with delete
    mark1();
    {
        MojDbReq req;
        // start transaction
        req.begin(&db, false);

        deleteMark(50ul, -1, req);

        // visible within transaction
        {
            MojDbQuery query;
            MojAssertNoErr( query.from(_T("Test:1")) );
            MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpLessThan, 2) );

            MojObject update;

            MojUInt32 count = 0xbaddcafe;
            MojAssertNoErr( db.merge(query, update, count, MojDb::FlagNone, req) );
            EXPECT_EQ( 33ul, count);
        }
    }

    // invisible after aborted transaction
    {
        MojDbQuery query;
        MojAssertNoErr( query.from(_T("Test:1")) );
        MojAssertNoErr( query.where(_T("bar"), MojDbQuery::OpLessThan, 2) );

        MojObject update;
        // Note: should not set value to something that will introduce double-update

        MojUInt32 count = 0xbaddcafe;
        MojAssertNoErr( db.merge(query, update, count) );

        EXPECT_EQ( 83ul, count);
    }
}
开发者ID:KyleMaas,项目名称:db8,代码行数:58,代码来源:ReqTest.cpp

示例2: drop

MojErr MojDb::drop(const MojChar* path)
{
	MojAssert(path);
	MojLogTrace(s_log);

	MojErr err = requireOpen();
	MojErrCheck(err);

	MojDbReq req;
	err = req.begin(this, true);
	MojErrCheck(err);
	err = m_storageEngine->drop(path, req.txn());
	MojErrCheck(err);
	err = req.end();
	MojErrCheck(err);
	err = close();
	MojErrCheck(err);

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:20,代码来源:MojDb.cpp

示例3: open

MojErr MojDb::open(const MojChar* path, MojDbStorageEngine* engine)
{
	MojAssert(path);
	MojLogTrace(s_log);

	MojErr err = requireNotOpen();
	MojErrCheck(err);

	MojLogInfo(s_log, _T("opening: '%s'..."), path);

	MojAutoCloser<MojDb> closer(this);
	m_isOpen = true;

	// check the database version number and bail if there's a mismatch
	err = checkDbVersion(path);
	MojErrCheck(err);
	// engine
	if (engine == NULL) {
		err = createEngine();
		MojErrCheck(err);
		MojAssert(m_storageEngine.get());
		err = m_storageEngine->configure(m_conf);
		MojErrCheck(err);
		err = m_storageEngine->open(path);
		MojErrCheck(err);
	} else {
		m_storageEngine.reset(engine);
	}

	MojDbReq req;
	err = req.begin(this, true);
	MojErrCheck(err);

	// db
    MojLogInfo(s_log, _T("Open Database: '%s'"), ObjDbName);
	err = m_storageEngine->openDatabase(ObjDbName, req.txn(), m_objDb);
	MojErrCheck(err);
	MojAssert(m_objDb.get());

	// seq
    MojLogInfo(s_log, _T("Open Database: '%s'"), IdSeqName);
	err = m_storageEngine->openSequence(IdSeqName, req.txn(), m_idSeq);
	MojErrCheck(err);
	MojAssert(m_idSeq.get());

	// kinds
    MojLogInfo(s_log, _T("Open Kind Engine"));
	err = m_kindEngine.open(this, req);
    MojLogInfo(s_log, _T("Kind Opened..."));
	MojErrCheck(err);

	// perms
    MojLogInfo(s_log, _T("Open Permissions"));
	err = m_permissionEngine.open(m_conf, this, req);
	MojErrCheck(err);

	// quota
	err = m_quotaEngine.open(m_conf, this, req);
	MojErrCheck(err);
	err = req.end();
	MojErrCheck(err);

	// idgen
	err = m_idGenerator.init();
	MojErrCheck(err);

	closer.release();
	MojLogInfo(s_log, _T("open completed"));

	return MojErrNone;
}
开发者ID:KyleMaas,项目名称:db8,代码行数:71,代码来源:MojDb.cpp

示例4: 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"));
//.........这里部分代码省略.........
开发者ID:feniksa,项目名称:indb8,代码行数:101,代码来源:MojDbTxnTest.cpp


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