本文整理汇总了C#中BerkeleyDB.BTreeDatabase类的典型用法代码示例。如果您正苦于以下问题:C# BTreeDatabase类的具体用法?C# BTreeDatabase怎么用?C# BTreeDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BTreeDatabase类属于BerkeleyDB命名空间,在下文中一共展示了BTreeDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSecCursor
public void GetSecCursor(BTreeDatabase db,
string secFileName, SecondaryKeyGenDelegate keyGen,
out SecondaryBTreeDatabase secDB,
out SecondaryCursor cursor, bool ifCfg,
DatabaseEntry data)
{
// Open secondary database.
SecondaryBTreeDatabaseConfig secCfg =
new SecondaryBTreeDatabaseConfig(db, keyGen);
secCfg.Creation = CreatePolicy.IF_NEEDED;
secCfg.Duplicates = DuplicatesPolicy.SORTED;
secDB = SecondaryBTreeDatabase.Open(secFileName, secCfg);
int[] intArray = new int[4];
intArray[0] = 0;
intArray[1] = 1;
intArray[2] = 2049;
intArray[3] = 65537;
for (int i = 0; i < 4; i++)
{
DatabaseEntry record = new DatabaseEntry(
BitConverter.GetBytes(intArray[i]));
db.Put(record, record);
}
// Get secondary cursor on the secondary database.
if (ifCfg == false)
cursor = secDB.SecondaryCursor();
else
cursor = secDB.SecondaryCursor(new CursorConfig());
// Position the cursor.
if (data != null)
Assert.IsTrue(cursor.Move(data, true));
}
示例2: OpenBase
private void OpenBase()
{
var pathStr = Environment.GetEnvironmentVariable("PATH");
var pwd = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
pwd = Path.Combine(pwd, IntPtr.Size == 4 ? "x86" : "x64");
if (pathStr != null && !pathStr.Contains(pwd))
{
pwd += ";" + Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable("PATH", pwd);
}
_btreeConfig = new BTreeDatabaseConfig
{
Duplicates = DuplicatesPolicy.NONE,
ErrorPrefix = "QH_" + Path.GetFileName(_dbPAth),
Creation = CreatePolicy.IF_NEEDED,
FreeThreaded = true
};
if (_env != null)
{
_btreeConfig.Env = _env;
}
_btreeDb = BTreeDatabase.Open(_dbPAth, _name, _btreeConfig);
}
示例3: GetCursorInBtreeDBInCDS
// 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);
}
示例4: GetCursorInBtreeDBUsingRecno
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();
}
示例5: Init
public override void Init(int flowCount, long flowRecordCount)
{
BTreeDatabaseConfig config = new BTreeDatabaseConfig();
config.Creation = CreatePolicy.IF_NEEDED;
config.CacheSize = new CacheInfo(5, 0, 2);
config.PageSize = 8 * 1024;
config.BTreeCompare = new EntryComparisonDelegate(CompareFunctionKeyByteArray);
config.Duplicates = DuplicatesPolicy.NONE;
string fileName = Path.Combine(DataDirectory, string.Format("{0}.oracle", CollectionName));
database = BTreeDatabase.Open(fileName, config);
}
示例6: OpenBtreeDBInEnv
public void OpenBtreeDBInEnv(string dbName,
DatabaseEnvironment env, out BTreeDatabase db,
bool create, Transaction txn)
{
BTreeDatabaseConfig btreeDBConfig =
new BTreeDatabaseConfig();
btreeDBConfig.Env = env;
if (create == true)
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
else
btreeDBConfig.Creation = CreatePolicy.NEVER;
if (txn == null)
db = BTreeDatabase.Open(dbName,
btreeDBConfig);
else
db = BTreeDatabase.Open(dbName,
btreeDBConfig, txn);
}
示例7: OpenPrimaryAndSecondaryDB
public void OpenPrimaryAndSecondaryDB(string dbFileName,
out BTreeDatabase primaryDB,
out SecondaryBTreeDatabase secDB)
{
// Open primary database.
BTreeDatabaseConfig primaryDBConfig =
new BTreeDatabaseConfig();
primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
primaryDB =
BTreeDatabase.Open(dbFileName, primaryDBConfig);
// Open secondary database.
SecondaryBTreeDatabaseConfig secDBConfig =
new SecondaryBTreeDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secDB = SecondaryBTreeDatabase.Open(dbFileName,
secDBConfig);
}
示例8: Confirm
public static void Confirm(XmlElement xmlElem,
BTreeDatabase btreeDB, bool compulsory)
{
DatabaseTest.Confirm(xmlElem, btreeDB, compulsory);
Configuration.ConfirmDuplicatesPolicy(xmlElem,
"Duplicates", btreeDB.Duplicates, compulsory);
Configuration.ConfirmUint(xmlElem, "MinKeysPerPage",
btreeDB.MinKeysPerPage, compulsory);
/*
* BTreeDatabase.RecordNumbers is the value of
* BTreeDatabaseConfig.UseRecordNumbers.
*/
Configuration.ConfirmBool(xmlElem, "UseRecordNumbers",
btreeDB.RecordNumbers, compulsory);
/*
* BTreeDatabase.ReverseSplit is the value of
* BTreeDatabaseConfig.NoReverseSplitting.
*/
Configuration.ConfirmBool(xmlElem, "NoReverseSplitting",
btreeDB.ReverseSplit, compulsory);
Assert.AreEqual(DatabaseType.BTREE, btreeDB.Type);
string type = btreeDB.ToString();
Assert.IsNotNull(type);
}
示例9: 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();
}
示例10: OpenNewSequence
public void OpenNewSequence(string dbFileName,
out BTreeDatabase db, out Sequence seq)
{
// Open a database.
BTreeDatabaseConfig btreeDBConfig =
new BTreeDatabaseConfig();
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
db = BTreeDatabase.Open(dbFileName, btreeDBConfig);
// Configure and initialize sequence.
SequenceConfig seqConfig = new SequenceConfig();
seqConfig.BackingDatabase = db;
seqConfig.CacheSize = 1000;
seqConfig.Creation = CreatePolicy.ALWAYS;
seqConfig.Decrement = false;
seqConfig.FreeThreaded = true;
seqConfig.Increment = true;
seqConfig.InitialValue = 100;
seqConfig.key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("key"));
seqConfig.SetRange(Int64.MinValue, Int64.MaxValue);
seqConfig.Wrap = true;
seq = new Sequence(seqConfig);
}
示例11: CursorReadUncommited
/*
* Configure a transactional cursor to have degree 1
* isolation. The cursor's read operations could return
* modified but not yet commited data.
*/
public void CursorReadUncommited(
DatabaseEnvironment env, BTreeDatabase db,
Cursor cursor, Transaction txn)
{
Console.WriteLine("CursorReadUncommited");
}
示例12: GetCursorInBtreeDBWithoutEnv
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();
}
示例13: 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();
}
示例14: MyDbs
public MyDbs(string databaseHome)
{
vDbName = "vendordb.db";
iDbName = "inventorydb.db";
itemSDbName = "itemname.sdb";
if (databaseHome != null) {
vDbName = databaseHome + "\\" + vDbName;
iDbName = databaseHome + "\\" + iDbName;
itemSDbName = databaseHome + "\\" + itemSDbName;
}
btreeConfig = new BTreeDatabaseConfig();
btreeConfig.Creation = CreatePolicy.IF_NEEDED;
btreeConfig.CacheSize = new CacheInfo(0, 64 * 1024, 1);
btreeConfig.ErrorPrefix = "excs_getting_started";
btreeConfig.PageSize = 8 * 1024;
/* Optionally remove existing database files. */
try {
RemoveDbFile(vDbName);
RemoveDbFile(iDbName);
RemoveDbFile(itemSDbName);
} catch (Exception e) {
Console.WriteLine("Error deleting db.");
Console.WriteLine(e.Message);
throw e;
}
/* Create and open the Inventory and Vendor database files. */
try {
vbtreeDB = BTreeDatabase.Open(vDbName, btreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening {0}.", vDbName);
Console.WriteLine(e.Message);
throw e;
}
try {
ibtreeDB = BTreeDatabase.Open(iDbName, btreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening {0}.", iDbName);
Console.WriteLine(e.Message);
throw e;
}
/*
* Open a secondary btree database associated with the
* Inventory database.
*/
try {
itemSecbtreeConfig = new SecondaryBTreeDatabaseConfig(
ibtreeDB, new SecondaryKeyGenDelegate(
CreateSecondaryKey));
itemSecbtreeConfig.Creation = CreatePolicy.IF_NEEDED;
itemSecbtreeConfig.Duplicates = DuplicatesPolicy.UNSORTED;
itemSecbtreeDB = SecondaryBTreeDatabase.Open(
itemSDbName, itemSecbtreeConfig);
} catch (Exception e) {
Console.WriteLine("Error opening secondary {0}", itemSDbName);
Console.WriteLine(e.Message);
throw e;
}
}
示例15: TestLockAndUnlockMutex
public void TestLockAndUnlockMutex()
{
testName = "TestLockAndUnlockMutex";
SetUpTest(true);
/*
* Open an environment without locking and
* deadlock detection.
*/
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.FreeThreaded = true;
envConfig.UseLogging = true;
envConfig.Create = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
// Open a database.
BTreeDatabaseConfig dbConfig =
new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
TestDB = BTreeDatabase.Open(
testName + ".db", dbConfig);
// Get a mutex which will be used in two threads.
TestMutex = env.GetMutex(true, false);
// Begin two threads to write records into database.
Thread mutexThread1 = new Thread(
new ThreadStart(MutexThread1));
Thread mutexThread2 = new Thread(
new ThreadStart(MutexThread2));
mutexThread1.Start();
mutexThread2.Start();
mutexThread1.Join();
mutexThread2.Join();
// Free the mutex.
TestMutex.Dispose();
// Close all.
TestDB.Close();
env.Close();
}