Skip to content

Commit

Permalink
Initial commit - Removing alias
Browse files Browse the repository at this point in the history
  • Loading branch information
jrahnama committed Jun 10, 2024
1 parent f7ab115 commit ba5cb6d
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Data.ProviderBase
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Data.Common;
using SysTx = System.Transactions;
using System.Transactions;

abstract internal class DbConnectionClosed : DbConnectionInternal
{
Expand All @@ -26,12 +26,12 @@ override public string ServerVersion
}
}

override protected void Activate(SysTx.Transaction transaction)
override protected void Activate(Transaction transaction)
{
throw ADP.ClosedConnectionError();
}

override public DbTransaction BeginTransaction(IsolationLevel il)
override public DbTransaction BeginTransaction(System.Data.IsolationLevel il)
{
throw ADP.ClosedConnectionError();
}
Expand All @@ -51,7 +51,7 @@ override protected void Deactivate()
throw ADP.ClosedConnectionError();
}

override public void EnlistTransaction(SysTx.Transaction transaction)
override public void EnlistTransaction(Transaction transaction)
{
throw ADP.ClosedConnectionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace Microsoft.Data.ProviderBase
using System.Threading.Tasks;
using Microsoft.Data.Common;
using Microsoft.Data.SqlClient;
using SysTx = System.Transactions;
using System.Transactions;

internal abstract class DbConnectionInternal
{
private static int _objectTypeCount;
internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount);
private SysTx.TransactionCompletedEventHandler _transactionCompletedEventHandler = null;
private TransactionCompletedEventHandler _transactionCompletedEventHandler = null;

internal static readonly StateChangeEventArgs StateChangeClosed = new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed);
internal static readonly StateChangeEventArgs StateChangeOpen = new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open);
Expand All @@ -43,13 +43,13 @@ internal abstract class DbConnectionInternal

private DateTime _createTime; // when the connection was created.

private SysTx.Transaction _enlistedTransaction; // [usage must be thread-safe] the transaction that we're enlisted in, either manually or automatically
private Transaction _enlistedTransaction; // [usage must be thread-safe] the transaction that we're enlisted in, either manually or automatically

// _enlistedTransaction is a clone, so that transaction information can be queried even if the original transaction object is disposed.
// However, there are times when we need to know if the original transaction object was disposed, so we keep a reference to it here.
// This field should only be assigned a value at the same time _enlistedTransaction is updated.
// Also, this reference should not be disposed, since we aren't taking ownership of it.
private SysTx.Transaction _enlistedTransactionOriginal;
private Transaction _enlistedTransactionOriginal;

#if DEBUG
private int _activateCount; // debug only counter to verify activate/deactivates are in sync.
Expand Down Expand Up @@ -83,15 +83,15 @@ internal bool CanBePooled
}
}

