本文整理汇总了C#中BerkeleyDB.Transaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Commit方法的具体用法?C# Transaction.Commit怎么用?C# Transaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BerkeleyDB.Transaction
的用法示例。
在下文中一共展示了Transaction.Commit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}