本文整理汇总了C#中BerkeleyDB.HashDatabaseConfig类的典型用法代码示例。如果您正苦于以下问题:C# HashDatabaseConfig类的具体用法?C# HashDatabaseConfig怎么用?C# HashDatabaseConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashDatabaseConfig类属于BerkeleyDB命名空间,在下文中一共展示了HashDatabaseConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigCase1
public void ConfigCase1(HashDatabaseConfig dbConfig)
{
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
dbConfig.FillFactor = 10;
dbConfig.TableSize = 20;
dbConfig.PageSize = 4096;
}
示例2: GetHashDBAndCursor
public void GetHashDBAndCursor(string home, string name,
out HashDatabase db, out HashCursor cursor)
{
string dbFileName = home + "/" + name + ".db";
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = HashDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
}
示例3: TestConfigWithoutEnv
public override void TestConfigWithoutEnv()
{
testName = "TestConfigWithoutEnv";
SetUpTest(false);
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
HashDatabaseConfig hashConfig = new HashDatabaseConfig();
Config(xmlElem, ref hashConfig, true);
Confirm(xmlElem, hashConfig, true);
}
示例4: Confirm
public static void Confirm(XmlElement xmlElement,
HashDatabaseConfig hashDBConfig, bool compulsory)
{
DatabaseConfig dbConfig = hashDBConfig;
Confirm(xmlElement, dbConfig, compulsory);
// Confirm Hash database specific configuration.
Configuration.ConfirmCreatePolicy(xmlElement,
"Creation", hashDBConfig.Creation, compulsory);
Configuration.ConfirmDuplicatesPolicy(xmlElement,
"Duplicates", hashDBConfig.Duplicates, compulsory);
Configuration.ConfirmUint(xmlElement, "FillFactor",
hashDBConfig.FillFactor, compulsory);
Configuration.ConfirmUint(xmlElement, "NumElements",
hashDBConfig.TableSize, compulsory);
}
示例5: Main
static void Main( string[] args )
{
try {
var cfg = new HashDatabaseConfig();
cfg.Duplicates = DuplicatesPolicy.UNSORTED;
cfg.Creation = CreatePolicy.IF_NEEDED;
cfg.CacheSize = new CacheInfo( 0, 64 * 1024, 1 );
cfg.PageSize = 8 * 1024;
Database db = HashDatabase.Open( "d:\\test.db", "hat_db", cfg );
Console.WriteLine("db opened");
var key = new DatabaseEntry();
var data = new DatabaseEntry();
key.Data = System.Text.Encoding.ASCII.GetBytes("key1");
data.Data = System.Text.Encoding.ASCII.GetBytes("val1");
try {
db.Put( key, data );
db.Put( key, data );
}
catch ( Exception ex ) {
Console.WriteLine( ex.Message );
}
using ( var dbc = db.Cursor() ) {
System.Text.ASCIIEncoding decode = new ASCIIEncoding();
/* Walk through the database and print out key/data pairs. */
Console.WriteLine( "All key : data pairs:" );
foreach ( KeyValuePair<DatabaseEntry, DatabaseEntry> p in dbc )
Console.WriteLine( "{0}::{1}",
decode.GetString( p.Key.Data ), decode.GetString( p.Value.Data ) );
}
db.Close();
Console.WriteLine( "db closed" );
}
catch ( Exception ex ) {
Console.WriteLine( ex.Message );
}
Console.ReadLine();
}
示例6: Config
private void Config(HashDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that does not get the Hash
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
if (cfg.BlobDir != null && cfg.Env == null)
db.set_blob_dir(cfg.BlobDir);
if (cfg.blobThresholdIsSet)
db.set_blob_threshold(cfg.BlobThreshold, 0);
if (cfg.HashFunction != null)
HashFunction = cfg.HashFunction;
// The duplicate comparison function cannot change.
if (cfg.DuplicateCompare != null)
DupCompare = cfg.DuplicateCompare;
if (cfg.fillFactorIsSet)
db.set_h_ffactor(cfg.FillFactor);
if (cfg.nelemIsSet)
db.set_h_nelem(cfg.TableSize);
if (cfg.HashComparison != null)
Compare = cfg.HashComparison;
if (cfg.partitionIsSet) {
nparts = cfg.NParts;
Partition = cfg.Partition;
if (Partition == null)
doPartitionRef = null;
else
doPartitionRef = new BDB_PartitionDelegate(doPartition);
partitionKeys = cfg.PartitionKeys;
IntPtr[] ptrs = null;
if (partitionKeys != null) {
int size = (int)nparts - 1;
ptrs = new IntPtr[size];
for (int i = 0; i < size; i++) {
ptrs[i] = DBT.getCPtr(
DatabaseEntry.getDBT(partitionKeys[i])).Handle;
}
}
db.set_partition(nparts, ptrs, doPartitionRef);
}
}
示例7: Config
private void Config(HashDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that doesn't get the Hash
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
if (cfg.HashFunction != null)
HashFunction = cfg.HashFunction;
// The duplicate comparison function cannot change.
if (cfg.DuplicateCompare != null)
DupCompare = cfg.DuplicateCompare;
if (cfg.fillFactorIsSet)
db.set_h_ffactor(cfg.FillFactor);
if (cfg.nelemIsSet)
db.set_h_nelem(cfg.TableSize);
if (cfg.HashComparison != null)
Compare = cfg.HashComparison;
}
示例8: Config
public static void Config(XmlElement xmlElement,
ref HashDatabaseConfig hashDBConfig, bool compulsory)
{
uint fillFactor = new uint();
uint numElements = new uint();
DatabaseConfig dbConfig = hashDBConfig;
Config(xmlElement, ref dbConfig, compulsory);
// Configure specific fields/properties of Hash db
Configuration.ConfigCreatePolicy(xmlElement,
"Creation", ref hashDBConfig.Creation,
compulsory);
Configuration.ConfigDuplicatesPolicy(xmlElement,
"Duplicates", ref hashDBConfig.Duplicates,
compulsory);
if (Configuration.ConfigUint(xmlElement, "FillFactor",
ref fillFactor, compulsory))
hashDBConfig.FillFactor = fillFactor;
if (Configuration.ConfigUint(xmlElement, "NumElements",
ref numElements, compulsory))
hashDBConfig.TableSize = numElements;
}
示例9: Open
/// <summary>
/// Instantiate a new HashDatabase 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 HashDatabase Open(
string Filename, HashDatabaseConfig cfg, Transaction txn)
{
return Open(Filename, null, cfg, txn);
}
示例10: TestHashFunction
public void TestHashFunction()
{
testName = "TestHashFunction";
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
string dbSecFileName = testHome + "/" +
testName + "_sec.db";
// Open a primary hash database.
HashDatabaseConfig dbConfig =
new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
HashDatabase hashDB = HashDatabase.Open(
dbFileName, dbConfig);
/*
* Define hash function and open a secondary
* hash database.
*/
SecondaryHashDatabaseConfig secDBConfig =
new SecondaryHashDatabaseConfig(hashDB, null);
secDBConfig.HashFunction =
new HashFunctionDelegate(HashFunction);
secDBConfig.Creation = CreatePolicy.IF_NEEDED;
SecondaryHashDatabase secDB =
SecondaryHashDatabase.Open(dbSecFileName,
secDBConfig);
/*
* Confirm the hash function defined in the configuration.
* Call the hash function and the one from secondary
* database. If they return the same value, then the hash
* function is configured successfully.
*/
uint data = secDB.HashFunction(BitConverter.GetBytes(1));
Assert.AreEqual(0, data);
// Close all.
secDB.Close();
hashDB.Close();
}
示例11: TestInsertToLoc
public void TestInsertToLoc()
{
HashDatabase db;
HashDatabaseConfig dbConfig;
HashCursor cursor;
DatabaseEntry data;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
string dbFileName;
testName = "TestInsertToLoc";
SetUpTest(true);
dbFileName = testHome + "/" + testName + ".db";
// Open database and cursor.
dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
/*
* The database should be set to be unsorted to
* insert before/after a certain record.
*/
dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
db = HashDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
// Add record("key", "data") into database.
AddOneByCursor(cursor);
/*
* Insert the new record("key","data1") after the
* record("key", "data").
*/
data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data1"));
cursor.Insert(data, Cursor.InsertLocation.AFTER);
/*
* Move the cursor to the record("key", "data") and
* confirm that the next record is the one just inserted.
*/
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
Assert.IsTrue(cursor.Move(pair, true));
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("key"),
cursor.Current.Key.Data);
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data1"),
cursor.Current.Value.Data);
try {
try {
cursor.Insert(data,
Cursor.InsertLocation.FIRST);
throw new TestException();
} catch (ArgumentException) { }
try
{
cursor.Insert(data,
Cursor.InsertLocation.LAST);
throw new TestException();
} catch (ArgumentException) { }
} finally {
cursor.Close();
db.Close();
}
}
示例12: TestHashComparison
public void TestHashComparison()
{
testName = "TestHashComparison";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.HashComparison = new EntryComparisonDelegate(EntryComparison);
HashDatabase db = HashDatabase.Open(dbFileName,dbConfig);
int ret;
/*
* Comparison gets the value that lowest byte of the
* former dbt minus that of the latter one.
*/
ret = db.Compare(new DatabaseEntry(BitConverter.GetBytes(2)),
new DatabaseEntry(BitConverter.GetBytes(2)));
Assert.AreEqual(0, ret);
ret = db.Compare(new DatabaseEntry(BitConverter.GetBytes(256)),
new DatabaseEntry(BitConverter.GetBytes(1)));
Assert.Greater(0, ret);
db.Close();
}
示例13: TestAddUnique
public void TestAddUnique()
{
HashDatabase db;
HashCursor cursor;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
testName = "TestAddUnique";
SetUpTest(true);
// Open a database and cursor.
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
/*
* To put no duplicate data, the database should be
* set to be sorted.
*/
dbConfig.Duplicates = DuplicatesPolicy.SORTED;
db = HashDatabase.Open(
testHome + "/" + testName + ".db", dbConfig);
cursor = db.Cursor();
// Add record("key", "data") into database.
AddOneByCursor(cursor);
/*
* Fail to add duplicate record("key","data").
*/
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
try
{
cursor.AddUnique(pair);
}
catch (KeyExistException)
{
}
finally
{
cursor.Close();
db.Close();
}
}
示例14: TestConfig
public void TestConfig()
{
testName = "TestConfig";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
// Open a primary btree database.
HashDatabaseConfig hashDBConfig =
new HashDatabaseConfig();
hashDBConfig.Creation = CreatePolicy.IF_NEEDED;
HashDatabase hashDB = HashDatabase.Open(
dbFileName, hashDBConfig);
SecondaryHashDatabaseConfig secDBConfig =
new SecondaryHashDatabaseConfig(hashDB, null);
Config(xmlElem, ref secDBConfig, true);
Confirm(xmlElem, secDBConfig, true);
// Close the primary btree database.
hashDB.Close();
}
示例15: TestOpenNewHashDB
public void TestOpenNewHashDB()
{
testName = "TestOpenNewHashDB";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
XmlElement xmlElem = Configuration.TestSetUp(testFixtureName, testName);
HashDatabaseConfig hashConfig = new HashDatabaseConfig();
HashDatabaseConfigTest.Config(xmlElem, ref hashConfig, true);
HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
Confirm(xmlElem, hashDB, true);
hashDB.Close();
}