Skip to content

Commit 406f46a

Browse files
NH-4003 - Refactor session constructor, some missing cleanup.
1 parent ad4c2ef commit 406f46a

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

src/NHibernate.Test/DebugSessionFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ ISession ISessionFactoryImplementor.OpenSession(
140140
bool autoCloseSessionEnabled,
141141
ConnectionReleaseMode connectionReleaseMode)
142142
{
143+
#pragma warning disable CS0618 // Type or member is obsolete
143144
var s = ActualFactory.OpenSession(connection, flushBeforeCompletionEnabled, autoCloseSessionEnabled, connectionReleaseMode);
145+
#pragma warning restore CS0618 // Type or member is obsolete
144146
_openedSessions.Add(s.GetSessionImplementation());
145147
return s;
146148
}

src/NHibernate/Context/ThreadLocalSessionContext.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace NHibernate.Context
88
{
99
//TODO: refactoring on this class. Maybe using MapBasedSessionContext.
1010
/// <summary>
11+
/// <para>
1112
/// A <see cref="ICurrentSessionContext"/> impl which scopes the notion of current
1213
/// session by the current thread of execution. Threads do not give us a
1314
/// nice hook to perform any type of cleanup making
@@ -19,13 +20,15 @@ namespace NHibernate.Context
1920
/// generated here are unusable until after {@link Session#beginTransaction()}
2021
/// has been called. If <tt>Close()</tt> is called on a session managed by
2122
/// this class, it will be automatically unbound.
22-
/// <p/>
23+
/// </para>
24+
/// <para>
2325
/// Additionally, the static <see cref="Bind"/> and <see cref="Unbind"/> methods are
2426
/// provided to allow application code to explicitly control opening and
2527
/// closing of these sessions. This, with some from of interception,
2628
/// is the preferred approach. It also allows easy framework integration
2729
/// and one possible approach for implementing long-sessions.
28-
/// <p/>
30+
/// </para>
31+
/// <para>The cleanup on transaction end is indeed not implemented.</para>
2932
/// </summary>
3033
[Serializable]
3134
public class ThreadLocalSessionContext : ICurrentSessionContext
@@ -148,23 +151,28 @@ private bool NeedsWrapping(ISession current)
148151

149152
protected ISession BuildOrObtainSession()
150153
{
151-
return factory.OpenSession(
152-
null,
153-
IsAutoFlushEnabled(),
154-
IsAutoCloseEnabled(),
155-
GetConnectionReleaseMode());
154+
return factory.WithOptions()
155+
.AutoClose(IsAutoCloseEnabled())
156+
.ConnectionReleaseMode(GetConnectionReleaseMode())
157+
.OpenSession();
156158
}
157159

158160
private ConnectionReleaseMode GetConnectionReleaseMode()
159161
{
160162
return factory.Settings.ConnectionReleaseMode;
161163
}
162164

165+
/// <summary>
166+
/// Not currently implemented.
167+
/// </summary>
168+
/// <returns><see langword="true"/></returns>
163169
protected virtual bool IsAutoCloseEnabled()
164170
{
165171
return true;
166172
}
167173

174+
// Obsolete since v5
175+
[Obsolete("Had never any implementation, has always had no effect.")]
168176
protected virtual bool IsAutoFlushEnabled()
169177
{
170178
return true;

src/NHibernate/Engine/ISessionFactoryImplementor.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Data.Common;
34
using NHibernate.Cache;
@@ -132,21 +133,17 @@ public interface ISessionFactoryImplementor : IMapping, ISessionFactory
132133
/// <summary> Get a named second-level cache region</summary>
133134
ICache GetSecondLevelCacheRegion(string regionName);
134135

136+
// Obsolete since v5
135137
/// <summary>
136138
/// Open a session conforming to the given parameters. Used mainly
137139
/// for current session processing.
138140
/// </summary>
139141
/// <param name="connection">The external ado.net connection to use, if one (i.e., optional).</param>
140-
/// <param name="flushBeforeCompletionEnabled">
141-
/// Should the session be auto-flushed
142-
/// prior to transaction completion?
143-
/// </param>
144-
/// <param name="autoCloseSessionEnabled">
145-
/// Should the session be auto-closed after
146-
/// transaction completion?
147-
/// </param>
142+
/// <param name="flushBeforeCompletionEnabled">No usage.</param>
143+
/// <param name="autoCloseSessionEnabled">Not yet implemented.</param>
148144
/// <param name="connectionReleaseMode">The release mode for managed jdbc connections.</param>
149145
/// <returns>An appropriate session.</returns>
146+
[Obsolete("Please use WithOptions() instead.")]
150147
ISession OpenSession(DbConnection connection, bool flushBeforeCompletionEnabled, bool autoCloseSessionEnabled,
151148
ConnectionReleaseMode connectionReleaseMode);
152149

src/NHibernate/ISessionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public interface ISessionBuilder<T> where T : ISessionBuilder<T>
5959
T ConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode);
6060

6161
/// <summary>
62-
/// Should the session be automatically closed after transaction completion?
62+
/// Should the session be automatically closed after transaction completion? Not yet implemented, will have no effect.
6363
/// </summary>
6464
/// <param name="autoClose">Should the session be automatically closed.</param>
6565
/// <returns><see langword="this" />, for method chaining.</returns>

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ public ISession OpenSession(DbConnection connection, bool flushBeforeCompletionE
505505
{
506506
return WithOptions()
507507
.Connection(connection)
508-
.Interceptor(interceptor)
509508
.AutoClose(autoCloseSessionEnabled)
510509
.ConnectionReleaseMode(connectionReleaseMode)
511510
.OpenSession();

0 commit comments

Comments
 (0)