Skip to content

Commit 5f595e1

Browse files
Removing potential breaking changes
1 parent fd4422e commit 5f595e1

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/NHibernate/Engine/ISessionImplementor.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@
1616

1717
namespace NHibernate.Engine
1818
{
19-
// TODO: Convert to interface methods in 6.0
19+
// 6.0 TODO: Convert to interface methods
2020
internal static class SessionImplementorExtensions
2121
{
2222
internal static IDisposable BeginContext(this ISessionImplementor session)
2323
{
24-
return (session as AbstractSessionImpl)?.BeginContext();
24+
if (session == null)
25+
return null;
26+
return (session as AbstractSessionImpl)?.BeginContext() ?? new SessionIdLoggingContext(session.SessionId);
2527
}
2628

2729
internal static IDisposable BeginProcess(this ISessionImplementor session)
2830
{
29-
return (session as AbstractSessionImpl)?.BeginProcess();
31+
if (session == null)
32+
return null;
33+
return (session as AbstractSessionImpl)?.BeginProcess() ??
34+
// This method has only replaced bare call to setting the id, so this fallback is enough for avoiding a
35+
// breaking change in case in custom session implementation is used.
36+
new SessionIdLoggingContext(session.SessionId);
3037
}
3138
}
3239

@@ -36,6 +43,7 @@ internal static IDisposable BeginProcess(this ISessionImplementor session)
3643
/// </summary>
3744
public partial interface ISessionImplementor
3845
{
46+
// 5.1 TODO: obsolete Initialize, it has no more usages.
3947
/// <summary>
4048
/// Initialize the session after its construction was complete
4149
/// </summary>

src/NHibernate/Event/IEventSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public partial interface IEventSource : ISessionImplementor, ISession
4040
/// <summary> Cascade delete an entity instance</summary>
4141
void Delete(string entityName, object child, bool isCascadeDeleteEnabled, ISet<object> transientEntities);
4242

43+
// 6.0 TODO: yield null if already suspended.
4344
/// <summary>
4445
/// Suspend auto-flushing, yielding a disposable to dispose when auto flush should be restored. Supports
4546
/// being called multiple times.
4647
/// </summary>
47-
/// <returns>A disposable to dispose when auto flush should be restored if it was not already suspended,
48-
/// <see langword="null" /> otherwise.</returns>
48+
/// <returns>A disposable to dispose when auto flush should be restored.</returns>
4949
IDisposable SuspendAutoFlush();
5050
}
5151
}

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public sealed partial class SessionImpl : AbstractSessionImpl, IEventSource, ISe
5454
private readonly ActionQueue actionQueue;
5555

5656
[NonSerialized]
57-
private bool _suspendAutoFlush;
57+
private int _suspendAutoFlushCount;
5858

5959
private readonly ConnectionManager connectionManager;
6060

@@ -893,12 +893,12 @@ public void Delete(string entityName, object child, bool isCascadeDeleteEnabled,
893893
}
894894

895895
/// <inheritdoc/>
896-
public bool AutoFlushSuspended => _suspendAutoFlush;
896+
public bool AutoFlushSuspended => _suspendAutoFlushCount > 0;
897897

898898
/// <inheritdoc/>
899899
public IDisposable SuspendAutoFlush()
900900
{
901-
return _suspendAutoFlush ? null : new SuspendAutoFlushHelper(this);
901+
return new SuspendAutoFlushHelper(this);
902902
}
903903

904904
private sealed class SuspendAutoFlushHelper : IDisposable
@@ -908,14 +908,14 @@ private sealed class SuspendAutoFlushHelper : IDisposable
908908
public SuspendAutoFlushHelper(SessionImpl session)
909909
{
910910
_session = session;
911-
_session._suspendAutoFlush = true;
911+
_session._suspendAutoFlushCount++;
912912
}
913913

914914
public void Dispose()
915915
{
916916
if (_session == null)
917917
throw new ObjectDisposedException("The auto-flush suspension helper has been disposed already");
918-
_session._suspendAutoFlush = false;
918+
_session._suspendAutoFlushCount --;
919919
_session = null;
920920
}
921921
}
@@ -977,7 +977,7 @@ public void PersistOnFlush(object obj)
977977

978978
public override string BestGuessEntityName(object entity)
979979
{
980-
using (BeginProcess())
980+
using (BeginContext())
981981
{
982982
if (entity.IsProxy())
983983
{

src/NHibernate/Impl/StatelessSessionImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public override FlushMode FlushMode
358358

359359
public override string BestGuessEntityName(object entity)
360360
{
361-
using (BeginProcess())
361+
using (BeginContext())
362362
{
363363
if (entity.IsProxy())
364364
{

0 commit comments

Comments
 (0)