本文整理汇总了C#中BerkeleyDB.CursorConfig类的典型用法代码示例。如果您正苦于以下问题:C# CursorConfig类的具体用法?C# CursorConfig怎么用?C# CursorConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CursorConfig类属于BerkeleyDB命名空间,在下文中一共展示了CursorConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetCursur
public void GetCursur(string dbFileName, bool ifConfig)
{
HeapDatabaseConfig dbConfig = new HeapDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
HeapDatabase db = HeapDatabase.Open(dbFileName, dbConfig);
HeapRecordId rid = db.Append(
new DatabaseEntry(BitConverter.GetBytes((int)1)));
Cursor cursor;
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.Priority = CachePriority.HIGH;
if (ifConfig == false)
cursor = db.Cursor();
else
cursor = db.Cursor(cursorConfig);
cursor.Add(new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(rid.toArray()),
new DatabaseEntry(BitConverter.GetBytes((int)2))));
Cursor dupCursor = cursor.Duplicate(false);
Assert.IsNull(dupCursor.Current.Key);
if (ifConfig)
Assert.AreEqual(CachePriority.HIGH, dupCursor.Priority);
dupCursor.Close();
cursor.Close();
db.Close();
}
开发者ID:bohrasd,项目名称:windowsrtdev,代码行数:25,代码来源:HeapDatabaseTest.cs
示例2: 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);
}
开发者ID:kanbang,项目名称:Colt,代码行数:34,代码来源:CursorTest.cs
示例3: GetSecondaryCursurWithTxn
public void GetSecondaryCursurWithTxn(string home,
string name, bool ifCfg)
{
string dbFileName = name + ".db";
SecondaryCursor cursor;
// Open env.
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(home,
envConfig);
// Open primary/secondary database.
Transaction txn = env.BeginTransaction();
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
BTreeDatabase db = BTreeDatabase.Open(dbFileName,
dbConfig, txn);
SecondaryBTreeDatabaseConfig secDBConfig = new
SecondaryBTreeDatabaseConfig(db,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secDBConfig.Env = env;
SecondaryBTreeDatabase secDB =
SecondaryBTreeDatabase.Open(dbFileName,
secDBConfig, txn);
for (int i = 0; i < 10; i++)
db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
new DatabaseEntry(BitConverter.GetBytes((int)i)), txn);
// Create secondary cursor.
if (ifCfg == false)
secDB.SecondaryCursor(txn);
else if (ifCfg == true)
{
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.WriteCursor = false;
cursor = secDB.SecondaryCursor(cursorConfig, txn);
cursor.Close();
}
secDB.Close();
db.Close();
txn.Commit();
env.Close();
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:51,代码来源:SecondaryDatabaseTest.cs
示例4: TestConfig
public void TestConfig()
{
testName = "TestConfig";
SetUpTest(false);
/*
* Configure the fields/properties and see if
* they are updated successfully.
*/
CursorConfig cursorConfig = new CursorConfig();
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
Config(xmlElem, ref cursorConfig, true);
Confirm(xmlElem, cursorConfig, true);
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:14,代码来源:CursorConfigTest.cs
示例5: Config
public static void Config(XmlElement xmlElement,
ref CursorConfig cursorConfig, bool compulsory)
{
Configuration.ConfigIsolation(xmlElement,
"IsolationDegree", ref cursorConfig.IsolationDegree,
compulsory);
Configuration.ConfigCachePriority(xmlElement,
"Priority", ref cursorConfig.Priority, compulsory);
Configuration.ConfigBool(xmlElement,
"SnapshotIsolation", ref cursorConfig.SnapshotIsolation,
compulsory);
Configuration.ConfigBool(xmlElement,
"WriteCursor", ref cursorConfig.WriteCursor,
compulsory);
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:15,代码来源:CursorConfigTest.cs
示例6: TestPriority
public void TestPriority()
{
BTreeCursor cursor;
BTreeDatabase db;
CachePriority[] priorities;
CursorConfig cursorConfig;
DatabaseEnvironment env;
cursorConfig = new CursorConfig();
priorities = new CachePriority[5];
priorities[0] = CachePriority.DEFAULT;
priorities[1] = CachePriority.HIGH;
priorities[2] = CachePriority.LOW;
priorities[3] = CachePriority.VERY_HIGH;
priorities[4] = CachePriority.VERY_LOW;
testName = "TestPriority";
testHome = testFixtureHome + "/" + testName;
Configuration.ClearDir(testHome);
for (int i = 0; i < 5; i++)
{
// Configure the cursor priority.
cursorConfig.Priority = priorities[i];
// Open a database to test a specified priority.
GetCursorInBtreeDBInCDS(testHome, testName,
cursorConfig, out env, out db, out cursor);
Assert.AreEqual(priorities[i], cursorConfig.Priority);
cursor.Close();
db.Close();
env.Close();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:36,代码来源:CursorTest.cs
示例7: CountRecords
/*
* This simply counts the number of records contained in the
* database and returns the result. You can use this method
* in three ways:
*
* First call it with an active txn handle.
* Secondly, configure the cursor for dirty reads
* Third, call countRecords AFTER the writer has committed
* its transaction.
*
* If you do none of these things, the writer thread will
* self-deadlock.
*
* Note that this method exists only for illustrative purposes.
* A more straight-forward way to count the number of records in
* a database is to use the Database.getStats() method.
*/
private int CountRecords(Transaction txn)
{
int count = 0;
Cursor cursor = null;
try {
// Get the cursor.
CursorConfig cc = new CursorConfig();
/*
* Isolation degree one is ignored if the
* database was not opened for uncommitted
* read support. TxnGuide opens its database
* in this way and TxnGuideInMemory does not.
*/
cc.IsolationDegree = Isolation.DEGREE_ONE;
cursor = db.Cursor(cc, txn);
while (cursor.MoveNext())
count++;
} finally {
if (cursor != null)
cursor.Close();
}
return count;
}
开发者ID:mania25,项目名称:diy-project,代码行数:43,代码来源:ex_txn.cs
示例8: SecondaryCursor
/// <summary>
/// Create a secondary database cursor with the given configuration.
/// </summary>
/// <param name="cfg">
/// The configuration properties for the cursor.
/// </param>
/// <returns>A newly created cursor</returns>
public SecondaryCursor SecondaryCursor(CursorConfig cfg) {
return SecondaryCursor(cfg, null);
}
开发者ID:rohitlodha,项目名称:DenverDB,代码行数:10,代码来源:SecondaryDatabase.cs
示例9: ReadTxn
public void ReadTxn()
{
// Get a new transaction for reading the db.
TransactionConfig txnConfig =
new TransactionConfig();
txnConfig.Snapshot = true;
readTxn = paramEnv.BeginTransaction(
txnConfig);
// Get a new cursor for putting record into db.
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.WriteCursor = false;
BTreeCursor cursor = paramDB.Cursor(
cursorConfig, readTxn);
// Continually reading record from db.
try
{
Assert.IsTrue(cursor.MoveFirst());
int i = 0;
do
{
Assert.AreEqual(
BitConverter.ToInt32(
cursor.Current.Key.Data, 0),
BitConverter.ToInt32(
cursor.Current.Value.Data, 0));
} while (i <= 1000 && cursor.MoveNext());
}
catch (DeadlockException)
{
}
finally
{
cursor.Close();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:37,代码来源:CursorTest.cs
示例10: TestPriority
public void TestPriority()
{
CachePriority[] priorities;
CursorConfig cursorConfig;
testName = "TestPriority";
SetUpTest(true);
cursorConfig = new CursorConfig();
priorities = new CachePriority[6];
priorities[0] = CachePriority.DEFAULT;
priorities[1] = CachePriority.HIGH;
priorities[2] = CachePriority.LOW;
priorities[3] = CachePriority.VERY_HIGH;
priorities[4] = CachePriority.VERY_LOW;
priorities[5] = null;
for (int i = 0; i < 6; i++) {
if (priorities[i] != null) {
cursorConfig.Priority = priorities[i];
Assert.AreEqual(priorities[i], cursorConfig.Priority);
}
GetCursorWithConfig(testHome + "/" + testName + ".db",
DatabaseType.BTREE.ToString(), cursorConfig, DatabaseType.BTREE);
GetCursorWithConfig(testHome + "/" + testName + ".db",
DatabaseType.HASH.ToString(), cursorConfig, DatabaseType.HASH);
GetCursorWithConfig(testHome + "/" + testName + ".db",
DatabaseType.QUEUE.ToString(), cursorConfig, DatabaseType.QUEUE);
GetCursorWithConfig(testHome + "/" + testName + ".db",
DatabaseType.RECNO.ToString(), cursorConfig, DatabaseType.RECNO);
}
}
开发者ID:mcandre,项目名称:db,代码行数:31,代码来源:CursorTest.cs
示例11: 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 != 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);
}
开发者ID:mcandre,项目名称:db,代码行数:43,代码来源:CursorTest.cs
示例12: Cursor
/// <summary>
/// Create a database cursor with the given configuration.
/// </summary>
/// <param name="cfg">
/// The configuration properties for the cursor.
/// </param>
/// <returns>A newly created cursor</returns>
public Cursor Cursor(CursorConfig cfg)
{
return Cursor(cfg, null);
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:11,代码来源:BaseDatabase.cs
示例13: Cursor
/// <summary>
/// Create a transactionally protected database cursor with the given
/// configuration.
/// </summary>
/// <param name="cfg">
/// The configuration properties for the cursor.
/// </param>
/// <param name="txn">
/// The transaction context in which the cursor may be used.
/// </param>
/// <returns>A newly created cursor</returns>
public new HashCursor Cursor(CursorConfig cfg, Transaction txn)
{
return new HashCursor(
db.cursor(Transaction.getDB_TXN(txn), cfg.flags), Pagesize);
}
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:16,代码来源:HashDatabase.cs
示例14: TestWriteCursor
public void TestWriteCursor()
{
BTreeCursor cursor;
BTreeDatabase db;
CursorConfig cursorConfig;
DatabaseEnvironment env;
testName = "TestWriteCursor";
testHome = testFixtureHome + "/" + testName;
Configuration.ClearDir(testHome);
cursorConfig = new CursorConfig();
cursorConfig.WriteCursor = true;
GetCursorInBtreeDBInCDS(testHome, testName,
cursorConfig, out env, out db, out cursor);
/*
* Add a record by cursor to the database. If the
* WriteCursor doesn't work, exception will be
* throwed in the environment which is configured
* with DB_INIT_CDB.
*/
try
{
AddOneByCursor(db, cursor);
}
catch (DatabaseException)
{
throw new TestException();
}
finally
{
cursor.Close();
db.Close();
env.Close();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:39,代码来源:CursorTest.cs
示例15: GetCursorWithConfig
private void GetCursorWithConfig(string dbFile, string dbName,
CursorConfig cfg, DatabaseType type)
{
Database db;
Cursor cursor;
Configuration.ClearDir(testHome);
if (type == DatabaseType.BTREE) {
BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = BTreeDatabase.Open(dbFile, dbName, dbConfig);
cursor = ((BTreeDatabase)db).Cursor(cfg);
} else if (type == DatabaseType.HASH) {
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = (HashDatabase)HashDatabase.Open(dbFile, dbName, dbConfig);
cursor = ((HashDatabase)db).Cursor(cfg);
} else if (type == DatabaseType.QUEUE) {
QueueDatabaseConfig dbConfig = new QueueDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Length = 100;
db = QueueDatabase.Open(dbFile, dbConfig);
cursor = ((QueueDatabase)db).Cursor(cfg);
} else if (type == DatabaseType.RECNO) {
RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = RecnoDatabase.Open(dbFile, dbName, dbConfig);
cursor = ((RecnoDatabase)db).Cursor(cfg);
} else
throw new TestException();
if (cfg.Priority != null)
Assert.AreEqual(cursor.Priority, cfg.Priority);
else
Assert.AreEqual(CachePriority.DEFAULT, cursor.Priority);
Cursor dupCursor = cursor.Duplicate(false);
Assert.AreEqual(cursor.Priority, dupCursor.Priority);
cursor.Close();
db.Close();
}
开发者ID:mcandre,项目名称:db,代码行数:40,代码来源:CursorTest.cs
示例16: TestCloseResmgr_int
void TestCloseResmgr_int(bool havetxn)
{
BTreeDatabase db;
BTreeCursor cursor, csr;
CursorConfig cursorConfig;
DatabaseEnvironment env;
Transaction txn;
DatabaseEntry key, data;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
txn = null;
testName = "TestCloseResmgr";
testHome = testFixtureHome + "/" + testName;
Configuration.ClearDir(testHome);
cursorConfig = new CursorConfig();
// Open an environment, a database and a cursor.
if (havetxn)
GetCursorInBtreeDBInTDS(testHome, testName,
cursorConfig, out env, out db,
out cursor, out txn);
else
GetCursorInBtreeDB(testHome, testName,
cursorConfig, out env, out db,
out cursor);
// Add a record to db via cursor.
key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("key"));
data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("data"));
pair = new KeyValuePair<DatabaseEntry,DatabaseEntry>
(key, data);
byte []kbytes;
byte []dbytes;
for (int i = 0; i < 100; i++) {
kbytes = ASCIIEncoding.ASCII.
GetBytes("key" + i);
dbytes = ASCIIEncoding.ASCII.
GetBytes("data" + i);
key.Data = kbytes;
data.Data = dbytes;
cursor.Add(pair);
}
// Do not close cursor.
csr = db.Cursor(cursorConfig, txn);
while (csr.MoveNext()) {
// Do nothing for now.
}
// Do not close csr.
if (havetxn && txn != null)
txn.Commit();
env.CloseForceSync();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:60,代码来源:CursorTest.cs
示例17: Cursor
/// <summary>
/// Create a database cursor with the given configuration.
/// </summary>
/// <param name="cfg">
/// The configuration properties for the cursor.
/// </param>
/// <returns>A newly created cursor</returns>
public new BTreeCursor Cursor(CursorConfig cfg)
{
return Cursor(cfg, null);
}
开发者ID:mcandre,项目名称:db,代码行数:11,代码来源:BTreeDatabase.cs
示例18: TestIsolationDegree
public void TestIsolationDegree()
{
BTreeDatabase db;
BTreeCursor cursor;
CursorConfig cursorConfig;
DatabaseEnvironment env;
Transaction txn;
testName = "TestIsolationDegree";
testHome = testFixtureHome + "/" + testName;
Isolation[] isolationDegrees = new Isolation[3];
isolationDegrees[0] = Isolation.DEGREE_ONE;
isolationDegrees[1] = Isolation.DEGREE_TWO;
isolationDegrees[2] = Isolation.DEGREE_THREE;
IsolationDelegate[] delegates = {
new IsolationDelegate(CursorReadUncommited),
new IsolationDelegate(CursorReadCommited),
new IsolationDelegate(CursorRead)};
cursorConfig = new CursorConfig();
for (int i = 0; i < 3; i++)
{
cursorConfig.IsolationDegree = isolationDegrees[i];
GetCursorInBtreeDBInTDS(testHome + "/" + i.ToString(),
testName, cursorConfig, out env, out db,
out cursor, out txn);
cursor.Close();
db.Close();
txn.Commit();
env.Close();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:34,代码来源:CursorTest.cs
示例19: GetMultipleDB
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);
}
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:46,代码来源:BTreeCursorTest.cs
示例20: TestSecondaryCursorWithConfig
public void TestSecondaryCursorWithConfig()
{
testName = "TestSecondaryCursorWithConfig";
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
BTreeDatabase db;
SecondaryBTreeDatabase secDB;
OpenPrimaryAndSecondaryDB(dbFileName, out db, out secDB);
for (int i = 0; i < 10; i++)
db.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
new DatabaseEntry(BitConverter.GetBytes((int)i)));
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.WriteCursor = false;
SecondaryCursor cursor =
secDB.SecondaryCursor(cursorConfig);
cursor.Move(new DatabaseEntry(
BitConverter.GetBytes((int)5)), true);
Assert.AreEqual(1, cursor.Count());
// Close the cursor.
cursor.Close();
// Close secondary database.
secDB.Close();
// Close primary database.
db.Close();
}
开发者ID:xiaogao0371,项目名称:dockerfile,代码行数:33,代码来源:SecondaryDatabaseTest.cs
注:本文中的BerkeleyDB.CursorConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论