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


C# DatabaseEnvironment.BeginTransaction方法代码示例

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


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

示例1: SetUpEnvWithTxnAndLocking

        public static void SetUpEnvWithTxnAndLocking(string envHome,
		    out DatabaseEnvironment env, out Transaction txn,
		    uint maxLock, uint maxLocker, uint maxObject, uint partition)
        {
            // Configure env and locking subsystem.
            LockingConfig lkConfig = new LockingConfig();

            /*
             * If the maximum number of locks/lockers/objects
             * is given, then the LockingConfig is set. Unless,
             * it is not set to any value.
             */
            if (maxLock != 0)
                lkConfig.MaxLocks = maxLock;
            if (maxLocker != 0)
                lkConfig.MaxLockers = maxLocker;
            if (maxObject != 0)
                lkConfig.MaxObjects = maxObject;
            if (partition != 0)
                lkConfig.Partitions = partition;

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.UseLocking = true;
            envConfig.NoLocking = false;
            env = DatabaseEnvironment.Open(envHome, envConfig);
            txn = env.BeginTransaction();
        }
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:32,代码来源:TransactionTest.cs

示例2: OpenNewSequenceInEnv

        public void OpenNewSequenceInEnv(string home, string dbname,
		    out DatabaseEnvironment env, out BTreeDatabase db,
		    out Sequence seq)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLogging = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            Transaction openTxn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            db = BTreeDatabase.Open(dbname + ".db", dbConfig,
                openTxn);
            openTxn.Commit();

            Transaction seqTxn = env.BeginTransaction();
            SequenceConfig seqConfig = new SequenceConfig();
            seqConfig.BackingDatabase = db;
            seqConfig.Creation = CreatePolicy.ALWAYS;
            seqConfig.Decrement = false;
            seqConfig.FreeThreaded = true;
            seqConfig.Increment = true;
            seqConfig.InitialValue = 0;
            seqConfig.key = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("key"));
            seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
            seqConfig.Wrap = true;
            seq = new Sequence(seqConfig);
            seqTxn.Commit();
        }
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:36,代码来源:SequenceTest.cs

示例3: OpenSecDBInTxn

        public void OpenSecDBInTxn(string home, string dbFileName, 
		    string dbSecFileName, out DatabaseEnvironment env,
		    out BTreeDatabase db, out SecondaryBTreeDatabase secDB)
        {
            // Open environment.
            DatabaseEnvironmentConfig envCfg =
                new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.UseLocking = true;
            envCfg.UseLogging = true;
            envCfg.UseMPool = true;
            envCfg.UseTxns = true;
            env = DatabaseEnvironment.Open(
                home, envCfg);

            // Open primary and secondary database in a transaction.
            Transaction openTxn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            dbConfig.PageSize = 4096;
            dbConfig.Duplicates = DuplicatesPolicy.NONE;
            dbConfig.ReadUncommitted = true;
            db = BTreeDatabase.Open(dbFileName, dbConfig,
                openTxn);
            openTxn.Commit();

            openTxn = env.BeginTransaction();
            SecondaryBTreeDatabaseConfig secConfig =
                new SecondaryBTreeDatabaseConfig(db,
                new SecondaryKeyGenDelegate(SecondaryKeyGen));
            secConfig.Creation = CreatePolicy.IF_NEEDED;
            secConfig.Duplicates = DuplicatesPolicy.SORTED;
            secConfig.Env = env;
            secConfig.ReadUncommitted = true;
            secDB = SecondaryBTreeDatabase.Open(dbSecFileName,
                secConfig, openTxn);
            openTxn.Commit();
        }
开发者ID:mcandre,项目名称:db,代码行数:40,代码来源:SecondaryCursorTest.cs

