// Get a cursor in CDS. public static void GetCursorInBtreeDBInCDS( string home, string name, CursorConfig cursorConfig, out DatabaseEnvironment env, out BTreeDatabase db, out BTreeCursor cursor) { string dbFileName = name + ".db"; // Open an environment. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseCDB = true; envConfig.UseMPool = 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); // Get a cursor in the transaction. cursor = db.Cursor(cursorConfig); }
/* * Move the cursor according to recno. The recno * starts from 1 and is increased by 1. */ public void MoveCursorToRecno(BTreeCursor cursor, LockingInfo lck) { for (uint i = 1; i <= 5; i++) if (lck == null) Assert.IsTrue(cursor.Move(i)); else Assert.IsTrue(cursor.Move(i, lck)); }
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(); }
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(); }
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 != null && cursorConfig.IsolationDegree == Isolation.DEGREE_ONE) dbConfig.ReadUncommitted = true; db = BTreeDatabase.Open(dbFileName, dbConfig, txn); // Get a cursor in the transaction. if (cursorConfig != null) cursor = db.Cursor(cursorConfig, txn); else cursor = db.Cursor(txn); }
/*l * Move the cursor according to a given recno and * return the current record's recno. The given recno * and the one got from the cursor should be the same. */ public void ReturnRecno(BTreeCursor cursor, LockingInfo lck) { for (uint i = 1; i <= 5; i++) if (lck == null) { if (cursor.Move(i) == true) Assert.AreEqual(i, cursor.Recno()); } else { if (cursor.Move(i, lck) == true) Assert.AreEqual(i, cursor.Recno(lck)); } }
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); }
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); } }