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