示例4: WriteRecordsInTxn

        public void WriteRecordsInTxn(BTreeDatabase db, 
		    DatabaseEnvironment env)
        {
            Transaction txn = env.BeginTransaction();
            /*
             * Write ten records into the database. The records
             * from 1st to 5th and 8th to 10th are unique in the
             * database. The data in the 6th and 7th records
             * are the same.
             */
            for (int i = 0; i < 10; i++)
            {
                if (i == 5 || i == 6)
                    db.Put(new DatabaseEntry(
                        BitConverter.GetBytes(i)),
                        new DatabaseEntry(
                        BitConverter.GetBytes((int)10)), txn);
                else
                    db.Put(new DatabaseEntry(
                        BitConverter.GetBytes(i)),
                        new DatabaseEntry(BitConverter.GetBytes(i)), txn);
            }

            txn.Commit();
        }
开发者ID:mcandre,项目名称:db,代码行数:25,代码来源:SecondaryCursorTest.cs

示例5: MoveWithRMW

        public void MoveWithRMW(string home, string name)
        {
            paramEnv = null;
            paramDB = null;

            // Open the environment.
            DatabaseEnvironmentConfig envCfg =
                new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.FreeThreaded = true;
            envCfg.UseLocking = true;
            envCfg.UseLogging = true;
            envCfg.UseMPool = true;
            envCfg.UseTxns = true;
            paramEnv = DatabaseEnvironment.Open(home, envCfg);

            // Open database in transaction.
            Transaction openTxn = paramEnv.BeginTransaction();
            BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
            cfg.Creation = CreatePolicy.ALWAYS;
            cfg.Env = paramEnv;
            cfg.FreeThreaded = true;
            cfg.PageSize = 4096;
            cfg.Duplicates = DuplicatesPolicy.UNSORTED;
            paramDB = BTreeDatabase.Open(name + ".db", cfg, openTxn);
            openTxn.Commit();

            /*
             * Put 10 different, 2 duplicate and another different
             * records into database.
             */
            Transaction txn = paramEnv.BeginTransaction();
            for (int i = 0; i < 13; i++)
            {
                DatabaseEntry key, data;
                if (i == 10 || i == 11)
                {
                    key = new DatabaseEntry(
                        ASCIIEncoding.ASCII.GetBytes("key"));
                    data = new DatabaseEntry(
                        ASCIIEncoding.ASCII.GetBytes("data"));
                }
                else
                {
                    key = new DatabaseEntry(
                        BitConverter.GetBytes(i));
                    data = new DatabaseEntry(
                        BitConverter.GetBytes(i));
                }
                paramDB.Put(key, data, txn);
            }

            txn.Commit();

            // Get a event wait handle.
            signal = new EventWaitHandle(false, EventResetMode.ManualReset);

            /*
             * Start RdMfWt() in two threads. RdMfWt() reads
             * and writes data into database.
             */
            Thread t1 = new Thread(new ThreadStart(RdMfWt));
            Thread t2 = new Thread(new ThreadStart(RdMfWt));
            t1.Start();
            t2.Start();

            /*
             * Give both threads time to read before signalling
             * them to write.
             */
            Thread.Sleep(1000);

            // Invoke the write operation in both threads.
            signal.Set();

            // Return the number of deadlocks.
            while (t1.IsAlive || t2.IsAlive)
            {
                /*
                 * Give both threads time to write before
                 * counting the number of deadlocks.
                 */
                Thread.Sleep(1000);
                uint deadlocks = paramEnv.DetectDeadlocks(
                   DeadlockPolicy.DEFAULT);

                // Confirm that there won't be any deadlock.
                Assert.AreEqual(0, deadlocks);
            }

            t1.Join();
            t2.Join();
            paramDB.Close();
            paramEnv.Close();
        }
开发者ID:gildafnai82,项目名称:craq,代码行数:95,代码来源:CursorTest.cs

