Skip to content

Commit 1011410

Browse files
NH-2176 naming fix, clean up.
1 parent 419d434 commit 1011410

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void EnlistInSystemTransactionIfNeeded(ISessionImplementor session)
3333
// Ensure the session does not run on a thread supposed to be blocked, waiting
3434
// for transaction completion.
3535
session.TransactionContext?.WaitOne();
36-
36+
3737
var transaction = System.Transactions.Transaction.Current;
3838
// We may have defined the transaction context before having the connection, do not
3939
// move under test on TransactionContext already defined. Otherwise we would rely on
@@ -49,11 +49,11 @@ public void EnlistInSystemTransactionIfNeeded(ISessionImplementor session)
4949
session.TransactionContext = transactionContext;
5050
_logger.DebugFormat(
5151
"enlisted into DTC transaction: {0}",
52-
transactionContext.AmbientTransation.IsolationLevel);
52+
transactionContext.AmbientTransaction.IsolationLevel);
5353
session.AfterTransactionBegin(null);
5454

55-
transactionContext.AmbientTransation.TransactionCompleted += transactionContext.TransactionCompleted;
56-
transactionContext.AmbientTransation.EnlistVolatile(
55+
transactionContext.AmbientTransaction.TransactionCompleted += transactionContext.TransactionCompleted;
56+
transactionContext.AmbientTransaction.EnlistVolatile(
5757
transactionContext,
5858
EnlistmentOptions.EnlistDuringPrepareRequired);
5959
}
@@ -74,30 +74,30 @@ public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork wo
7474

7575
public class SystemTransactionContext : ITransactionContext, IEnlistmentNotification
7676
{
77-
internal System.Transactions.Transaction AmbientTransation { get; private set; }
77+
internal System.Transactions.Transaction AmbientTransaction { get; private set; }
7878
public bool ShouldCloseSessionOnSystemTransactionCompleted { get; set; }
7979
public bool IsInActiveTransaction { get; internal set; }
8080

8181
private readonly ISessionImplementor _sessionImplementor;
8282
private readonly ManualResetEvent _waitEvent = new ManualResetEvent(true);
8383
private volatile bool _locked;
8484
private readonly AsyncLocal<bool> _bypassWait = new AsyncLocal<bool>();
85-
private bool IsDistributed => AmbientTransation.TransactionInformation.DistributedIdentifier != Guid.Empty;
85+
private bool IsDistributed => AmbientTransaction.TransactionInformation.DistributedIdentifier != Guid.Empty;
8686

8787
public SystemTransactionContext(
8888
ISessionImplementor sessionImplementor,
8989
System.Transactions.Transaction transaction)
9090
{
9191
_sessionImplementor = sessionImplementor;
92-
AmbientTransation = transaction.Clone();
92+
AmbientTransaction = transaction.Clone();
9393
IsInActiveTransaction = true;
9494
}
9595

9696
public void WaitOne()
9797
{
9898
if (_bypassWait.Value || _isDisposed)
9999
return;
100-
if (!_locked && AmbientTransation.TransactionInformation.Status != TransactionStatus.Active)
100+
if (!_locked && AmbientTransaction.TransactionInformation.Status != TransactionStatus.Active)
101101
// Rollback case may end the transaction without a prepare phase, apply the lock.
102102
SafeLockSession();
103103
try
@@ -157,7 +157,7 @@ void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
157157
{
158158
try
159159
{
160-
using (var tx = new TransactionScope(AmbientTransation))
160+
using (var tx = new TransactionScope(AmbientTransaction))
161161
{
162162
if (_sessionImplementor.FlushMode != FlushMode.Manual && _sessionImplementor.ConnectionManager.IsConnected)
163163
{
@@ -197,9 +197,6 @@ void IEnlistmentNotification.InDoubt(Enlistment enlistment)
197197

198198
private void ProcessSecondPhase(Enlistment enlistment, bool? success)
199199
{
200-
// In case of rollback, the prepare phase may have not be run, and we then need to lock as soon as possible.
201-
// There is no guarantee the second phase will be run before the completed event, doing that at both places.
202-
SafeLockSession();
203200
using (new SessionIdLoggingContext(_sessionImplementor.SessionId))
204201
{
205202
_logger.Debug(
@@ -225,9 +222,6 @@ private void ProcessSecondPhase(Enlistment enlistment, bool? success)
225222

226223
public void TransactionCompleted(object sender, TransactionEventArgs e)
227224
{
228-
// In case of rollback, the prepare phase may have not be run, and we then need to lock as soon as possible.
229-
// There is no guarantee the second phase will be run before the completed event, doing that at both places.
230-
SafeLockSession();
231225
e.Transaction.TransactionCompleted -= TransactionCompleted;
232226
// This event may execute before second phase, so we cannot try to get the success from second phase.
233227
// Using this event is required by example in case the prepare phase failed and called force rollback:
@@ -237,7 +231,7 @@ public void TransactionCompleted(object sender, TransactionEventArgs e)
237231
try
238232
{
239233
wasSuccessful =
240-
e.Transaction.TransactionInformation.Status == TransactionStatus.Committed;
234+
AmbientTransaction.TransactionInformation.Status == TransactionStatus.Committed;
241235
}
242236
catch (ObjectDisposedException ode)
243237
{
@@ -253,6 +247,7 @@ private void RunAfterTransactionActions(bool wasSuccessful)
253247
if (_afterTransactionActionsDone)
254248
// Probably called from In-Doubt and TransactionCompleted.
255249
return;
250+
_afterTransactionActionsDone = true;
256251
// Allow transaction completed actions to run while others stay blocked.
257252
_bypassWait.Value = true;
258253
try
@@ -272,7 +267,6 @@ private void RunAfterTransactionActions(bool wasSuccessful)
272267
}
273268
finally
274269
{
275-
_afterTransactionActionsDone = true;
276270
// Dispose releases blocked threads by the way.
277271
// Must dispose in case !ShouldCloseSessionOnSystemTransactionCompleted, since
278272
// we nullify session TransactionContext, causing it to have nothing still holding it.
@@ -296,11 +290,8 @@ protected virtual void Dispose(bool disposing)
296290
{
297291
if (disposing)
298292
{
299-
if (AmbientTransation != null)
300-
{
301-
AmbientTransation.Dispose();
302-
AmbientTransation = null;
303-
}
293+
AmbientTransaction?.Dispose();
294+
AmbientTransaction = null;
304295
_waitEvent.Set();
305296
_waitEvent.Dispose();
306297
}

0 commit comments

Comments
 (0)