本文整理汇总了C#中System.Transactions.Transaction.EnlistPromotableSinglePhase方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.EnlistPromotableSinglePhase方法的具体用法?C# Transaction.EnlistPromotableSinglePhase怎么用?C# Transaction.EnlistPromotableSinglePhase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Transactions.Transaction
的用法示例。
在下文中一共展示了Transaction.EnlistPromotableSinglePhase方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SharedConnectionInfo
/// <summary>
/// Instantiate an opened connection enlisted to the Transaction
/// if promotable is false, the Transaction wraps a local
/// transaction inside and can never be promoted
/// </summary>
/// <param name="dbResourceAllocator"></param>
/// <param name="transaction"></param>
/// <param name="wantPromotable"></param>
internal SharedConnectionInfo(
DbResourceAllocator dbResourceAllocator,
Transaction transaction,
bool wantPromotable,
ManualResetEvent handle)
{
Debug.Assert((transaction != null), "Null Transaction!");
if (null == handle)
throw new ArgumentNullException("handle");
this.handle = handle;
if (wantPromotable)
{
// Enlist a newly opened connection to this regular Transaction
this.connection = dbResourceAllocator.OpenNewConnection();
this.connection.EnlistTransaction(transaction);
}
else
{
// Make this transaction no longer promotable by attaching our
// IPromotableSinglePhaseNotification implementation (LocalTranscaction)
// and track the DbConnection and DbTransaction associated with the LocalTranscaction
LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle);
transaction.EnlistPromotableSinglePhase(localTransaction);
this.connection = localTransaction.Connection;
this.localTransaction = localTransaction.Transaction;
}
}
示例2: Enlist
private void Enlist(Transaction transaction)
{
if (transaction == null)
{
// no enlistment as we are not in a TransactionScope
return;
}
// try to enlist as a PSPE
if (!transaction.EnlistPromotableSinglePhase(this))
{
// our enlistmente fail so we need to enlist ourselves as durable.
// we create a transaction directly instead of using BeginTransaction that GraphClient
// doesn't store it in its stack of scopes.
var localTransaction = new Neo4jTransaction(_client);
localTransaction.ForceKeepAlive();
_transactionId = localTransaction.Id;
var resourceManager = GetResourceManager();
var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
{
TransactionId = localTransaction.Id,
TransactionBaseEndpoint = _client.TransactionEndpoint
};
resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
localTransaction.Cancel();
}
_enlistedInTransactions.Add(transaction);
}
示例3: SharedConnectionInfo
internal SharedConnectionInfo(DbResourceAllocator dbResourceAllocator, Transaction transaction, bool wantPromotable, ManualResetEvent handle)
{
if (handle == null)
{
throw new ArgumentNullException("handle");
}
this.handle = handle;
if (wantPromotable)
{
this.connection = dbResourceAllocator.OpenNewConnection();
this.connection.EnlistTransaction(transaction);
}
else
{
LocalTransaction promotableSinglePhaseNotification = new LocalTransaction(dbResourceAllocator, handle);
transaction.EnlistPromotableSinglePhase(promotableSinglePhaseNotification);
this.connection = promotableSinglePhaseNotification.Connection;
this.localTransaction = promotableSinglePhaseNotification.Transaction;
}
}
示例4: Enlist
public void Enlist(Transaction tx)
{
if (tx != null)
{
_isolationLevel = tx.IsolationLevel;
if (!tx.EnlistPromotableSinglePhase(this))
{
// must already have a durable resource
// start transaction
_npgsqlTx = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel));
_inTransaction = true;
_rm = CreateResourceManager();
_callbacks = new NpgsqlTransactionCallbacks(_connection);
_rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx));
// enlisted in distributed transaction
// disconnect and cleanup local transaction
_npgsqlTx.Cancel();
_npgsqlTx.Dispose();
_npgsqlTx = null;
}
}
}
示例5: EnlistAsync
async Task<byte[]> EnlistAsync(Link link, Transaction txn)
{
string id = txn.TransactionInformation.LocalIdentifier;
Enlistment enlistment;
lock (this.SyncRoot)
{
if (!this.enlistments.TryGetValue(id, out enlistment))
{
enlistment = new Enlistment(this, txn);
this.enlistments.Add(id, enlistment);
txn.TransactionCompleted += this.OnTransactionCompleted;
if (!txn.EnlistPromotableSinglePhase(enlistment))
{
this.enlistments.Remove(id);
txn.TransactionCompleted -= this.OnTransactionCompleted;
throw new InvalidOperationException("DTC not supported");
}
}
}
return await enlistment.EnlistAsync(link);
}
示例6: EnlistTransaction
/// <summary>
/// Enlists in the specified transaction.
/// </summary>
/// <param name="transaction">
/// A reference to an existing <see cref="System.Transactions.Transaction"/> in which to enlist.
/// </param>
public override void EnlistTransaction(Transaction transaction)
{
// enlisting in the null transaction is a noop
if (transaction == null)
return;
// guard against trying to enlist in more than one transaction
if (driver.CurrentTransaction != null)
{
if (driver.CurrentTransaction.BaseTransaction == transaction)
return;
throw new MySqlException("Already enlisted");
}
// now see if we need to swap out drivers. We would need to do this since
// we have to make sure all ops for a given transaction are done on the
// same physical connection.
Driver existingDriver = DriverTransactionManager.GetDriverInTransaction(transaction);
if (existingDriver != null)
{
// we can't allow more than one driver to contribute to the same connection
if (existingDriver.IsInActiveUse)
throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
// there is an existing driver and it's not being currently used.
// now we need to see if it is using the same connection string
string text1 = existingDriver.Settings.GetConnectionString(true);
string text2 = Settings.GetConnectionString(true);
if (String.Compare(text1, text2, true) != 0)
throw new NotSupportedException(Resources.MultipleConnectionsInTransactionNotSupported);
// close existing driver
// set this new driver as our existing driver
CloseFully();
driver = existingDriver;
}
if (driver.CurrentTransaction == null)
{
MySqlPromotableTransaction t = new MySqlPromotableTransaction(this, transaction);
if (!transaction.EnlistPromotableSinglePhase(t))
throw new NotSupportedException(Resources.DistributedTxnNotSupported);
driver.CurrentTransaction = t;
DriverTransactionManager.SetDriverInTransaction(driver);
driver.IsInActiveUse = true;
}
}
示例7: EnlistTransaction
public override void EnlistTransaction( Transaction transaction ) {
if( transaction != null ) {
if( this.driver.CurrentTransaction != null ) {
if( this.driver.CurrentTransaction.BaseTransaction != transaction ) {
throw new MySqlException( "Already enlisted" );
}
} else {
Driver driverInTransaction = DriverTransactionManager.GetDriverInTransaction( transaction );
if( driverInTransaction != null ) {
if( driverInTransaction.IsInActiveUse ) {
throw new NotSupportedException( Resources.MultipleConnectionsInTransactionNotSupported );
}
string connectionString = driverInTransaction.Settings.GetConnectionString( true );
string strB = this.Settings.GetConnectionString( true );
if( string.Compare( connectionString, strB, true ) != 0 ) {
throw new NotSupportedException( Resources.MultipleConnectionsInTransactionNotSupported );
}
this.CloseFully();
this.driver = driverInTransaction;
}
if( this.driver.CurrentTransaction == null ) {
MySqlPromotableTransaction promotableSinglePhaseNotification = new MySqlPromotableTransaction( this, transaction );
if( !transaction.EnlistPromotableSinglePhase( promotableSinglePhaseNotification ) ) {
throw new NotSupportedException( Resources.DistributedTxnNotSupported );
}
this.driver.CurrentTransaction = promotableSinglePhaseNotification;
DriverTransactionManager.SetDriverInTransaction( this.driver );
this.driver.IsInActiveUse = true;
}
}
}
}
示例8: EnlistTransaction
public override void EnlistTransaction(Transaction systemTransaction)
{
lock (m_syncRoot)
{
CheckClosed();
if (systemTransaction == null)
{
throw new ArgumentNullException("transaction");
}
HsqlEnlistment enlistment = m_enlistment;
if (enlistment == null)
{
enlistment = new HsqlEnlistment(this, systemTransaction);
if (!systemTransaction.EnlistPromotableSinglePhase(enlistment))
{
if (m_transaction == null)
{
BeginTransaction(HsqlConvert.ToIsolationLevel(systemTransaction.IsolationLevel));
}
enlistment.m_dbTransaction = m_transaction;
systemTransaction.EnlistDurable(enlistment.Rmid, enlistment, EnlistmentOptions.None);
}
m_enlistment = enlistment;
GC.KeepAlive(this);
}
else if (enlistment.Transaction != systemTransaction)
{
throw new InvalidOperationException(
"Connection currently has transaction enlisted."
+ " Finish current transaction and retry."); // NOI18N
}
}
}
示例9: EnlistNonNull
private void EnlistNonNull(Transaction tx)
{
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnection.EnlistNonNull|ADV> %d#, transaction %d#.\n", base.ObjectID, tx.GetHashCode());
}
bool flag = false;
if (this.IsYukonOrNewer)
{
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnection.EnlistNonNull|ADV> %d#, attempting to delegate\n", base.ObjectID);
}
SqlDelegatedTransaction promotableSinglePhaseNotification = new SqlDelegatedTransaction(this, tx);
try
{
if (tx.EnlistPromotableSinglePhase(promotableSinglePhaseNotification))
{
flag = true;
this.DelegatedTransaction = promotableSinglePhaseNotification;
if (Bid.AdvancedOn)
{
long transactionId = 0L;
int objectID = 0;
if (this.CurrentTransaction != null)
{
transactionId = this.CurrentTransaction.TransactionId;
objectID = this.CurrentTransaction.ObjectID;
}
Bid.Trace("<sc.SqlInternalConnection.EnlistNonNull|ADV> %d#, delegated to transaction %d# with transactionId=0x%I64x\n", base.ObjectID, objectID, transactionId);
}
}
}
catch (SqlException exception)
{
if (exception.Class >= 20)
{
throw;
}
SqlInternalConnectionTds tds = this as SqlInternalConnectionTds;
if (tds != null)
{
TdsParser parser = tds.Parser;
if ((parser == null) || (parser.State != TdsParserState.OpenLoggedIn))
{
throw;
}
}
ADP.TraceExceptionWithoutRethrow(exception);
}
}
if (!flag)
{
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnection.EnlistNonNull|ADV> %d#, delegation not possible, enlisting.\n", base.ObjectID);
}
byte[] transactionCookie = null;
if (this._whereAbouts == null)
{
byte[] dTCAddress = this.GetDTCAddress();
if (dTCAddress == null)
{
throw SQL.CannotGetDTCAddress();
}
this._whereAbouts = dTCAddress;
}
transactionCookie = GetTransactionCookie(tx, this._whereAbouts);
this.PropagateTransactionCookie(transactionCookie);
this._isEnlistedInTransaction = true;
if (Bid.AdvancedOn)
{
long num2 = 0L;
int num = 0;
if (this.CurrentTransaction != null)
{
num2 = this.CurrentTransaction.TransactionId;
num = this.CurrentTransaction.ObjectID;
}
Bid.Trace("<sc.SqlInternalConnection.EnlistNonNull|ADV> %d#, enlisted with transaction %d# with transactionId=0x%I64x\n", base.ObjectID, num, num2);
}
}
base.EnlistedTransaction = tx;
}