示例6: GetCursorInBtreeDBInTDS

        public static void GetCursorInBtreeDBInTDS(
		    string home, string name,
		    CursorConfig cursorConfig,
		    out DatabaseEnvironment env, out BTreeDatabase db,
		    out BTreeCursor cursor, out Transaction txn)
        {
            string dbFileName = name + ".db";

            Configuration.ClearDir(home);

            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            envConfig.NoMMap = false;
            envConfig.UseLocking = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            // Begin a transaction.
            txn = env.BeginTransaction();

            /*
             * Open an btree database. The underlying database
             * should be opened with ReadUncommitted if the
             * cursor's isolation degree will be set to be 1.
             */
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            if (cursorConfig.IsolationDegree == Isolation.DEGREE_ONE)
                dbConfig.ReadUncommitted = true;

            db = BTreeDatabase.Open(dbFileName, dbConfig, txn);

            // Get a cursor in the transaction.
            cursor = db.Cursor(cursorConfig, txn);
        }
开发者ID:gildafnai82,项目名称:craq,代码行数:39,代码来源:CursorTest.cs

示例7: TestSnapshotIsolation

        public void TestSnapshotIsolation()
        {
            BTreeDatabaseConfig dbConfig;
            DatabaseEntry key, data;
            DatabaseEnvironmentConfig envConfig;
            Thread readThread, updateThread;
            Transaction txn;

            updateTxn = null;
            readTxn = null;
            paramDB = null;
            paramEnv = null;
            testName = "TestSnapshotIsolation";
            testHome = testFixtureHome + "/" + testName;

            Configuration.ClearDir(testHome);

            /*
             * Open environment with DB_MULTIVERSION
             * which is required by DB_TXN_SNAPSHOT.
             */
            envConfig = new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMVCC = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            envConfig.UseLocking = true;
            envConfig.TxnTimeout = 1000;
            paramEnv = DatabaseEnvironment.Open(
                testHome, envConfig);
            paramEnv.DetectDeadlocks(DeadlockPolicy.YOUNGEST);

            /*
             * Open a transactional database and put 1000 records
             * into it within transaction.
             */
            txn = paramEnv.BeginTransaction();
            dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.UseMVCC = true;
            dbConfig.Env = paramEnv;
            paramDB = BTreeDatabase.Open(
                testName + ".db", dbConfig, txn);
            for (int i = 0; i < 256; i++)
            {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                data = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                paramDB.Put(key, data, txn);
            }
            txn.Commit();

            /*
             * Begin two threads, read and update thread.
             * The update thread runs a update transaction
             * using full read/write locking. The read thread
             * set DB_TXN_SNAPSHOT on read-only cursor.
             */
            readThread = new Thread(new ThreadStart(ReadTxn));
            updateThread = new Thread(new ThreadStart(UpdateTxn));
            updateThread.Start();
            Thread.Sleep(1000);
            readThread.Start();
            readThread.Join();
            updateThread.Join();

            // Commit transacion in both two threads.
            if (updateTxn != null)
                updateTxn.Commit();
            if (readTxn != null)
                readTxn.Commit();

            /*
             * Confirm that the overwrite operation works.
             */
            ConfirmOverwrite();

            paramDB.Close();
            paramEnv.Close();
        }
开发者ID:gildafnai82,项目名称:craq,代码行数:81,代码来源:CursorTest.cs

示例8: PutRecordWithTxn

        public void PutRecordWithTxn(out DatabaseEnvironment env,
		    string home, string dbName, out Transaction txn)
        {
            BTreeDatabase db;

            // Open a new environment and begin a transaction.
            SetUpTransactionalEnv(home, out env);
            TransactionConfig txnConfig = new TransactionConfig();
            txnConfig.Name = "Transaction";
            txn = env.BeginTransaction(txnConfig);
            Assert.AreEqual("Transaction", txn.Name);

            // Open a new database within the transaction.
            OpenBtreeDBInEnv(dbName + ".db", env, out db, true, txn);

            // Write to the database within the transaction.
            WriteOneIntoBtreeDBWithTxn(db, txn);

            // Close the database.
            db.Close();
        }
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:21,代码来源:TransactionTest.cs

