本文整理汇总了C#中BerkeleyDB.RecnoDatabaseConfig类的典型用法代码示例。如果您正苦于以下问题:C# RecnoDatabaseConfig类的具体用法?C# RecnoDatabaseConfig怎么用?C# RecnoDatabaseConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecnoDatabaseConfig类属于BerkeleyDB命名空间,在下文中一共展示了RecnoDatabaseConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigCase1
public void ConfigCase1(RecnoDatabaseConfig dbConfig)
{
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.PageSize = 4096;
dbConfig.Length = 4000;
dbConfig.PadByte = 256;
}
示例2: Logging
/*
* Open environment, database and write data into database.
* Generated log files are put under testHome.
*/
public void Logging(string home, string dbName,
out DatabaseEnvironment env, out RecnoDatabase recnoDB)
{
string dbFileName = dbName + ".db";
Configuration.ClearDir(home);
// Open environment with logging subsystem.
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseLogging = true;
envConfig.LogSystemCfg = new LogConfig();
envConfig.LogSystemCfg.FileMode = 755;
envConfig.LogSystemCfg.ZeroOnCreate = true;
envConfig.UseMPool = true;
env = DatabaseEnvironment.Open(home, envConfig);
/*
* Open recno database, write 100000 records into
* the database and close it.
*/
RecnoDatabaseConfig recnoConfig =
new RecnoDatabaseConfig();
recnoConfig.Creation = CreatePolicy.IF_NEEDED;
recnoConfig.Env = env;
// The db needs mpool to open.
recnoConfig.NoMMap = false;
recnoDB = RecnoDatabase.Open(dbFileName,
recnoConfig);
for (int i = 0; i < 1000; i++)
recnoDB.Append(new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("key")));
}
示例3: Config
public static void Config(XmlElement xmlElement,
ref RecnoDatabaseConfig recnoDBConfig, bool compulsory)
{
int intValue = new int();
uint uintValue = new uint();
DatabaseConfig dbConfig = recnoDBConfig;
Config(xmlElement, ref dbConfig, compulsory);
// Configure specific fields/properties of Recno database
Configuration.ConfigCreatePolicy(xmlElement, "Creation",
ref recnoDBConfig.Creation, compulsory);
if (Configuration.ConfigInt(xmlElement, "Delimiter",
ref intValue, compulsory))
recnoDBConfig.Delimiter = intValue;
if (Configuration.ConfigUint(xmlElement, "Length",
ref uintValue, compulsory))
recnoDBConfig.Length = uintValue;
if (Configuration.ConfigInt(xmlElement, "PadByte",
ref intValue, compulsory))
recnoDBConfig.PadByte = intValue;
Configuration.ConfigBool(xmlElement, "Renumber",
ref recnoDBConfig.Renumber, compulsory);
Configuration.ConfigBool(xmlElement, "Snapshot",
ref recnoDBConfig.Snapshot, compulsory);
}
示例4: GetCursorWithImplicitTxn
public void GetCursorWithImplicitTxn(string home,
string dbFile, bool ifConfig)
{
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseCDB = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
home, envConfig);
RecnoDatabaseConfig dbConfig =
new RecnoDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
RecnoDatabase db = RecnoDatabase.Open(dbFile,
dbConfig);
RecnoCursor cursor;
if (ifConfig == false)
cursor = db.Cursor();
else
cursor = db.Cursor(new CursorConfig());
cursor.Close();
db.Close();
env.Close();
}
示例5: GetCursorWithExplicitTxn
public void GetCursorWithExplicitTxn(string home,
string dbFile, bool ifConfig)
{
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
home, envConfig);
Transaction openTxn = env.BeginTransaction();
RecnoDatabaseConfig dbConfig =
new RecnoDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
RecnoDatabase db = RecnoDatabase.Open(dbFile,
dbConfig, openTxn);
openTxn.Commit();
Transaction cursorTxn = env.BeginTransaction();
RecnoCursor cursor;
if (ifConfig == false)
cursor = db.Cursor(cursorTxn);
else
cursor = db.Cursor(new CursorConfig(), cursorTxn);
cursor.Close();
cursorTxn.Commit();
db.Close();
env.Close();
}
示例6: Config
private void Config(RecnoDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that doesn't get the Recno
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
if (cfg.delimiterIsSet)
RecordDelimiter = cfg.Delimiter;
if (cfg.lengthIsSet)
RecordLength = cfg.Length;
if (cfg.padIsSet)
RecordPad = cfg.PadByte;
if (cfg.BackingFile != null)
SourceFile = cfg.BackingFile;
}
示例7: Confirm
public static void Confirm(XmlElement xmlElement,
RecnoDatabaseConfig recnoDBConfig, bool compulsory)
{
DatabaseConfig dbConfig = recnoDBConfig;
Confirm(xmlElement, dbConfig, compulsory);
// Confirm Recno database specific configuration
Configuration.ConfirmString(xmlElement, "BackingFile",
recnoDBConfig.BackingFile, compulsory);
Configuration.ConfirmCreatePolicy(xmlElement,
"Creation", recnoDBConfig.Creation, compulsory);
Configuration.ConfirmInt(xmlElement, "Delimiter",
recnoDBConfig.Delimiter, compulsory);
Configuration.ConfirmUint(xmlElement, "Length",
recnoDBConfig.Length, compulsory);
Configuration.ConfirmInt(xmlElement, "PadByte",
recnoDBConfig.PadByte, compulsory);
Configuration.ConfirmBool(xmlElement, "Renumber",
recnoDBConfig.Renumber, compulsory);
Configuration.ConfirmBool(xmlElement, "Snapshot",
recnoDBConfig.Snapshot, compulsory);
}
示例8: OpenSecRecnoDB
public void OpenSecRecnoDB(string className,
string funName, string dbFileName, string dbSecFileName,
bool ifDBName)
{
XmlElement xmlElem = Configuration.TestSetUp(
className, funName);
// Open a primary recno database.
RecnoDatabaseConfig primaryDBConfig =
new RecnoDatabaseConfig();
primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
RecnoDatabase primaryDB;
/*
* If secondary database name is given, the primary
* database is also opened with database name.
*/
if (ifDBName == false)
primaryDB = RecnoDatabase.Open(dbFileName,
primaryDBConfig);
else
primaryDB = RecnoDatabase.Open(dbFileName,
"primary", primaryDBConfig);
try
{
// Open a new secondary database.
SecondaryRecnoDatabaseConfig secRecnoDBConfig =
new SecondaryRecnoDatabaseConfig(
primaryDB, null);
SecondaryRecnoDatabaseConfigTest.Config(
xmlElem, ref secRecnoDBConfig, false);
secRecnoDBConfig.Creation =
CreatePolicy.IF_NEEDED;
SecondaryRecnoDatabase secRecnoDB;
if (ifDBName == false)
secRecnoDB = SecondaryRecnoDatabase.Open(
dbSecFileName, secRecnoDBConfig);
else
secRecnoDB = SecondaryRecnoDatabase.Open(
dbSecFileName, "secondary",
secRecnoDBConfig);
// Close the secondary database.
secRecnoDB.Close();
// Open the existing secondary database.
SecondaryDatabaseConfig secDBConfig =
new SecondaryDatabaseConfig(
primaryDB, null);
SecondaryDatabase secDB;
if (ifDBName == false)
secDB = SecondaryRecnoDatabase.Open(
dbSecFileName, secDBConfig);
else
secDB = SecondaryRecnoDatabase.Open(
dbSecFileName, "secondary", secDBConfig);
// Close secondary database.
secDB.Close();
}
catch (DatabaseException)
{
throw new TestException();
}
finally
{
// Close primary database.
primaryDB.Close();
}
}
示例9: OpenSecRecnoDBWithinTxn
public void OpenSecRecnoDBWithinTxn(string className,
string funName, string home, string dbFileName,
string dbSecFileName, bool ifDbName)
{
XmlElement xmlElem = Configuration.TestSetUp(
className, funName);
// Open an environment.
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
envConfig.UseLogging = true;
DatabaseEnvironment env = DatabaseEnvironment.Open(
home, envConfig);
// Open a primary recno database.
Transaction openDBTxn = env.BeginTransaction();
RecnoDatabaseConfig dbConfig =
new RecnoDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Env = env;
RecnoDatabase db = RecnoDatabase.Open(
dbFileName, dbConfig, openDBTxn);
openDBTxn.Commit();
// Open a secondary recno database.
Transaction openSecTxn = env.BeginTransaction();
SecondaryRecnoDatabaseConfig secDBConfig =
new SecondaryRecnoDatabaseConfig(db,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
SecondaryRecnoDatabaseConfigTest.Config(xmlElem,
ref secDBConfig, false);
secDBConfig.Env = env;
SecondaryRecnoDatabase secDB;
if (ifDbName == false)
secDB = SecondaryRecnoDatabase.Open(
dbSecFileName, secDBConfig, openSecTxn);
else
secDB = SecondaryRecnoDatabase.Open(
dbSecFileName, "secondary", secDBConfig,
openSecTxn);
openSecTxn.Commit();
// Confirm its flags configured in secDBConfig.
Confirm(xmlElem, secDB, true);
secDB.Close();
// Open the existing secondary database.
Transaction secTxn = env.BeginTransaction();
SecondaryDatabaseConfig secConfig =
new SecondaryDatabaseConfig(db,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secConfig.Env = env;
SecondaryDatabase secExDB;
if (ifDbName == false)
secExDB = SecondaryRecnoDatabase.Open(
dbSecFileName, secConfig, secTxn);
else
secExDB = SecondaryRecnoDatabase.Open(
dbSecFileName, "secondary", secConfig,
secTxn);
secExDB.Close();
secTxn.Commit();
db.Close();
env.Close();
}
示例10: 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();
}
示例11: TestAppend
public void TestAppend()
{
uint recno;
testName = "TestAppend";
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
RecnoDatabaseConfig recnoConfig =
new RecnoDatabaseConfig();
recnoConfig.Creation = CreatePolicy.IF_NEEDED;
recnoConfig.Append = new AppendRecordDelegate(
AppendRecord);
RecnoDatabase recnoDB = RecnoDatabase.Open(
dbFileName, recnoConfig);
recno = recnoDB.Append(new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("data")));
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
pair = recnoDB.Get(
new DatabaseEntry(BitConverter.GetBytes(recno)));
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data"),
pair.Value.Data);
recnoDB.Close();
}
示例12: TestInsertToLoc
public void TestInsertToLoc()
{
RecnoDatabase db;
RecnoDatabaseConfig dbConfig;
RecnoCursor cursor;
DatabaseEntry data;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
string dbFileName;
testName = "TestInsertToLoc";
testHome = testFixtureHome + "/" + testName;
dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
// Open database and cursor.
dbConfig = new RecnoDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Renumber = true;
db = RecnoDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
// Add record(1,1) into database.
/*
* Add a record(1, 1) by cursor and move
* the cursor to the current record.
*/
AddOneByCursor(cursor);
cursor.Refresh();
/*
* Insert the new record(1,10) after the
* record(1,1).
*/
data = new DatabaseEntry(
BitConverter.GetBytes((int)10));
cursor.Insert(data, Cursor.InsertLocation.AFTER);
/*
* Move the cursor to the record(1,1) and
* confirm that the next record is the one just inserted.
*/
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(
BitConverter.GetBytes((int)1)),
new DatabaseEntry(
BitConverter.GetBytes((int)1)));
Assert.IsTrue(cursor.Move(pair, true));
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(BitConverter.GetBytes((int)10),
cursor.Current.Value.Data);
cursor.Close();
db.Close();
}
示例13: TestConfig
public void TestConfig()
{
testName = "TestConfig";
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
// Open a primary btree database.
RecnoDatabaseConfig recDBConfig =
new RecnoDatabaseConfig();
recDBConfig.Creation = CreatePolicy.IF_NEEDED;
RecnoDatabase recDB = RecnoDatabase.Open(
dbFileName, recDBConfig);
SecondaryRecnoDatabaseConfig secDBConfig =
new SecondaryRecnoDatabaseConfig(recDB, null);
Config(xmlElem, ref secDBConfig, true);
Confirm(xmlElem, secDBConfig, true);
// Close the primary btree database.
recDB.Close();
}
示例14: TestForeignKeyDelete
public void TestForeignKeyDelete(DatabaseType dbtype, ForeignKeyDeleteAction action)
{
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
string fdbFileName = testHome + "/" + testName + "foreign.db";
string sdbFileName = testHome + "/" + testName + "sec.db";
Database primaryDB, fdb;
SecondaryDatabase secDB;
// Open primary database.
if (dbtype == DatabaseType.BTREE) {
BTreeDatabaseConfig btConfig = new BTreeDatabaseConfig();
btConfig.Creation = CreatePolicy.ALWAYS;
primaryDB = BTreeDatabase.Open(dbFileName, btConfig);
fdb = BTreeDatabase.Open(fdbFileName, btConfig);
} else if (dbtype == DatabaseType.HASH) {
HashDatabaseConfig hConfig = new HashDatabaseConfig();
hConfig.Creation = CreatePolicy.ALWAYS;
primaryDB = HashDatabase.Open(dbFileName, hConfig);
fdb = HashDatabase.Open(fdbFileName, hConfig);
} else if (dbtype == DatabaseType.QUEUE) {
QueueDatabaseConfig qConfig = new QueueDatabaseConfig();
qConfig.Creation = CreatePolicy.ALWAYS;
qConfig.Length = 4;
primaryDB = QueueDatabase.Open(dbFileName, qConfig);
fdb = QueueDatabase.Open(fdbFileName, qConfig);
} else if (dbtype == DatabaseType.RECNO) {
RecnoDatabaseConfig rConfig = new RecnoDatabaseConfig();
rConfig.Creation = CreatePolicy.ALWAYS;
primaryDB = RecnoDatabase.Open(dbFileName, rConfig);
fdb = RecnoDatabase.Open(fdbFileName, rConfig);
} else {
throw new ArgumentException("Invalid DatabaseType");
}
// Open secondary database.
if (dbtype == DatabaseType.BTREE) {
SecondaryBTreeDatabaseConfig secbtConfig =
new SecondaryBTreeDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secbtConfig.Creation = CreatePolicy.ALWAYS;
secbtConfig.Duplicates = DuplicatesPolicy.SORTED;
if (action == ForeignKeyDeleteAction.NULLIFY)
secbtConfig.SetForeignKeyConstraint(fdb, action, new ForeignKeyNullifyDelegate(Nullify));
else
secbtConfig.SetForeignKeyConstraint(fdb, action);
secDB = SecondaryBTreeDatabase.Open(sdbFileName, secbtConfig);
} else if (dbtype == DatabaseType.HASH) {
SecondaryHashDatabaseConfig sechConfig =
new SecondaryHashDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
sechConfig.Creation = CreatePolicy.ALWAYS;
sechConfig.Duplicates = DuplicatesPolicy.SORTED;
if (action == ForeignKeyDeleteAction.NULLIFY)
sechConfig.SetForeignKeyConstraint(fdb, action, new ForeignKeyNullifyDelegate(Nullify));
else
sechConfig.SetForeignKeyConstraint(fdb, action);
secDB = SecondaryHashDatabase.Open(sdbFileName, sechConfig);
} else if (dbtype == DatabaseType.QUEUE) {
SecondaryQueueDatabaseConfig secqConfig =
new SecondaryQueueDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secqConfig.Creation = CreatePolicy.ALWAYS;
secqConfig.Length = 4;
if (action == ForeignKeyDeleteAction.NULLIFY)
secqConfig.SetForeignKeyConstraint(fdb, action, new ForeignKeyNullifyDelegate(Nullify));
else
secqConfig.SetForeignKeyConstraint(fdb, action);
secDB = SecondaryQueueDatabase.Open(sdbFileName, secqConfig);
} else if (dbtype == DatabaseType.RECNO) {
SecondaryRecnoDatabaseConfig secrConfig =
new SecondaryRecnoDatabaseConfig(primaryDB,
new SecondaryKeyGenDelegate(SecondaryKeyGen));
secrConfig.Creation = CreatePolicy.ALWAYS;
if (action == ForeignKeyDeleteAction.NULLIFY)
secrConfig.SetForeignKeyConstraint(fdb, action, new ForeignKeyNullifyDelegate(Nullify));
else
secrConfig.SetForeignKeyConstraint(fdb, action);
secDB = SecondaryRecnoDatabase.Open(sdbFileName, secrConfig);
} else {
throw new ArgumentException("Invalid DatabaseType");
}
/* Use integer keys for Queue/Recno support. */
fdb.Put(new DatabaseEntry(BitConverter.GetBytes(100)),
new DatabaseEntry(BitConverter.GetBytes(1001)));
fdb.Put(new DatabaseEntry(BitConverter.GetBytes(200)),
new DatabaseEntry(BitConverter.GetBytes(2002)));
fdb.Put(new DatabaseEntry(BitConverter.GetBytes(300)),
new DatabaseEntry(BitConverter.GetBytes(3003)));
primaryDB.Put(new DatabaseEntry(BitConverter.GetBytes(1)),
new DatabaseEntry(BitConverter.GetBytes(100)));
primaryDB.Put(new DatabaseEntry(BitConverter.GetBytes(2)),
new DatabaseEntry(BitConverter.GetBytes(200)));
if (dbtype == DatabaseType.BTREE || dbtype == DatabaseType.HASH)
primaryDB.Put(new DatabaseEntry(BitConverter.GetBytes(3)),
new DatabaseEntry(BitConverter.GetBytes(100)));
//.........这里部分代码省略.........
示例15: TestOpenNewRecnoDB
public void TestOpenNewRecnoDB()
{
RecnoDatabase recnoDB;
RecnoDatabaseConfig recnoConfig;
testName = "TestOpenNewRecnoDB";
testHome = testFixtureHome + "/" + testName;
string recnoDBFileName = testHome + "/" +
testName + ".db";
Configuration.ClearDir(testHome);
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
recnoConfig = new RecnoDatabaseConfig();
RecnoDatabaseConfigTest.Config(xmlElem,
ref recnoConfig, true);
recnoDB = RecnoDatabase.Open(recnoDBFileName,
recnoConfig);
Confirm(xmlElem, recnoDB, true);
recnoDB.Close();
}