public void GetCursorInBtreeDBUsingRecno(string home,
		    string name, out BTreeDatabase db,
		    out BTreeCursor cursor)
        {
            string dbFileName = home + "/" + name + ".db";
            BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
            dbConfig.UseRecordNumbers = true;
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            db = BTreeDatabase.Open(dbFileName, dbConfig);
            cursor = db.Cursor();
        }
示例#2
0
        public static void GetCursorInBtreeDB(
		    string home, string name,
		    CursorConfig cursorConfig,
		    out DatabaseEnvironment env, out BTreeDatabase db,
		    out BTreeCursor cursor)
        {
            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);

            /*
             * 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, null);

            // Get a cursor in the transaction.
            cursor = db.Cursor(cursorConfig, null);
        }
示例#3
0
        public static void GetCursorInBtreeDBWithoutEnv(
		    string home, string name, out BTreeDatabase db,
		    out BTreeCursor cursor)
        {
            string dbFileName = home + "/" + name + ".db";

            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
            db = BTreeDatabase.Open(dbFileName, dbConfig);
            cursor = db.Cursor();
        }
        private void GetMultipleDB(string dbFileName, 
		    BTreeDatabaseConfig dbConfig, Transaction txn, 
		    out BTreeDatabase db, out BTreeCursor cursor)
        {
            if (txn == null) {
                db = BTreeDatabase.Open(dbFileName, dbConfig);
                cursor = db.Cursor();
            } else {
                db = BTreeDatabase.Open(
                    dbFileName, dbConfig, txn);
                CursorConfig cursorConfig = new CursorConfig();
                cursor = db.Cursor(cursorConfig, txn);
            }

            KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
            DatabaseEntry key, data;
            for (int i = 1; i < 100; i++) {
                key = new DatabaseEntry(BitConverter.GetBytes(i));
                data = new DatabaseEntry(BitConverter.GetBytes(i));
                pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(key, data);
                cursor.Add(pair);
            }

            if (dbConfig.UseRecordNumbers == true) {
                byte[] bytes = new byte[512];
                for (int i = 0; i < 512; i++)
                    bytes[i] = (byte)i;
                key = new DatabaseEntry(BitConverter.GetBytes(100));
                data = new DatabaseEntry(bytes);
                pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(key, data);
                cursor.Add(pair);
            } else {
                if (dbConfig.Duplicates == DuplicatesPolicy.UNSORTED ||
                    dbConfig.Duplicates == DuplicatesPolicy.SORTED) {
                    key = new DatabaseEntry(BitConverter.GetBytes(99));
                    data = new DatabaseEntry(BitConverter.GetBytes(100));
                    pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(key, data);
                    cursor.Add(pair);
                }

                key = new DatabaseEntry(BitConverter.GetBytes(101));
                data = new DatabaseEntry(BitConverter.GetBytes(101));
                pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(key, data);
                cursor.Add(pair);
            }
        }