示例9: InitDbs

        /* Initialize environment and database (s) */
        public void InitDbs()
        {
            /* Open transactional environment */
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            envConfig.UseLocking = true;
            envConfig.UseLogging = true;
            envConfig.UseTxns = true;
            envConfig.LockSystemCfg = new LockingConfig();
            envConfig.LockSystemCfg.MaxLocks =
                (this.dups == 0) ?
                (uint)this.num :
                (uint)(this.num * this.dups);
            envConfig.LockSystemCfg.MaxObjects =
                envConfig.LockSystemCfg.MaxLocks;
            if (this.cachesize != 0) {
                envConfig.MPoolSystemCfg = new MPoolConfig();
                envConfig.MPoolSystemCfg.CacheSize =
                    new CacheInfo(0, this.cachesize, 1);
            }

            try {
                env = DatabaseEnvironment.Open(home, envConfig);
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
                System.Environment.Exit(1);
            }

            Transaction txn = env.BeginTransaction();

            try {
                /* Open primary db in transaction */
                BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
                dbConfig.Env = env;
                dbConfig.Creation = CreatePolicy.IF_NEEDED;
                if (this.pagesize != 0)
                    dbConfig.PageSize = this.pagesize;
                if (this.dups != 0)
                    dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
                pdb = BTreeDatabase.Open(dbFileName, pDbName, dbConfig, txn);

                /* Open secondary db in transaction */
                if (this.secondary) {
                    SecondaryBTreeDatabaseConfig sdbConfig =
                        new SecondaryBTreeDatabaseConfig(
                        pdb, new SecondaryKeyGenDelegate(SecondaryKeyGen));
                    sdbConfig.Creation = CreatePolicy.IF_NEEDED;
                    if (this.pagesize != 0)
                        sdbConfig.PageSize = this.pagesize;
                    sdbConfig.Duplicates = DuplicatesPolicy.SORTED;
                    sdbConfig.Env = env;
                    sdb = SecondaryBTreeDatabase.Open(
                        dbFileName, sDbName, sdbConfig, txn);
                }

                txn.Commit();
            } catch (DatabaseException e1) {
                txn.Abort();
                throw e1;
            } catch (FileNotFoundException e2) {
                txn.Abort();
                throw e2;
            }
        }
开发者ID:simonzhangsm,项目名称:h-store,代码行数:67,代码来源:excs_bulk.cs

示例10: SetUpEnvAndTxn

        public void SetUpEnvAndTxn(string home,
		    out DatabaseEnvironment env, out Transaction txn)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseMPool = true;
            env = DatabaseEnvironment.Open(home, envConfig);
            txn = env.BeginTransaction();
        }
开发者ID:remotesyssupport,项目名称:omnibus,代码行数:11,代码来源:BTreeDatabaseTest.cs

