本文整理汇总了C#中BerkeleyDB.Transaction类的典型用法代码示例。如果您正苦于以下问题:C# Transaction类的具体用法?C# Transaction怎么用?C# Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于BerkeleyDB命名空间,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EstimatedQueryCost
public double EstimatedQueryCost(Transaction transaction)
{
var endOfKeyRange = string.Concat(Key, new string(char.MaxValue, 1));
return (managedIndex.Index.KeyRange(new DatabaseEntry(managedIndex.KeyAsByteArray(endOfKeyRange)), transaction).Less -
managedIndex.Index.KeyRange(new DatabaseEntry(managedIndex.KeyAsByteArray(Key)), transaction).Less) *
managedIndex.Index.FastStats().nPages / pageSizeBufferMultipler * (double)QueryCostScale;
}
示例2: SetUpEnvWithTxnAndLocking
public static void SetUpEnvWithTxnAndLocking(string envHome,
out DatabaseEnvironment env, out Transaction txn,
uint maxLock, uint maxLocker, uint maxObject, uint partition)
{
// Configure env and locking subsystem.
LockingConfig lkConfig = new LockingConfig();
/*
* If the maximum number of locks/lockers/objects
* is given, then the LockingConfig is set. Unless,
* it is not set to any value.
*/
if (maxLock != 0)
lkConfig.MaxLocks = maxLock;
if (maxLocker != 0)
lkConfig.MaxLockers = maxLocker;
if (maxObject != 0)
lkConfig.MaxObjects = maxObject;
if (partition != 0)
lkConfig.Partitions = partition;
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
envConfig.Create = true;
envConfig.UseTxns = true;
envConfig.UseMPool = true;
envConfig.LockSystemCfg = lkConfig;
envConfig.UseLocking = true;
envConfig.NoLocking = false;
env = DatabaseEnvironment.Open(envHome, envConfig);
txn = env.BeginTransaction();
}
示例3: Execute
public IEnumerable<InternalId> Execute(Transaction transaction)
{
var cursor = managedIndex.Index.Cursor(new CursorConfig(), transaction);
try
{
var comparer = managedIndex.Comparer;
var keyAsBytes = managedIndex.KeyAsByteArray(Key);
var bufferSize = (int)managedIndex.Index.Pagesize * pageSizeBufferMultipler;
if(cursor.MoveMultipleKey(new DatabaseEntry(keyAsBytes), false, bufferSize))
{
do
{
//Each char is 2 bytes. Only take the start of the key data to the length of the query key.
foreach(var internalId in
cursor.CurrentMultipleKey
.Select(_ => new {key = _.Key.Data.Take(Key.Length * 2).ToArray(), value = _.Value.Data.AsInternalId()})
.TakeWhile(pair => comparer.Compare(managedIndex.ByteArrayAsKey(pair.key), Key) == 0)
.Select(_ => _.value))
{
yield return internalId;
}
}
while(cursor.MoveNextMultipleKey(bufferSize) &&
comparer.Compare(managedIndex.ByteArrayAsKey(cursor.CurrentMultipleKey.First().Key.Data), Key) == 0);
}
}
finally
{
cursor.Close();
}
}
示例4: Execute
public IEnumerable<InternalId> Execute(Transaction transaction)
{
var cursor = managedIndex.ReverseIndex.Cursor();
while(cursor.MoveNextUnique())
{
yield return cursor.Current.Key.Data.AsInternalId();
}
}
示例5: ExecuteInsideIntersect
public IEnumerable<InternalId> ExecuteInsideIntersect(Transaction transaction, IEnumerable<InternalId> joinConstraint)
{
if(joinConstraint.Count() > EstimatedQueryCost(transaction))
return Execute(transaction);
var cursor = managedIndex.ReverseIndex.Cursor();
return
joinConstraint
.Where(joinMatched => cursor.Move(new DatabaseEntry(joinMatched.AsByteArray()), true));
}
示例6: Sequence
/// <summary>
/// Instantiate a new Sequence object.
/// </summary>
/// <remarks>
/// If <paramref name="txn"/> is null and the operation occurs in a
/// transactional database, the operation will be implicitly transaction
/// protected.
/// </remarks>
/// <param name="cfg">Configuration parameters for the Sequence</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>
public Sequence(SequenceConfig cfg, Transaction txn) {
seq = new DB_SEQUENCE(cfg.BackingDatabase.db, 0);
if (cfg.initialValIsSet)
seq.initial_value(cfg.InitialValue);
seq.set_flags(cfg.flags);
if (cfg.rangeIsSet)
seq.set_range(cfg.Min, cfg.Max);
if (cfg.cacheSzIsSet)
seq.set_cachesize(cfg.CacheSize);
seq.open(Transaction.getDB_TXN(txn),
cfg.key, cfg.openFlags);
isOpen = true;
}
示例7: OpenBtreeDBInEnv
public void OpenBtreeDBInEnv(string dbName,
DatabaseEnvironment env, out BTreeDatabase db,
bool create, Transaction txn)
{
BTreeDatabaseConfig btreeDBConfig =
new BTreeDatabaseConfig();
btreeDBConfig.Env = env;
if (create == true)
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;
else
btreeDBConfig.Creation = CreatePolicy.NEVER;
if (txn == null)
db = BTreeDatabase.Open(dbName,
btreeDBConfig);
else
db = BTreeDatabase.Open(dbName,
btreeDBConfig, txn);
}
示例8: SecondaryCursor
/// <summary>
/// Create a transactionally protected secondary database cursor.
/// </summary>
/// <param name="txn">
/// The transaction context in which the cursor may be used.
/// </param>
/// <returns>A newly created cursor</returns>
public SecondaryCursor SecondaryCursor(Transaction txn) {
return SecondaryCursor(new CursorConfig(), txn);
}
示例9: Open
/// <summary>
/// Instantiate a new SecondaryDatabase object, open the database
/// represented by <paramref name="Filename"/> and associate the
/// database with the <see cref="SecondaryDatabaseConfig.Primary">
/// primary index</see>. The file specified by
/// <paramref name="Filename"/> must exist.
/// </summary>
/// <remarks>
/// <para>
/// If <see cref="DatabaseConfig.AutoCommit"/> is set, the operation
/// is implicitly transaction protected. Transactionally
/// protected operations on a database object requires the object itself
/// be transactionally protected during its open.
/// </para>
/// </remarks>
/// <param name="Filename">
/// The name of an underlying file used to back the
/// database.
/// </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 SecondaryDatabase Open(string Filename,
SecondaryDatabaseConfig cfg, Transaction txn) {
return Open(Filename, null, cfg, txn);
}
示例10: GetMultiple
/// <summary>
/// Retrieve a key and all duplicate data items from the database.
/// </summary>
/// <param name="key">The key to search for</param>
/// <param name="BufferSize">
/// The initial size of the buffer to fill with duplicate data items. If
/// the buffer is not large enough, it is automatically resized.
/// </param>
/// <param name="txn">
/// <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 <see cref="KeyValuePair{T,T}"/>
/// whose Key parameter is <paramref name="key"/> and whose Value
/// parameter is the retrieved data items.
/// </returns>
public KeyValuePair<DatabaseEntry, MultipleDatabaseEntry> GetMultiple(
DatabaseEntry key, int BufferSize, Transaction txn)
{
return GetMultiple(key, BufferSize, txn, null);
}
示例11: Open
/// <summary>
/// Instantiate a new Database object and open the database represented
/// by <paramref name="Filename"/> and <paramref name="DatabaseName"/>.
/// The file specified by <paramref name="Filename"/> must exist.
/// </summary>
/// <remarks>
/// <para>
/// If both <paramref name="Filename"/> and
/// <paramref name="DatabaseName"/> are 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. If
/// <paramref name="Filename"/> is null and
/// <paramref name="DatabaseName"/> is non-null, the database can be
/// opened by other threads of control and be replicated to client
/// sites in any replication group.
/// </para>
/// <para>
/// If <paramref name="txn"/> is null, but
/// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation
/// is implicitly transaction protected. Transactionally
/// protected operations on a database object requires the object itself
/// be transactionally protected during its open. The
/// transaction must be committed before the object is closed.
/// </para>
/// </remarks>
/// <param name="Filename">
/// The name of an underlying file 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="DatabaseName">
/// This parameter allows applications to have multiple databases in a
/// single file. Although no DatabaseName needs to be specified, it is
/// an error to attempt to open a second database in a file that was not
/// initially created using a database name.
/// </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 new Database Open(string Filename,
string DatabaseName, DatabaseConfig cfg, Transaction txn)
{
Database ret;
BaseDatabase db = BaseDatabase.Open(
Filename, DatabaseName, cfg, txn);
switch (db.Type.getDBTYPE()) {
case DBTYPE.DB_BTREE:
ret = new BTreeDatabase(db);
break;
case DBTYPE.DB_HASH:
ret = new HashDatabase(db);
break;
case DBTYPE.DB_HEAP:
ret = new HeapDatabase(db);
break;
case DBTYPE.DB_QUEUE:
ret = new QueueDatabase(db);
break;
case DBTYPE.DB_RECNO:
ret = new RecnoDatabase(db);
break;
default:
throw new DatabaseException(0);
}
db.Dispose();
ret.isOpen = true;
return ret;
}
示例12: PutNoOverwrite
/// <summary>
/// Store the key/data pair in the database, only if the key does not
/// already appear in the database.
/// </summary>
/// <remarks>
/// This enforcement of uniqueness of keys applies only to the primary
/// key, the behavior of insertions into secondary databases is not
/// affected. In particular, the insertion of a record that would result
/// in the creation of a duplicate key in a secondary database that
/// allows duplicates would not be prevented by the use of this flag.
/// </remarks>
/// <param name="key">The key to store in the database</param>
/// <param name="data">The data item to store in the database</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>
public void PutNoOverwrite(
DatabaseEntry key, DatabaseEntry data, Transaction txn)
{
Put(key, data, txn, DbConstants.DB_NOOVERWRITE);
}
示例13: Put
/// <summary>
/// Store the key/data pair in the database, replacing any previously
/// existing key if duplicates are disallowed, or adding a duplicate
/// data item if duplicates are allowed.
/// </summary>
/// <remarks>
/// <para>
/// When partial put to a duplicate database, a
/// <see cref="DatabaseException"/> is thrown.
/// </para>
/// </remarks>
/// <param name="key">The key to store in the database</param>
/// <param name="data">The data item to store in the database</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>
/// <exception cref="DatabaseException">
/// Partial put to a duplicate database, or <see cref="QueueDatabase"/>
/// or <see cref="RecnoDatabase"/> with fixed-length records.
/// </exception>
public void Put(
DatabaseEntry key, DatabaseEntry data, Transaction txn)
{
Put(key, data, txn, 0);
}
示例14: CursorReadUncommited
/*
* Configure a transactional cursor to have degree 1
* isolation. The cursor's read operations could return
* modified but not yet commited data.
*/
public void CursorReadUncommited(
DatabaseEnvironment env, BTreeDatabase db,
Cursor cursor, Transaction txn)
{
Console.WriteLine("CursorReadUncommited");
}
示例15: UpdateTxn
public void UpdateTxn()
{
int int32Value;
DatabaseEntry data;
// Get a new transaction for updating the db.
TransactionConfig txnConfig =
new TransactionConfig();
txnConfig.IsolationDegree =
Isolation.DEGREE_THREE;
updateTxn =
paramEnv.BeginTransaction(txnConfig);
// Continually putting record to db.
BTreeCursor cursor =
paramDB.Cursor(updateTxn);
// Move the cursor to the first record.
Assert.IsTrue(cursor.MoveFirst());
int i = 0;
try
{
do
{
int32Value = BitConverter.ToInt32(
cursor.Current.Value.Data, 0);
data = new DatabaseEntry(
BitConverter.GetBytes(int32Value - 1));
cursor.Overwrite(data);
} while (i <= 1000 && cursor.MoveNext());
}
catch (DeadlockException)
{
}
finally
{
cursor.Close();
}
}