本文整理汇总了C#中BerkeleyDB.Transaction类的典型用法代码示例。如果您正苦于以下问题:C# Transaction类的具体用法?C# Transaction怎么用?C# Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于BerkeleyDB命名空间,在下文中一共展示了Transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:AndyHitchman,项目名称:Stash,代码行数:7,代码来源:StartsWithQuery.cs
示例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();
}
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:32,代码来源:TransactionTest.cs
示例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();
}
}
开发者ID:AndyHitchman,项目名称:Stash,代码行数:32,代码来源:StartsWithQuery.cs
示例4: Execute
public IEnumerable<InternalId> Execute(Transaction transaction)
{
var cursor = managedIndex.ReverseIndex.Cursor();
while(cursor.MoveNextUnique())
{
yield return cursor.Current.Key.Data.AsInternalId();
}
}
开发者ID:AndyHitchman,项目名称:Stash,代码行数:8,代码来源:IsIndexedQuery.cs
示例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));
}
开发者ID:AndyHitchman,项目名称:Stash,代码行数:11,代码来源:IsIndexedQuery.cs
示例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;
}
开发者ID:gildafnai82,项目名称:craq,代码行数:30,代码来源:Sequence.cs
示例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);
}
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:18,代码来源:TransactionTest.cs
示例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);
}
开发者ID:rohitlodha,项目名称:DenverDB,代码行数:10,代码来源:SecondaryDatabase.cs
示例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);
}
开发者ID:rohitlodha,项目名称:DenverDB,代码行数:33,代码来源:SecondaryDatabase.cs
示例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);
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:25,代码来源:Database.cs
示例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;
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:76,代码来源:Database.cs
示例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);
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:26,代码来源:Database.cs
示例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);
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:30,代码来源:Database.cs
示例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");
}
开发者ID:gildafnai82,项目名称:craq,代码行数:11,代码来源:CursorTest.cs
示例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();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:42,代码来源:CursorTest.cs
示例16: Stats
private HeapStats Stats(Transaction txn, bool fast, Isolation isoDegree)
{
uint flags = 0;
flags |= fast ? DbConstants.DB_FAST_STAT : 0;
switch (isoDegree) {
case Isolation.DEGREE_ONE:
flags |= DbConstants.DB_READ_UNCOMMITTED;
break;
case Isolation.DEGREE_TWO:
flags |= DbConstants.DB_READ_COMMITTED;
break;
}
HeapStatStruct st = db.stat_heap(Transaction.getDB_TXN(txn), flags);
return new HeapStats(st);
}
开发者ID:mcandre,项目名称:db,代码行数:15,代码来源:HeapDatabase.cs
示例17: 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();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:37,代码来源:CursorTest.cs
示例18: Open
/// <summary>
/// Instantiate a new HeapDatabase 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 HeapDatabase Open(
string Filename, HeapDatabaseConfig cfg, Transaction txn)
{
HeapDatabase ret = new HeapDatabase(cfg.Env, 0);
ret.Config(cfg);
ret.db.open(Transaction.getDB_TXN(txn),
Filename, null, DBTYPE.DB_HEAP, cfg.openFlags, 0);
ret.isOpen = true;
return ret;
}
开发者ID:mcandre,项目名称:db,代码行数:45,代码来源:HeapDatabase.cs
示例19: Append
/// <summary>
/// Append the data item to the end of the database.
/// </summary>
/// <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>
/// <returns>The heap record id allocated to the record</returns>
public HeapRecordId Append(DatabaseEntry data, Transaction txn)
{
DatabaseEntry key = new DatabaseEntry();
Put(key, data, txn, DbConstants.DB_APPEND);
return HeapRecordId.fromArray(key.Data);
}
开发者ID:mcandre,项目名称:db,代码行数:19,代码来源:HeapDatabase.cs
示例20: GetBothMultiple
/// <summary>
/// If a key/data pair in the database matches <paramref name="key"/>
/// and <paramref name="data"/>, return the key and all duplicate data
/// items.
/// </summary>
/// <param name="key">The key to search for</param>
/// <param name="data">The data 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>
/// <param name="info">The locking behavior to use.</param>
/// <exception cref="NotFoundException">
/// A NotFoundException is thrown if <paramref name="key"/> and
/// <paramref name="data"/> are not in the database.
/// </exception>
/// <exception cref="KeyEmptyException">
/// A KeyEmptyException is thrown if the database is a
/// <see cref="QueueDatabase"/> or <see cref="RecnoDatabase"/>
/// database and <paramref name="key"/> exists, but was never explicitly
/// created by the application or was later deleted.
/// </exception>
/// <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> GetBothMultiple(
DatabaseEntry key, DatabaseEntry data,
int BufferSize, Transaction txn, LockingInfo info)
{
KeyValuePair<DatabaseEntry, DatabaseEntry> kvp;
int datasz = (int)data.Data.Length;
for (; ; ) {
byte[] udata = new byte[BufferSize];
Array.Copy(data.Data, udata, datasz);
data.UserData = udata;
data.size = (uint)datasz;
try {
kvp = Get(key, data, txn, info,
DbConstants.DB_MULTIPLE | DbConstants.DB_GET_BOTH);
break;
} catch (MemoryException) {
int sz = (int)data.size;
if (sz > BufferSize)
BufferSize = sz;
else
BufferSize *= 2;
}
}
MultipleDatabaseEntry dbe = new MultipleDatabaseEntry(kvp.Value);
return new KeyValuePair<DatabaseEntry, MultipleDatabaseEntry>(
kvp.Key, dbe);
}
开发者ID:simonzhangsm,项目名称:h-store,代码行数:62,代码来源:Database.cs
注:本文中的BerkeleyDB.Transaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论