Skip to content

Commit 8b86bb6

Browse files
NH-4034 - better naming for dependent session to handle from transaction commit.
1 parent eeb9a60 commit 8b86bb6

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

src/NHibernate.Test/DebugSessionFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Data.Common;
5+
using System.Linq;
56
using System.Threading;
67
using log4net;
78
using NHibernate.Cache;
@@ -57,9 +58,9 @@ public bool CheckSessionsWereClosed()
5758
allClosed = CheckSessionWasClosed(session) && allClosed;
5859
// Catches only session opened from another one while sharing the connection. Those
5960
// opened without sharing the connection stay un-monitored.
60-
foreach (var sharingSession in session.ConnectionManager.SessionsSharingManager)
61+
foreach (var dependentSession in session.ConnectionManager.DependentSessions.ToList())
6162
{
62-
allClosed = CheckSessionWasClosed(sharingSession) && allClosed;
63+
allClosed = CheckSessionWasClosed(dependentSession) && allClosed;
6364
}
6465
}
6566

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ public interface Callback
4242
private readonly ISessionImplementor session;
4343
private readonly ConnectionReleaseMode connectionReleaseMode;
4444
private readonly IInterceptor interceptor;
45-
private readonly List<ISessionImplementor> _sessionsSharingManager = new List<ISessionImplementor>();
45+
private readonly List<ISessionImplementor> _dependentSessions = new List<ISessionImplementor>();
4646

47+
/// <summary>
48+
/// The session responsible for the lifecycle of the connection manager.
49+
/// </summary>
4750
public ISessionImplementor Session => session;
48-
public IReadOnlyCollection<ISessionImplementor> SessionsSharingManager => _sessionsSharingManager;
51+
52+
/// <summary>
53+
/// The sessions using the connection manager of the session responsible for it.
54+
/// </summary>
55+
public IReadOnlyCollection<ISessionImplementor> DependentSessions => _dependentSessions;
4956

5057
[NonSerialized]
5158
private bool _releasesEnabled = true;
@@ -70,12 +77,12 @@ public ConnectionManager(
7077

7178
public void AddSessionSharingManager(ISessionImplementor session)
7279
{
73-
_sessionsSharingManager.Add(session);
80+
_dependentSessions.Add(session);
7481
}
7582

7683
public void RemoveSessionSharingManager(ISessionImplementor session)
7784
{
78-
_sessionsSharingManager.Remove(session);
85+
_dependentSessions.Remove(session);
7986
}
8087

8188
public bool IsInActiveTransaction

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public DbConnection Close()
318318
public override void AfterTransactionCompletion(bool success, ITransaction tx)
319319
{
320320
if (!_transactionCoordinatorShared)
321-
foreach (var sharingSession in ConnectionManager.SessionsSharingManager)
321+
foreach (var dependentSession in ConnectionManager.DependentSessions)
322322
{
323-
sharingSession.AfterTransactionCompletion(success, tx);
323+
dependentSession.AfterTransactionCompletion(success, tx);
324324
}
325325

326326
using (new SessionIdLoggingContext(SessionId))
@@ -2112,18 +2112,18 @@ public override void AfterTransactionBegin(ITransaction tx)
21122112
}
21132113

21142114
if (!_transactionCoordinatorShared)
2115-
foreach (var sharingSession in ConnectionManager.SessionsSharingManager)
2115+
foreach (var dependentSession in ConnectionManager.DependentSessions)
21162116
{
2117-
sharingSession.AfterTransactionBegin(tx);
2117+
dependentSession.AfterTransactionBegin(tx);
21182118
}
21192119
}
21202120

21212121
public override void BeforeTransactionCompletion(ITransaction tx)
21222122
{
21232123
if (!_transactionCoordinatorShared)
2124-
foreach (var sharingSession in ConnectionManager.SessionsSharingManager)
2124+
foreach (var dependentSession in ConnectionManager.DependentSessions)
21252125
{
2126-
sharingSession.BeforeTransactionCompletion(tx);
2126+
dependentSession.BeforeTransactionCompletion(tx);
21272127
}
21282128

21292129
using (new SessionIdLoggingContext(SessionId))

src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
8282

8383
private static void Cleanup(ISessionImplementor session)
8484
{
85-
foreach (var sharingSession in session.ConnectionManager.SessionsSharingManager.ToList())
85+
foreach (var dependentSession in session.ConnectionManager.DependentSessions.ToList())
8686
{
87-
if (sharingSession.TransactionContext?.ShouldCloseSessionOnDistributedTransactionCompleted ?? false)
87+
if (dependentSession.TransactionContext?.ShouldCloseSessionOnDistributedTransactionCompleted ?? false)
8888
// This change the enumerated collection.
89-
sharingSession.CloseSessionFromDistributedTransaction();
90-
sharingSession.TransactionContext?.Dispose();
91-
sharingSession.TransactionContext = null;
89+
dependentSession.CloseSessionFromDistributedTransaction();
90+
dependentSession.TransactionContext?.Dispose();
91+
dependentSession.TransactionContext = null;
9292
}
9393
if (session.TransactionContext.ShouldCloseSessionOnDistributedTransactionCompleted)
9494
{
@@ -145,12 +145,12 @@ void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
145145
{
146146
using (sessionImplementor.ConnectionManager.FlushingFromDtcTransaction)
147147
{
148-
foreach (var sharingSession in sessionImplementor.ConnectionManager.SessionsSharingManager)
148+
foreach (var dependentSession in sessionImplementor.ConnectionManager.DependentSessions)
149149
{
150-
if (sharingSession.FlushMode != FlushMode.Manual)
150+
if (dependentSession.FlushMode != FlushMode.Manual)
151151
{
152-
logger.DebugFormat("[session-id={0}] Flushing from Dtc Transaction", sharingSession.SessionId);
153-
sharingSession.Flush();
152+
logger.DebugFormat("[session-id={0}] Flushing from Dtc Transaction", dependentSession.SessionId);
153+
dependentSession.Flush();
154154
}
155155
}
156156
if (sessionImplementor.FlushMode != FlushMode.Manual)

src/NHibernate/Transaction/AdoTransaction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ public void Commit()
186186

187187
log.Debug("Start Commit");
188188

189-
foreach (var sharingSession in session.ConnectionManager.SessionsSharingManager)
189+
foreach (var dependentSession in session.ConnectionManager.DependentSessions)
190190
{
191-
if (sharingSession.FlushMode != FlushMode.Manual)
191+
if (dependentSession.FlushMode != FlushMode.Manual)
192192
{
193-
sharingSession.Flush();
193+
dependentSession.Flush();
194194
}
195195
}
196196
if (session.FlushMode != FlushMode.Manual)

0 commit comments

Comments
 (0)