本文整理汇总了C#中BerkeleyDB.QueueDatabaseConfig类的典型用法代码示例。如果您正苦于以下问题:C# QueueDatabaseConfig类的具体用法?C# QueueDatabaseConfig怎么用?C# QueueDatabaseConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueueDatabaseConfig类属于BerkeleyDB命名空间,在下文中一共展示了QueueDatabaseConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenSecQueueDB
public void OpenSecQueueDB(string className,
string funName, string dbFileName, string dbSecFileName)
{
XmlElement xmlElem = Configuration.TestSetUp(
className, funName);
// Open a primary queue database.
QueueDatabaseConfig primaryDBConfig =
new QueueDatabaseConfig();
primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
QueueDatabase primaryDB;
/*
* If secondary database name is given, the primary
* database is also opened with database name.
*/
primaryDB = QueueDatabase.Open(dbFileName,
primaryDBConfig);
try
{
// Open a new secondary database.
SecondaryQueueDatabaseConfig secQueueDBConfig =
new SecondaryQueueDatabaseConfig(
primaryDB, null);
SecondaryQueueDatabaseConfigTest.Config(
xmlElem, ref secQueueDBConfig, false);
secQueueDBConfig.Creation =
CreatePolicy.IF_NEEDED;
SecondaryQueueDatabase secQueueDB;
secQueueDB = SecondaryQueueDatabase.Open(
dbSecFileName, secQueueDBConfig);
// Close the secondary database.
secQueueDB.Close();
// Open the existing secondary database.
SecondaryDatabaseConfig secDBConfig =
new SecondaryQueueDatabaseConfig(
primaryDB, null);
SecondaryDatabase secDB;
secDB = SecondaryQueueDatabase.Open(
dbSecFileName, secDBConfig);
// Close secondary database.
secDB.Close();
}
catch (DatabaseException)
{
throw new TestException();
}
finally
{
// Close primary database.
primaryDB.Close();
}
}
示例2: ConfigCase1
public void ConfigCase1(QueueDatabaseConfig dbConfig)
{
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.PageSize = 4096;
dbConfig.ExtentSize = 1024;
dbConfig.Length = 4000;
dbConfig.PadByte = 32;
}
示例3: Config
private void Config(QueueDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that doesn't get the Queue
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
db.set_re_len(cfg.Length);
if (cfg.padIsSet)
db.set_re_pad(cfg.PadByte);
if (cfg.extentIsSet)
db.set_q_extentsize(cfg.ExtentSize);
}
示例4: Confirm
public static void Confirm(XmlElement xmlElement,
QueueDatabaseConfig queueDBConfig, bool compulsory)
{
DatabaseConfig dbConfig = queueDBConfig;
Confirm(xmlElement, dbConfig, compulsory);
// Confirm Queue database specific configuration
Configuration.ConfirmBool(xmlElement, "ConsumeInOrder",
queueDBConfig.ConsumeInOrder, compulsory);
Configuration.ConfirmCreatePolicy(xmlElement, "Creation",
queueDBConfig.Creation, compulsory);
Configuration.ConfirmUint(xmlElement, "Length",
queueDBConfig.Length, compulsory);
Configuration.ConfirmInt(xmlElement, "PadByte",
queueDBConfig.PadByte, compulsory);
Configuration.ConfirmUint(xmlElement, "ExtentSize",
queueDBConfig.ExtentSize, compulsory);
}
示例5: GetCursur
public void GetCursur(string dbFileName, bool ifConfig)
{
QueueDatabaseConfig dbConfig = new QueueDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Length = 100;
QueueDatabase db = QueueDatabase.Open(dbFileName, dbConfig);
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(BitConverter.GetBytes((int)1)),
new DatabaseEntry(BitConverter.GetBytes((int)1))));
Cursor dupCursor = cursor.Duplicate(false);
Assert.IsNull(dupCursor.Current.Key);
Assert.AreEqual(CachePriority.HIGH, dupCursor.Priority);
dupCursor.Close();
cursor.Close();
db.Close();
}
示例6: Config
public static void Config(XmlElement xmlElement,
ref QueueDatabaseConfig queueDBConfig, bool compulsory)
{
uint uintValue = new uint();
int intValue = new int();
DatabaseConfig dbConfig = queueDBConfig;
Config(xmlElement, ref dbConfig, compulsory);
// Configure specific fields/properties of Queue database
Configuration.ConfigBool(xmlElement, "ConsumeInOrder",
ref queueDBConfig.ConsumeInOrder, compulsory);
Configuration.ConfigCreatePolicy(xmlElement, "Creation",
ref queueDBConfig.Creation, compulsory);
if (Configuration.ConfigUint(xmlElement, "Length",
ref uintValue, compulsory))
queueDBConfig.Length = uintValue;
if (Configuration.ConfigInt(xmlElement, "PadByte",
ref intValue, compulsory))
queueDBConfig.PadByte = intValue;
if (Configuration.ConfigUint(xmlElement, "ExtentSize",
ref uintValue, compulsory))
queueDBConfig.ExtentSize = uintValue;
}
示例7: TestMessageFile
public void TestMessageFile()
{
testName = "TestMessageFile";
SetUpTest(true);
// Configure and open an environment.
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
// Configure and open a database.
QueueDatabaseConfig DBConfig =
new QueueDatabaseConfig();
DBConfig.Env = env;
DBConfig.Creation = CreatePolicy.IF_NEEDED;
string DBFileName = testName + ".db";
QueueDatabase db = QueueDatabase.Open(
DBFileName, DBConfig);
// Confirm message file does not exist.
string messageFile = testHome + "/" + "msgfile";
Assert.AreEqual(false, File.Exists(messageFile));
// Call set_msgfile() of db.
db.Msgfile = messageFile;
// Print db statistic to message file.
db.PrintStats(true);
// Confirm message file exists now.
Assert.AreEqual(true, File.Exists(messageFile));
db.Msgfile = "";
string line = null;
// Read the third line of message file.
System.IO.StreamReader file = new System.IO.StreamReader(@"" + messageFile);
line = file.ReadLine();
line = file.ReadLine();
line = file.ReadLine();
// Confirm the message file is not empty.
Assert.AreEqual(line, "DB handle information:");
file.Close();
// Close database and environment.
db.Close();
env.Close();
}
示例8: TestKeyEmptyException
public void TestKeyEmptyException()
{
testName = "TestKeyEmptyException";
SetUpTest(true);
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseLocking = true;
envConfig.UseLogging = true;
envConfig.UseMPool = true;
envConfig.UseTxns = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
QueueDatabase db;
try
{
Transaction openTxn = env.BeginTransaction();
try
{
QueueDatabaseConfig queueConfig =
new QueueDatabaseConfig();
queueConfig.Creation = CreatePolicy.IF_NEEDED;
queueConfig.Length = 10;
queueConfig.Env = env;
db = QueueDatabase.Open(testName + ".db",
queueConfig, openTxn);
openTxn.Commit();
}
catch (DatabaseException e)
{
openTxn.Abort();
throw e;
}
Transaction cursorTxn = env.BeginTransaction();
Cursor cursor;
try
{
/*
* Put a record into queue database with
* cursor and abort the operation.
*/
cursor = db.Cursor(cursorTxn);
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(BitConverter.GetBytes((int)10)),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
cursor.Add(pair);
cursor.Close();
cursorTxn.Abort();
}
catch (DatabaseException e)
{
cursorTxn.Abort();
db.Close();
throw e;
}
Transaction delTxn = env.BeginTransaction();
try
{
/*
* The put operation is aborted in the queue
* database so querying if the record still exists
* throws KeyEmptyException.
*/
db.Exists(new DatabaseEntry(
BitConverter.GetBytes((int)10)), delTxn);
delTxn.Commit();
}
catch (DatabaseException e)
{
delTxn.Abort();
throw e;
}
finally
{
db.Close();
}
}
catch (KeyEmptyException)
{
throw new ExpectedTestException();
}
finally
{
env.Close();
}
}
示例9: GetCursur
public void GetCursur(string dbFileName, bool ifConfig)
{
QueueDatabaseConfig dbConfig = new QueueDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Length = 100;
QueueDatabase db = QueueDatabase.Open(dbFileName, dbConfig);
Cursor cursor;
if (ifConfig == false)
cursor = db.Cursor();
else
cursor = db.Cursor(new CursorConfig());
cursor.Close();
db.Close();
}
示例10: TestDeleteMultipleKey
public void TestDeleteMultipleKey()
{
testName = "TestDeleteMultipleKey";
SetUpTest(true);
QueueDatabaseConfig dbConfig = new QueueDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.ExtentSize = 1024;
dbConfig.Length = 520;
QueueDatabase db = QueueDatabase.Open(testHome + "/" +
testName + ".db", dbConfig);
List<KeyValuePair<DatabaseEntry, DatabaseEntry>> pList =
new List<KeyValuePair<DatabaseEntry, DatabaseEntry>>();
DatabaseEntry key, data;
for (uint i = 1; i <= 100; i++)
{
key = new DatabaseEntry(
BitConverter.GetBytes(i));
data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes(
"data" + i.ToString() +
Configuration.RandomString(512)));
pList.Add(new KeyValuePair<
DatabaseEntry, DatabaseEntry>(key, data));
db.Put(key, data);
}
// Create key/value pair bulk buffer and delete all.
db.Delete(new MultipleKeyDatabaseEntry(pList, true));
// Verify that the database is empty.
Assert.AreEqual(0, db.Truncate());
db.Close();
}
示例11: Open
/// <summary>
/// Instantiate a new QueueDatabase object and open the database
/// represented by <paramref name="Filename"/>.
/// </summary>
/// <remarks>
/// <para>
/// If <paramref name="Filename"/> is null, the database is strictly
/// temporary and cannot be opened by any other thread of control, thus
/// the database can only be accessed by sharing the single database
/// object that created it, in circumstances where doing so is safe.
/// </para>
/// <para>
/// If <paramref name="txn"/> is null, but
/// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation will
/// be implicitly transaction protected. Note that transactionally
/// protected operations on a datbase object requires the object itself
/// be transactionally protected during its open. Also note that the
/// transaction must be committed before the object is closed.
/// </para>
/// </remarks>
/// <param name="Filename">
/// The name of an underlying file that will be used to back the
/// database. In-memory databases never intended to be preserved on disk
/// may be created by setting this parameter to null.
/// </param>
/// <param name="cfg">The database's configuration</param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null.
/// </param>
/// <returns>A new, open database object</returns>
public static QueueDatabase Open(
string Filename, QueueDatabaseConfig cfg, Transaction txn)
{
QueueDatabase ret = new QueueDatabase(cfg.Env, 0);
ret.Config(cfg);
ret.db.open(Transaction.getDB_TXN(txn),
Filename, null, DBTYPE.DB_QUEUE, cfg.openFlags, 0);
ret.isOpen = true;
return ret;
}
示例12: TestStats
public void TestStats()
{
testName = "TestStats";
SetUpTest(true);
string dbFileName = testHome + "/" +
testName + ".db";
QueueDatabaseConfig dbConfig =
new QueueDatabaseConfig();
ConfigCase1(dbConfig);
QueueDatabase db = QueueDatabase.Open(dbFileName, dbConfig);
QueueStats stats = db.Stats();
ConfirmStatsPart1Case1(stats);
db.Msgfile = testHome + "/" + testName+ ".log";
db.PrintFastStats(true);
// Put 500 records into the database.
PutRecordCase1(db, null);
stats = db.Stats();
ConfirmStatsPart2Case1(stats);
db.PrintFastStats();
db.Close();
}
示例13: TestPutMultiple
public void TestPutMultiple()
{
testName = "TestPutMultiple";
SetUpTest(true);
QueueDatabaseConfig dbConfig = new QueueDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.ExtentSize = 1024;
dbConfig.Length = 520;
dbConfig.PadByte = 0;
QueueDatabase db = QueueDatabase.Open(testHome + "/" +
testName + ".db", dbConfig);
List<uint> kList = new List<uint>();
List<DatabaseEntry> vList = new List<DatabaseEntry>();
DatabaseEntry key, data;
for (uint i = 1; i <= 9;i++) {
key = new DatabaseEntry(BitConverter.GetBytes(i));
data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("data" + i +
Configuration.RandomString(512)));
kList.Add(i);
vList.Add(data);
}
// Create bulk buffer for recno based keys.
MultipleDatabaseEntry kBuff =
new MultipleDatabaseEntry(kList);
Assert.IsTrue(kBuff.Recno);
int val = 0;
foreach (DatabaseEntry dbt in kBuff) {
Assert.AreEqual(
BitConverter.GetBytes(kList[val]),
dbt.Data);
val++;
}
Assert.AreEqual(9, val);
// Create bulk buffer for data.
MultipleDatabaseEntry vBuff =
new MultipleDatabaseEntry(vList, false);
/*
* Create recno bulk buffer from another recno bulk
* buffer.
*/
MultipleDatabaseEntry kBuff1 =
new MultipleDatabaseEntry(kBuff.Data, kBuff.Recno);
val = 0;
foreach (DatabaseEntry dbt in kBuff1) {
Assert.AreEqual(
BitConverter.GetBytes(kList[val]),
dbt.Data);
val++;
}
Assert.AreEqual(9, val);
// Bulk insert to database with key and value buffers.
db.Put(kBuff, vBuff);
Cursor cursor = db.Cursor();
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
val = 0;
while (cursor.MoveNext()) {
pair = cursor.Current;
Assert.AreEqual(
BitConverter.GetBytes(kList[val]),
pair.Key.Data);
for (int i = 0; i < 520; i++) {
if (i < vList[val].Data.Length)
Assert.AreEqual(vList[val].Data[i],
pair.Value.Data[i]);
else
// The pad byte is 0.
Assert.AreEqual(0, pair.Value.Data[i]);
}
Assert.IsFalse(cursor.MoveNextDuplicate());
val++;
}
Assert.AreEqual(9, val);
cursor.Close();
db.Close();
}
示例14: TestAppendWithTxn
public void TestAppendWithTxn()
{
testName = "TestAppendWithTxn";
SetUpTest(true);
string queueDBFileName = testHome + "/" + testName + ".db";
string queueDBName =
Path.GetFileNameWithoutExtension(queueDBFileName);
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
testHome, envConfig);
Transaction txn = env.BeginTransaction();
QueueDatabaseConfig queueConfig = new QueueDatabaseConfig();
queueConfig.Creation = CreatePolicy.ALWAYS;
queueConfig.Env = env;
queueConfig.Length = 1000;
/* If environmnet home is set, the file name in
* Open() is the relative path.
*/
QueueDatabase queueDB = QueueDatabase.Open(
queueDBName, queueConfig, txn);
DatabaseEntry data;
int i = 1000;
try
{
while (i > 0)
{
data = new DatabaseEntry(
BitConverter.GetBytes(i));
queueDB.Append(data, txn);
i--;
}
txn.Commit();
}
catch
{
txn.Abort();
}
finally
{
queueDB.Close();
env.Close();
}
}
示例15: TestAppendWithoutTxn
public void TestAppendWithoutTxn()
{
testName = "TestAppendWithoutTxn";
SetUpTest(true);
string queueDBFileName = testHome + "/" + testName + ".db";
QueueDatabaseConfig queueConfig = new QueueDatabaseConfig();
queueConfig.Creation = CreatePolicy.ALWAYS;
queueConfig.Length = 1000;
QueueDatabase queueDB = QueueDatabase.Open(
queueDBFileName, queueConfig);
byte[] byteArr = new byte[4];
byteArr = BitConverter.GetBytes((int)1);
DatabaseEntry data = new DatabaseEntry(byteArr);
uint recno = queueDB.Append(data);
// Confirm that the recno is larger than 0.
Assert.AreNotEqual(0, recno);
// Confirm that the record exists in the database.
byteArr = BitConverter.GetBytes(recno);
DatabaseEntry key = new DatabaseEntry();
key.Data = byteArr;
Assert.IsTrue(queueDB.Exists(key));
queueDB.Close();
}