示例11: TestLockStats

        public void TestLockStats()
        {
            testName = "TestLockStats";
            SetUpTest(true);

            // Configure locking subsystem.
            LockingConfig lkConfig = new LockingConfig();
            lkConfig.MaxLockers = 60;
            lkConfig.MaxLocks = 50;
            lkConfig.MaxObjects = 70;
            lkConfig.Partitions = 20;
            lkConfig.DeadlockResolution = DeadlockPolicy.DEFAULT;

            // Configure and open environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.FreeThreaded = true;
            envConfig.LockSystemCfg = lkConfig;
            envConfig.LockTimeout = 1000;
            envConfig.MPoolSystemCfg = new MPoolConfig();
            envConfig.MPoolSystemCfg.CacheSize = new CacheInfo(0, 104800, 1);
            envConfig.NoLocking = false;
            envConfig.TxnTimeout = 2000;
            envConfig.UseLocking = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            DatabaseEnvironment env =
                DatabaseEnvironment.Open(testHome, envConfig);

            // Get and confirm locking subsystem statistics.
            LockStats stats = env.LockingSystemStats();
            env.PrintLockingSystemStats(true, true);
            Assert.AreEqual(0, stats.AllocatedLockers);
            Assert.AreNotEqual(0, stats.AllocatedLocks);
            Assert.AreNotEqual(0, stats.AllocatedObjects);
            Assert.AreEqual(0, stats.InitLockers);
            Assert.AreNotEqual(0, stats.InitLocks);
            Assert.AreNotEqual(0, stats.InitObjects);
            Assert.AreEqual(0, stats.LastAllocatedLockerID);
            Assert.AreEqual(0, stats.LockConflictsNoWait);
            Assert.AreEqual(0, stats.LockConflictsWait);
            Assert.AreEqual(0, stats.LockDeadlocks);
            Assert.AreEqual(0, stats.LockDowngrades);
            Assert.AreEqual(0, stats.LockerNoWait);
            Assert.AreEqual(0, stats.Lockers);
            Assert.AreEqual(0, stats.LockerWait);
            Assert.AreEqual(9, stats.LockModes);
            Assert.AreEqual(0, stats.LockPuts);
            Assert.AreEqual(0, stats.LockRequests);
            Assert.AreEqual(0, stats.Locks);
            Assert.AreEqual(0, stats.LockSteals);
            Assert.AreEqual(1000, stats.LockTimeoutLength);
            Assert.AreEqual(0, stats.LockTimeouts);
            Assert.AreEqual(0, stats.LockUpgrades);
            Assert.AreEqual(0, stats.MaxBucketLength);
            Assert.AreEqual(0, stats.MaxLockers);
            Assert.AreEqual(60, stats.MaxLockersInTable);
            Assert.AreEqual(0, stats.MaxLocks);
            Assert.AreEqual(0, stats.MaxLocksInBucket);
            Assert.AreEqual(50, stats.MaxLocksInTable);
            Assert.AreEqual(0, stats.MaxLockSteals);
            Assert.AreEqual(0, stats.MaxObjects);
            Assert.AreEqual(0, stats.MaxObjectsInBucket);
            Assert.AreEqual(70, stats.MaxObjectsInTable);
            Assert.AreEqual(0, stats.MaxObjectSteals);
            Assert.AreEqual(0, stats.MaxPartitionLockNoWait);
            Assert.AreEqual(0, stats.MaxPartitionLockWait);
            Assert.AreNotEqual(0, stats.MaxUnusedID);
            Assert.AreEqual(20, stats.nPartitions);
            Assert.AreEqual(0, stats.ObjectNoWait);
            Assert.AreEqual(0, stats.Objects);
            Assert.AreEqual(0, stats.ObjectSteals);
            Assert.AreEqual(0, stats.ObjectWait);
            Assert.LessOrEqual(0, stats.PartitionLockNoWait);
            Assert.AreEqual(0, stats.PartitionLockWait);
            Assert.Less(0, stats.RegionNoWait);
            Assert.AreNotEqual(0, stats.RegionSize);
            Assert.AreEqual(0, stats.RegionWait);
            Assert.AreNotEqual(0, stats.TableSize);
            Assert.AreEqual(2000, stats.TxnTimeoutLength);
            Assert.AreEqual(0, stats.TxnTimeouts);

            env.PrintLockingSystemStats();

            Transaction txn = env.BeginTransaction();
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
                dbConfig.FreeThreaded = true;
            BTreeDatabase db = BTreeDatabase.Open(
                testName + ".db", dbConfig, txn);
            txn.Commit();

            testLockStatsEnv = env;
            testLockStatsDb = db;

            // Use some locks, to ensure  the stats work when populated.
            txn = testLockStatsEnv.BeginTransaction();
            for (int i = 0; i < 500; i++)
//.........这里部分代码省略.........
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:101,代码来源:LockTest.cs

示例12: GetMultipleDB

        private void GetMultipleDB(string home, string dbFileName, 
		    BTreeDatabaseConfig dbConfig, out DatabaseEnvironment env, 
		    out Transaction txn, out BTreeDatabase db,
		    out BTreeCursor cursor)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseTxns = true;
            envConfig.UseLocking = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool = true;
            env = DatabaseEnvironment.Open(home, envConfig);
            txn = env.BeginTransaction();
            if (dbConfig == null)
                dbConfig = new BTreeDatabaseConfig();
            dbConfig.Env = env;
            GetMultipleDB(dbFileName, dbConfig, txn, out db,
                out cursor);
        }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:20,代码来源:BTreeCursorTest.cs

