Skip to content

Commit b76b22a

Browse files
committed
ISessionImplementor.AutoFlushIfRequired
1 parent 6e70f60 commit b76b22a

File tree

6 files changed

+59
-25
lines changed

6 files changed

+59
-25
lines changed

src/NHibernate/Async/Engine/ISessionImplementor.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ namespace NHibernate.Engine
2828
{
2929
using System.Threading.Tasks;
3030
using System.Threading;
31+
internal static partial class SessionImplementorExtensions
32+
{
33+
34+
internal static async Task AutoFlushIfRequiredAsync(this ISessionImplementor implementor, ISet<string> querySpaces, CancellationToken cancellationToken)
35+
{
36+
cancellationToken.ThrowIfCancellationRequested();
37+
var autoFlushIfRequiredTask = (implementor as AbstractSessionImpl)?.AutoFlushIfRequiredAsync(querySpaces, cancellationToken);
38+
if (autoFlushIfRequiredTask != null)
39+
{
40+
await (autoFlushIfRequiredTask).ConfigureAwait(false);
41+
}
42+
}
43+
}
3144

3245
public partial interface ISessionImplementor
3346
{

src/NHibernate/Async/Impl/AbstractSessionImpl.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,30 @@ public virtual async Task<IList<T>> ListCustomQueryAsync<T>(ICustomQuery customQ
166166
public abstract Task<object> GetEntityUsingInterceptorAsync(EntityKey key, CancellationToken cancellationToken);
167167
public abstract Task<int> ExecuteNativeUpdateAsync(NativeSQLQuerySpecification specification, QueryParameters queryParameters, CancellationToken cancellationToken);
168168

169+
//6.0 TODO: Make abstract
170+
/// <summary>
171+
/// detect in-memory changes, determine if the changes are to tables
172+
/// named in the query and, if so, complete execution the flush
173+
/// </summary>
174+
/// <param name="querySpaces"></param>
175+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
176+
/// <returns>Returns true if flush was executed</returns>
177+
public virtual Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpaces, CancellationToken cancellationToken)
178+
{
179+
if (cancellationToken.IsCancellationRequested)
180+
{
181+
return Task.FromCanceled<bool>(cancellationToken);
182+
}
183+
try
184+
{
185+
return Task.FromResult<bool>(AutoFlushIfRequired(querySpaces));
186+
}
187+
catch (Exception ex)
188+
{
189+
return Task.FromException<bool>(ex);
190+
}
191+
}
192+
169193
public abstract Task FlushAsync(CancellationToken cancellationToken);
170194

171195
#endregion

src/NHibernate/Async/Impl/SessionImpl.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ namespace NHibernate.Impl
3737
{
3838
using System.Threading.Tasks;
3939
using System.Threading;
40-
internal static partial class SessionImplExtensions
41-
{
42-
internal static async Task AutoFlushIfRequiredAsync(this ISessionImplementor implementor, ISet<string> querySpaces, CancellationToken cancellationToken)
43-
{
44-
cancellationToken.ThrowIfCancellationRequested();
45-
var autoFlushIfRequiredTask = (implementor as SessionImpl)?.AutoFlushIfRequiredAsync(querySpaces, cancellationToken);
46-
if (autoFlushIfRequiredTask != null)
47-
{
48-
await (autoFlushIfRequiredTask).ConfigureAwait(false);
49-
}
50-
}
51-
}
5240
public sealed partial class SessionImpl : AbstractSessionImpl, IEventSource, ISerializable, IDeserializationCallback
5341
{
5442

@@ -691,8 +679,8 @@ public override async Task<object> GetEntityUsingInterceptorAsync(EntityKey key,
691679
/// </summary>
692680
/// <param name="querySpaces"></param>
693681
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
694-
/// <returns></returns>
695-
internal async Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpaces, CancellationToken cancellationToken)
682+
/// <returns>Returns true if flush was executed</returns>
683+
public override async Task<bool> AutoFlushIfRequiredAsync(ISet<string> querySpaces, CancellationToken cancellationToken)
696684
{
697685
cancellationToken.ThrowIfCancellationRequested();
698686
using (BeginProcess())

src/NHibernate/Engine/ISessionImplementor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace NHibernate.Engine
1818
{
1919
// 6.0 TODO: Convert to interface methods
20-
internal static class SessionImplementorExtensions
20+
internal static partial class SessionImplementorExtensions
2121
{
2222
internal static IDisposable BeginContext(this ISessionImplementor session)
2323
{
@@ -40,6 +40,11 @@ internal static IMultiAnyQueryBatch GetFutureMultiBatch(this ISessionImplementor
4040
{
4141
return (session as AbstractSessionImpl)?.FutureMultiBatch;
4242
}
43+
44+
internal static void AutoFlushIfRequired(this ISessionImplementor implementor, ISet<string> querySpaces)
45+
{
46+
(implementor as AbstractSessionImpl)?.AutoFlushIfRequired(querySpaces);
47+
}
4348
}
4449

4550
/// <summary>

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ public virtual FlushMode FlushMode
301301
set => _flushMode = value;
302302
}
303303

304+
//6.0 TODO: Make abstract
305+
/// <summary>
306+
/// detect in-memory changes, determine if the changes are to tables
307+
/// named in the query and, if so, complete execution the flush
308+
/// </summary>
309+
/// <param name="querySpaces"></param>
310+
/// <returns>Returns true if flush was executed</returns>
311+
public virtual bool AutoFlushIfRequired(ISet<string> querySpaces)
312+
{
313+
return false;
314+
}
315+
304316
public virtual IQuery GetNamedQuery(string queryName)
305317
{
306318
using (BeginProcess())

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525

2626
namespace NHibernate.Impl
2727
{
28-
internal static partial class SessionImplExtensions
29-
{
30-
internal static void AutoFlushIfRequired(this ISessionImplementor implementor, ISet<string> querySpaces)
31-
{
32-
(implementor as SessionImpl)?.AutoFlushIfRequired(querySpaces);
33-
}
34-
}
35-
3628
/// <summary>
3729
/// Concrete implementation of an <see cref="ISession" />, also the central, organizing component
3830
/// of NHibernate's internal implementation.
@@ -1044,8 +1036,8 @@ public override IPersistenceContext PersistenceContext
10441036
/// named in the query and, if so, complete execution the flush
10451037
/// </summary>
10461038
/// <param name="querySpaces"></param>
1047-
/// <returns></returns>
1048-
internal bool AutoFlushIfRequired(ISet<string> querySpaces)
1039+
/// <returns>Returns true if flush was executed</returns>
1040+
public override bool AutoFlushIfRequired(ISet<string> querySpaces)
10491041
{
10501042
using (BeginProcess())
10511043
{

0 commit comments

Comments
 (0)