示例#1
0
        public void GetCursorWithImplicitTxn(string home,
                                             string dbFile, bool ifConfig)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create   = true;
            envConfig.UseCDB   = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            RecnoDatabaseConfig dbConfig =
                new RecnoDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env      = env;
            RecnoDatabase db = RecnoDatabase.Open(dbFile,
                                                  dbConfig);

            RecnoCursor cursor;

            if (ifConfig == false)
            {
                cursor = db.Cursor();
            }
            else
            {
                cursor = db.Cursor(new CursorConfig());
            }

            cursor.Close();
            db.Close();
            env.Close();
        }
示例#2
0
        public void GetCursorWithExplicitTxn(string home,
                                             string dbFile, bool ifConfig)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create   = true;
            envConfig.UseTxns  = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            Transaction         openTxn  = env.BeginTransaction();
            RecnoDatabaseConfig dbConfig =
                new RecnoDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env      = env;
            RecnoDatabase db = RecnoDatabase.Open(dbFile,
                                                  dbConfig, openTxn);

            openTxn.Commit();

            Transaction cursorTxn = env.BeginTransaction();
            RecnoCursor cursor;

            if (ifConfig == false)
            {
                cursor = db.Cursor(cursorTxn);
            }
            else
            {
                cursor = db.Cursor(new CursorConfig(), cursorTxn);
            }
            cursor.Close();
            cursorTxn.Commit();
            db.Close();
            env.Close();
        }