示例13: PutMultipleKey

        private void PutMultipleKey(DatabaseEnvironment env)
        {
            List<KeyValuePair<DatabaseEntry, DatabaseEntry>> pList =
                new List<KeyValuePair<
                DatabaseEntry, DatabaseEntry>>();
            BTreeDatabase db;
            DatabaseEntry key, value;
            Transaction txn;
            string dbFileName = (env == null) ? testHome +
                "/" + testName + ".db" : testName + ".db";
            int i;

            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            if (env != null) {
                dbConfig.Env = env;
                txn = env.BeginTransaction();
                db = BTreeDatabase.Open(
                    dbFileName, dbConfig, txn);
                txn.Commit();
            } else
                db = BTreeDatabase.Open(dbFileName, dbConfig);

            for (i = 0; i < 100; i++) {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                value = new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("data" +
                    i + Configuration.RandomString(512)));
                pList.Add(new KeyValuePair<
                    DatabaseEntry, DatabaseEntry>(key, value));
            }

            // Create btree bulk buffer for key/value pairs.
            MultipleKeyDatabaseEntry pairBuff =
                new MultipleKeyDatabaseEntry(pList, false);
            i = 0;
            foreach (KeyValuePair<DatabaseEntry, DatabaseEntry>
                pair in pairBuff) {
                Assert.AreEqual(pList[i].Key.Data,
                    pair.Key.Data);
                Assert.AreEqual(pList[i].Value.Data,
                    pair.Value.Data);
                i++;
            }
            Assert.AreEqual(100, i);

            /*
             * Create bulk buffer from another key/value pairs
             * bulk buffer.
             */
            MultipleKeyDatabaseEntry pairBuff1 =
                new MultipleKeyDatabaseEntry(
                pairBuff.Data, false);
            Assert.AreEqual(false, pairBuff1.Recno);
            i = 0;
            foreach (KeyValuePair<DatabaseEntry, DatabaseEntry>
                pair in pairBuff1) {
                Assert.AreEqual(pList[i].Key.Data,
                    pair.Key.Data);
                Assert.AreEqual(pList[i].Value.Data,
                    pair.Value.Data);
                i++;
            }
            Assert.AreEqual(100, i);

            if (env == null) {
                // Bulk insert with key/value pair bulk buffer.
                db.Put(pairBuff);
                Cursor cursor = db.Cursor();
                Assert.IsTrue(cursor.MoveFirst());
                i = 0;
                Assert.AreEqual(pList[i].Key.Data,
                     cursor.Current.Key.Data);
                Assert.AreEqual(pList[i].Value.Data,
                     cursor.Current.Value.Data);
                while (cursor.MoveNext()) {
                    i++;
                    Assert.AreEqual(pList[i].Key.Data,
                        cursor.Current.Key.Data);
                    Assert.AreEqual(pList[i].Value.Data,
                        cursor.Current.Value.Data);
                }
                Assert.AreEqual(99, i);
                cursor.Close();
                /*
                 * Dump all records from the database. The
                 * number of records should be 100.
                 */
                Assert.AreEqual(100, db.Truncate());

                // Bulk insert with copied key/value pair buffer.
                db.Put(pairBuff1);
                cursor = db.Cursor();
                Assert.IsTrue(cursor.MoveFirst());
                i = 0;
                Assert.AreEqual(pList[i].Key.Data,
                    cursor.Current.Key.Data);
                Assert.AreEqual(pList[i].Value.Data,
                    cursor.Current.Value.Data);
//.........这里部分代码省略.........
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:101,代码来源:BTreeDatabaseTest.cs

示例14: PutMultiple

        private void PutMultiple(DatabaseEnvironment env)
        {
            List<DatabaseEntry> kList = new List<DatabaseEntry>();
            List<DatabaseEntry> vList = new List<DatabaseEntry>();
            BTreeDatabase db;
            DatabaseEntry key, value;
            Transaction txn;
            string dbFileName = (env == null) ? testHome +
                "/" + testName + ".db" : testName + ".db";
            int i;

            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            if (env != null) {
                dbConfig.Env = env;
                txn = env.BeginTransaction();
                db = BTreeDatabase.Open(
                    dbFileName, dbConfig, txn);
                txn.Commit();
            } else
                db = BTreeDatabase.Open(dbFileName, dbConfig);

            for (i = 0; i < 100; i++) {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                value = new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("data" + i +
                    Configuration.RandomString(512)));
                kList.Add(key);
                vList.Add(value);
            }

            // Create bulk buffer for non-recno based keys.
            MultipleDatabaseEntry keyBuff =
                new MultipleDatabaseEntry(kList, false);
            Assert.IsFalse(keyBuff.Recno);

            // Create bulk buffer for values.
            MultipleDatabaseEntry valBuff =
                new MultipleDatabaseEntry(vList, false);
            i = 0;
            foreach (DatabaseEntry dbt in valBuff) {
                Assert.AreEqual(vList[i].Data, dbt.Data);
                i++;
            }
            Assert.AreEqual(100, i);

            // Create bulk buffer from another key buffer.
            MultipleDatabaseEntry keyBuff1 =
                new MultipleDatabaseEntry(
                keyBuff.Data, keyBuff.Recno);
            i = 0;
            foreach (DatabaseEntry dbt in keyBuff1) {
                Assert.AreEqual(kList[i].Data, dbt.Data);
                i++;
            }
            Assert.AreEqual(100, i);

            if (env != null) {
                txn = env.BeginTransaction();
                db.Put(keyBuff, valBuff, txn);
                Assert.AreEqual(100, db.Truncate(txn));
                txn.Commit();
            } else {
                /*
                 * Bulk insert to database with key and value
                 * buffers.
                 */
                db.Put(keyBuff, valBuff);

                // Verify all records exist as expected.
                Cursor cursor = db.Cursor();
                i = 99;
                Assert.IsTrue(cursor.MoveLast());
                Assert.AreEqual(kList[i].Data,
                    cursor.Current.Key.Data);
                Assert.AreEqual(vList[i].Data,
                    cursor.Current.Value.Data);
                while (cursor.MovePrev()) {
                    i--;
                    Assert.AreEqual(kList[i].Data,
                        cursor.Current.Key.Data);
                    Assert.AreEqual(vList[i].Data,
                        cursor.Current.Value.Data);
                }
                Assert.AreEqual(0, i);
                cursor.Close();
                /*
                 * Dumped all records. The number of records
                 * should be 100.
                 */
                Assert.AreEqual(100, db.Truncate());

                /*
                 * Bulk insert to database with a copied key
                 * buffer and a value buffer.
                 */
                db.Put(keyBuff1, valBuff);
                cursor = db.Cursor();
                Assert.IsTrue(cursor.MoveLast());
//.........这里部分代码省略.........
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:101,代码来源:BTreeDatabaseTest.cs

示例15: PopulateDb

        private void PopulateDb(DatabaseEnvironment env,
		    out BTreeDatabase db)
        {
            DatabaseEntry key, data;
            Transaction txn = null;
            string dbName;

            if (env != null) {
                txn = env.BeginTransaction();
                dbName = testName + ".db";
            } else
                dbName = testHome + "/" + testName + ".db";

            OpenBtreeDB(env, txn, dbName, out db);

            for (int i = 0; i < 100; i++) {
                key = new DatabaseEntry(
                    BitConverter.GetBytes(i));
                data = new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("hello"));
                db.Put(key, data, txn);
            }

            if (txn != null)
                txn.Commit();
        }
开发者ID:hyc,项目名称:BerkeleyDB,代码行数:26,代码来源:BTreeDatabaseTest.cs


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