protected internal SysTx.Transaction EnlistedTransaction
protected internal Transaction EnlistedTransaction
{
get
{
return _enlistedTransaction;
}
set
{
SysTx.Transaction currentEnlistedTransaction = _enlistedTransaction;
Transaction currentEnlistedTransaction = _enlistedTransaction;
if (((null == currentEnlistedTransaction) && (null != value))
|| ((null != currentEnlistedTransaction) && !currentEnlistedTransaction.Equals(value)))
{ // WebData 20000024
Expand All @@ -104,8 +104,8 @@ protected internal SysTx.Transaction EnlistedTransaction
// SQLBUDT #230558 we need to use a clone of the transaction
// when we store it, or we'll end up keeping it past the
// duration of the using block of the TransactionScope
SysTx.Transaction valueClone = null;
SysTx.Transaction previousTransactionClone = null;
Transaction valueClone = null;
Transaction previousTransactionClone = null;
try
{
if (null != value)
Expand Down Expand Up @@ -188,7 +188,7 @@ protected bool EnlistedTransactionDisposed
{
bool disposed;

SysTx.Transaction currentEnlistedTransactionOriginal = _enlistedTransactionOriginal;
Transaction currentEnlistedTransactionOriginal = _enlistedTransactionOriginal;
if (currentEnlistedTransactionOriginal != null)
{
disposed = currentEnlistedTransactionOriginal.TransactionInformation == null;
Expand Down Expand Up @@ -385,9 +385,9 @@ public ConnectionState State

internal virtual bool IsAccessTokenExpired => false;

abstract protected void Activate(SysTx.Transaction transaction);
abstract protected void Activate(Transaction transaction);

internal void ActivateConnection(SysTx.Transaction transaction)
internal void ActivateConnection(Transaction transaction)
{
// Internal method called from the connection pooler so we don't expose
// the Activate method publicly.
Expand Down Expand Up @@ -415,7 +415,7 @@ internal void AddWeakReference(object value, int tag)
_referenceCollection.Add(value, tag);
}

abstract public DbTransaction BeginTransaction(IsolationLevel il);
abstract public DbTransaction BeginTransaction(System.Data.IsolationLevel il);

virtual public void ChangeDatabase(string value)
{
Expand Down Expand Up @@ -654,7 +654,7 @@ public virtual void Dispose()
// Dispose of the _enlistedTransaction since it is a clone
// of the original reference.
// VSDD 780271 - _enlistedTransaction can be changed by another thread (TX end event)
SysTx.Transaction enlistedTransaction = Interlocked.Exchange(ref _enlistedTransaction, null);
Transaction enlistedTransaction = Interlocked.Exchange(ref _enlistedTransaction, null);
if (enlistedTransaction != null)
{
enlistedTransaction.Dispose();
Expand All @@ -681,7 +681,7 @@ protected internal void UnDoomThisConnection()
_connectionIsDoomed = false;
}

abstract public void EnlistTransaction(SysTx.Transaction transaction);
abstract public void EnlistTransaction(Transaction transaction);

virtual protected internal DataTable GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, string collectionName, string[] restrictions)
{
Expand Down Expand Up @@ -865,21 +865,21 @@ internal void RemoveWeakReference(object value)
// Cleanup connection's transaction-specific structures (currently used by Delegated transaction).
// This is a separate method because cleanup can be triggered in multiple ways for a delegated
// transaction.
virtual protected void CleanupTransactionOnCompletion(SysTx.Transaction transaction)
virtual protected void CleanupTransactionOnCompletion(Transaction transaction)
{
}

internal void DetachCurrentTransactionIfEnded()
{
SysTx.Transaction enlistedTransaction = EnlistedTransaction;
Transaction enlistedTransaction = EnlistedTransaction;
if (enlistedTransaction != null)
{
bool transactionIsDead;
try
{
transactionIsDead = (SysTx.TransactionStatus.Active != enlistedTransaction.TransactionInformation.Status);
transactionIsDead = (TransactionStatus.Active != enlistedTransaction.TransactionInformation.Status);
}
catch (SysTx.TransactionException)
catch (TransactionException)
{
// If the transaction is being processed (i.e. is part way through a rollback\commit\etc then TransactionInformation.Status will throw an exception)
transactionIsDead = true;
Expand All @@ -892,7 +892,7 @@ internal void DetachCurrentTransactionIfEnded()
}

// Detach transaction from connection.
internal void DetachTransaction(SysTx.Transaction transaction, bool isExplicitlyReleasing)
internal void DetachTransaction(Transaction transaction, bool isExplicitlyReleasing)
{
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.DetachTransaction|RES|CPOOL> {0}, Transaction Completed. (pooledCount={1})", ObjectID, _pooledCount);

Expand All @@ -906,7 +906,7 @@ internal void DetachTransaction(SysTx.Transaction transaction, bool isExplicitly
DbConnection owner = Owner;
if (isExplicitlyReleasing || UnbindOnTransactionCompletion || owner is null)
{
SysTx.Transaction currentEnlistedTransaction = _enlistedTransaction;
Transaction currentEnlistedTransaction = _enlistedTransaction;
if (currentEnlistedTransaction != null && transaction.Equals(currentEnlistedTransaction))
{
// We need to remove the transaction completed event handler to cease listening for the transaction to end.
Expand All @@ -924,7 +924,7 @@ internal void DetachTransaction(SysTx.Transaction transaction, bool isExplicitly
}

// Handle transaction detach, pool cleanup and other post-transaction cleanup tasks associated with
internal void CleanupConnectionOnTransactionCompletion(SysTx.Transaction transaction)
internal void CleanupConnectionOnTransactionCompletion(Transaction transaction)
{
DetachTransaction(transaction, false);

Expand All @@ -935,9 +935,9 @@ internal void CleanupConnectionOnTransactionCompletion(SysTx.Transaction transac
}
}

void TransactionCompletedEvent(object sender, SysTx.TransactionEventArgs e)
void TransactionCompletedEvent(object sender, TransactionEventArgs e)
{
SysTx.Transaction transaction = e.Transaction;
Transaction transaction = e.Transaction;
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.TransactionCompletedEvent|RES|CPOOL> {0}, Transaction Completed. (pooledCount = {1})", ObjectID, _pooledCount);

CleanupTransactionOnCompletion(transaction);
Expand All @@ -947,9 +947,9 @@ void TransactionCompletedEvent(object sender, SysTx.TransactionEventArgs e)

// TODO: Review whether we need the unmanaged code permission when we have the new object model available.
[SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
private void TransactionOutcomeEnlist(SysTx.Transaction transaction)
private void TransactionOutcomeEnlist(Transaction transaction)
{
_transactionCompletedEventHandler ??= new SysTx.TransactionCompletedEventHandler(TransactionCompletedEvent);
_transactionCompletedEventHandler ??= new TransactionCompletedEventHandler(TransactionCompletedEvent);
transaction.TransactionCompleted += _transactionCompletedEventHandler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace Microsoft.Data.ProviderBase
using System.Threading.Tasks;
using Microsoft.Data.Common;
using Microsoft.Data.SqlClient;

using SysTx = System.Transactions;
using System.Transactions;

sealed internal class DbConnectionPool
{
Expand All @@ -36,8 +35,8 @@ private enum State
// copy as part of the value.
sealed private class TransactedConnectionList : List<DbConnectionInternal>
{
private SysTx.Transaction _transaction;
internal TransactedConnectionList(int initialAllocation, SysTx.Transaction tx) : base(initialAllocation)
private Transaction _transaction;
internal TransactedConnectionList(int initialAllocation, Transaction tx) : base(initialAllocation)
{
_transaction = tx;
}
Expand Down Expand Up @@ -69,7 +68,7 @@ public PendingGetConnection(long dueTime, DbConnection owner, TaskCompletionSour
sealed private class TransactedConnectionPool
{

Dictionary<SysTx.Transaction, TransactedConnectionList> _transactedCxns;
Dictionary<Transaction, TransactedConnectionList> _transactedCxns;

DbConnectionPool _pool;

Expand All @@ -80,7 +79,7 @@ internal TransactedConnectionPool(DbConnectionPool pool)
{
Debug.Assert(null != pool, "null pool?");
_pool = pool;
_transactedCxns = new Dictionary<SysTx.Transaction, TransactedConnectionList>();
_transactedCxns = new Dictionary<Transaction, TransactedConnectionList>();
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.TransactedConnectionPool.TransactedConnectionPool|RES|CPOOL> {0}, Constructed for connection pool {1}", ObjectID, _pool.ObjectID);
}

Expand All @@ -100,7 +99,7 @@ internal DbConnectionPool Pool
}
}

internal DbConnectionInternal GetTransactedObject(SysTx.Transaction transaction)
internal DbConnectionInternal GetTransactedObject(Transaction transaction)
{
Debug.Assert(null != transaction, "null transaction?");

Expand Down Expand Up @@ -145,7 +144,7 @@ internal DbConnectionInternal GetTransactedObject(SysTx.Transaction transaction)
return transactedObject;
}

internal void PutTransactedObject(SysTx.Transaction transaction, DbConnectionInternal transactedObject)
internal void PutTransactedObject(Transaction transaction, DbConnectionInternal transactedObject)
{
Debug.Assert(null != transaction, "null transaction?");
Debug.Assert(null != transactedObject, "null transactedObject?");
Expand Down Expand Up @@ -179,7 +178,7 @@ internal void PutTransactedObject(SysTx.Transaction transaction, DbConnectionInt
{
// create the transacted pool, making sure to clone the associated transaction
// for use as a key in our internal dictionary of transactions and connections
SysTx.Transaction transactionClone = null;
Transaction transactionClone = null;
TransactedConnectionList newConnections = null;

try
Expand Down Expand Up @@ -243,7 +242,7 @@ internal void PutTransactedObject(SysTx.Transaction transaction, DbConnectionInt

}

internal void TransactionEnded(SysTx.Transaction transaction, DbConnectionInternal transactedObject)
internal void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject)
{
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.TransactedConnectionPool.TransactionEnded|RES|CPOOL> {0}, Transaction {1}, Connection {2}, Transaction Completed", ObjectID, transaction.GetHashCode(), transactedObject.ObjectID);
TransactedConnectionList connections;
Expand Down Expand Up @@ -1014,7 +1013,7 @@ private void DeactivateObject(DbConnectionInternal obj)
// the transaction asynchronously completing on a second
// thread.

SysTx.Transaction transaction = obj.EnlistedTransaction;
Transaction transaction = obj.EnlistedTransaction;
if (null != transaction)
{
// NOTE: we're not locking on _state, so it's possible that its
Expand Down Expand Up @@ -1336,7 +1335,7 @@ internal bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<D
private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection)
{
DbConnectionInternal obj = null;
SysTx.Transaction transaction = null;
Transaction transaction = null;

PerformanceCounters.SoftConnectsPerSecond.Increment();
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.GetConnection|RES|CPOOL> {0}, Getting connection.", ObjectID);
Expand Down Expand Up @@ -1554,7 +1553,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj
return true;
}

private void PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, SysTx.Transaction transaction)
private void PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
{
lock (obj)
{ // Protect against Clear and ReclaimEmancipatedObjects, which call IsEmancipated, which is affected by PrePush and PostPop
Expand Down Expand Up @@ -1631,7 +1630,7 @@ private DbConnectionInternal GetFromGeneralPool()
return (obj);
}

private DbConnectionInternal GetFromTransactedPool(out SysTx.Transaction transaction)
private DbConnectionInternal GetFromTransactedPool(out Transaction transaction)
{
transaction = ADP.GetCurrentTransaction();
DbConnectionInternal obj = null;
Expand Down Expand Up @@ -1973,7 +1972,7 @@ internal void Shutdown()
// that is implemented inside DbConnectionPool. This method's counterpart (PutTransactedObject) should
// only be called from DbConnectionPool.DeactivateObject and thus the plumbing to provide access to
// other objects is unnecessary (hence the asymmetry of Ended but no Begin)
internal void TransactionEnded(SysTx.Transaction transaction, DbConnectionInternal transactedObject)
internal void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject)
{
Debug.Assert(null != transaction, "null transaction?");
Debug.Assert(null != transactedObject, "null transactedObject?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using Microsoft.Data.Common;
using Microsoft.Data.Sql;
using Microsoft.Data.SqlClient.Server;
using SysTx = System.Transactions;
using System.Transactions;
using System.Collections.Concurrent;

// NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available.
Expand Down Expand Up @@ -4046,7 +4046,7 @@ private void RunExecuteNonQuerySmi(bool sendToPipe)
try
{
long transactionId;
SysTx.Transaction transaction;
Transaction transaction;
innerConnection.GetCurrentTransactionPair(out transactionId, out transaction);

SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlCommand.RunExecuteNonQuerySmi|ADV> {0}, innerConnection={1}, transactionId=0x{2}, cmdBehavior={3}.", ObjectID, innerConnection.ObjectID, transactionId, (int)CommandBehavior.Default);
Expand Down Expand Up @@ -5696,7 +5696,7 @@ private SqlDataReader RunExecuteReaderSmi(CommandBehavior cmdBehavior, RunBehavi
requestExecutor = SetUpSmiRequest(innerConnection);

long transactionId;
SysTx.Transaction transaction;
Transaction transaction;
innerConnection.GetCurrentTransactionPair(out transactionId, out transaction);
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlCommand.RunExecuteReaderSmi|ADV> {0}, innerConnection={1}, transactionId=0x{2}, commandBehavior={(int)cmdBehavior}.", ObjectID, innerConnection.ObjectID, transactionId);

Expand Down
Loading

0 comments on commit ba5cb6d

Please sign in to comment.