Skip to content

Commit a51d974

Browse files
authored
Merge pull request #2 from fredericDelaporte/GH-1381
No breaking changes proposal
2 parents 9b27dd8 + aa0b3ea commit a51d974

16 files changed

+255
-143
lines changed

src/NHibernate.Test/Async/BulkManipulation/NativeSQLBulkOperationsWithCache.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using System.Linq;
1616
using NHibernate.Cache;
1717
using NHibernate.Cfg;
18-
using NHibernate.Engine;
1918
using NSubstitute;
2019
using NUnit.Framework;
2120
using Environment = NHibernate.Cfg.Environment;
@@ -30,7 +29,6 @@ public class NativeSQLBulkOperationsWithCacheAsync : TestCase
3029

3130
protected override IList Mappings => new[] { "BulkManipulation.Vehicle.hbm.xml" };
3231

33-
3432
protected override void Configure(Configuration configuration)
3533
{
3634
cfg.SetProperty(Environment.UseQueryCache, "true");
@@ -68,11 +66,7 @@ public async Task SimpleNativeSQLInsert_DoesNotEvictEntireCacheWhenQuerySpacesAr
6866

6967
Assert.AreEqual(0, clearCalls.Count);
7068
}
71-
7269
}
73-
74-
7570
}
76-
7771
}
7872
}

src/NHibernate.Test/Async/DebugSessionFactory.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ Task ISessionFactory.EvictAsync(System.Type persistentClass, CancellationToken c
5555
return ActualFactory.EvictAsync(persistentClass, cancellationToken);
5656
}
5757

58-
Task ISessionFactory.EvictAsync(IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken)
59-
{
60-
return ActualFactory.EvictAsync(persistentClasses, cancellationToken);
61-
}
62-
6358
Task ISessionFactory.EvictAsync(System.Type persistentClass, object id, CancellationToken cancellationToken)
6459
{
6560
return ActualFactory.EvictAsync(persistentClass, id, cancellationToken);
@@ -70,11 +65,6 @@ Task ISessionFactory.EvictEntityAsync(string entityName, CancellationToken cance
7065
return ActualFactory.EvictEntityAsync(entityName, cancellationToken);
7166
}
7267

73-
Task ISessionFactory.EvictEntityAsync(IEnumerable<string> entityNames, CancellationToken cancellationToken)
74-
{
75-
return ActualFactory.EvictEntityAsync(entityNames, cancellationToken);
76-
}
77-
7868
Task ISessionFactory.EvictEntityAsync(string entityName, object id, CancellationToken cancellationToken)
7969
{
8070
return ActualFactory.EvictEntityAsync(entityName, id, cancellationToken);
@@ -85,11 +75,6 @@ Task ISessionFactory.EvictCollectionAsync(string roleName, CancellationToken can
8575
return ActualFactory.EvictCollectionAsync(roleName, cancellationToken);
8676
}
8777

88-
Task ISessionFactory.EvictCollectionAsync(IEnumerable<string> roleNames, CancellationToken cancellationToken)
89-
{
90-
return ActualFactory.EvictCollectionAsync(roleNames, cancellationToken);
91-
}
92-
9378
Task ISessionFactory.EvictCollectionAsync(string roleName, object id, CancellationToken cancellationToken)
9479
{
9580
return ActualFactory.EvictCollectionAsync(roleName, id, cancellationToken);

src/NHibernate.Test/BulkManipulation/BulkOperationCleanupActionFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
5-
using System.Threading;
6-
using System.Threading.Tasks;
74
using NHibernate.Action;
85
using NHibernate.Engine;
96
using NHibernate.Metadata;
@@ -40,6 +37,8 @@ public void SetupTest()
4037
[TestCase("TestClass", false, 1, 0, 1)]
4138
[TestCase("", true, 1, 1, 1)]
4239
[Test]
40+
// 6.0 TODO: remove this ignore.
41+
[Ignore("Must wait for the tested methods to be actually added to ISessionFactoryImplementor")]
4342
public void AfterTransactionCompletionProcess_EvictsFromCache(string querySpaces, bool persisterHasCache, int expectedPropertySpaceLength, int expectedEntityEvictionCount, int expectedCollectionEvictionCount)
4443
{
4544
_persister.HasCache.Returns(persisterHasCache);
@@ -67,7 +66,6 @@ public void AfterTransactionCompletionProcess_EvictsFromCache(string querySpaces
6766
{
6867
_factory.DidNotReceive().EvictCollection(Arg.Any<IEnumerable<string>>());
6968
}
70-
7169
}
7270
}
7371
}

src/NHibernate.Test/BulkManipulation/NativeSQLBulkOperationsWithCache.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Linq;
66
using NHibernate.Cache;
77
using NHibernate.Cfg;
8-
using NHibernate.Engine;
98
using NSubstitute;
109
using NUnit.Framework;
1110
using Environment = NHibernate.Cfg.Environment;
@@ -19,7 +18,6 @@ public class NativeSQLBulkOperationsWithCache : TestCase
1918

2019
protected override IList Mappings => new[] { "BulkManipulation.Vehicle.hbm.xml" };
2120

22-
2321
protected override void Configure(Configuration configuration)
2422
{
2523
cfg.SetProperty(Environment.UseQueryCache, "true");
@@ -57,12 +55,8 @@ public void SimpleNativeSQLInsert_DoesNotEvictEntireCacheWhenQuerySpacesAreAdded
5755

5856
Assert.AreEqual(0, clearCalls.Count);
5957
}
60-
6158
}
62-
63-
6459
}
65-
6660
}
6761

6862
public class SubstituteCacheProvider : ICacheProvider

src/NHibernate.Test/DebugSessionFactory.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,6 @@ void ISessionFactory.Evict(System.Type persistentClass)
221221
ActualFactory.Evict(persistentClass);
222222
}
223223

224-
void ISessionFactory.Evict(IEnumerable<System.Type> persistentClasses)
225-
{
226-
ActualFactory.Evict(persistentClasses);
227-
}
228-
229224
void ISessionFactory.Evict(System.Type persistentClass, object id)
230225
{
231226
ActualFactory.Evict(persistentClass, id);
@@ -236,11 +231,6 @@ void ISessionFactory.EvictEntity(string entityName)
236231
ActualFactory.EvictEntity(entityName);
237232
}
238233

239-
void ISessionFactory.EvictEntity(IEnumerable<string> entityNames)
240-
{
241-
ActualFactory.EvictEntity(entityNames);
242-
}
243-
244234
void ISessionFactory.EvictEntity(string entityName, object id)
245235
{
246236
ActualFactory.EvictEntity(entityName, id);
@@ -251,11 +241,6 @@ void ISessionFactory.EvictCollection(string roleName)
251241
ActualFactory.EvictCollection(roleName);
252242
}
253243

254-
void ISessionFactory.EvictCollection(IEnumerable<string> roleNames)
255-
{
256-
ActualFactory.EvictCollection(roleNames);
257-
}
258-
259244
void ISessionFactory.EvictCollection(string roleName, object id)
260245
{
261246
ActualFactory.EvictCollection(roleName, id);

src/NHibernate/Action/BulkOperationCleanupAction.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,5 @@ private void EvictEntityRegions()
144144
}
145145

146146
#endregion
147-
148-
149147
}
150148
}

src/NHibernate/Async/Action/BulkOperationCleanupAction.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,5 @@ public Task ExecuteAsync(CancellationToken cancellationToken)
6060
}
6161

6262
#endregion
63-
64-
6563
}
6664
}

src/NHibernate/Async/ISessionFactory.cs

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,95 @@
1414
using System.Data.Common;
1515
using NHibernate.Connection;
1616
using NHibernate.Engine;
17+
using NHibernate.Impl;
1718
using NHibernate.Metadata;
1819
using NHibernate.Stat;
1920

2021
namespace NHibernate
2122
{
2223
using System.Threading.Tasks;
2324
using System.Threading;
25+
public static partial class SessionFactoryExtension
26+
{
27+
/// <summary>
28+
/// Evict all entries from the process-level cache. This method occurs outside
29+
/// of any transaction; it performs an immediate "hard" remove, so does not respect
30+
/// any transaction isolation semantics of the usage strategy. Use with care.
31+
/// </summary>
32+
/// <param name="factory">The session factory.</param>
33+
/// <param name="persistentClasses">The classes of the entities to evict.</param>
34+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
35+
public static async Task EvictAsync(this ISessionFactory factory, IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken = default(CancellationToken))
36+
{
37+
cancellationToken.ThrowIfCancellationRequested();
38+
if (factory is SessionFactoryImpl sfi)
39+
{
40+
await (sfi.EvictAsync(persistentClasses, cancellationToken)).ConfigureAwait(false);
41+
}
42+
else
43+
{
44+
if (persistentClasses == null)
45+
throw new ArgumentNullException(nameof(persistentClasses));
46+
foreach (var @class in persistentClasses)
47+
{
48+
await (factory.EvictAsync(@class, cancellationToken)).ConfigureAwait(false);
49+
}
50+
}
51+
}
52+
53+
/// <summary>
54+
/// Evict all entries from the second-level cache. This method occurs outside
55+
/// of any transaction; it performs an immediate "hard" remove, so does not respect
56+
/// any transaction isolation semantics of the usage strategy. Use with care.
57+
/// </summary>
58+
/// <param name="factory">The session factory.</param>
59+
/// <param name="entityNames">The names of the entities to evict.</param>
60+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
61+
public static async Task EvictEntityAsync(this ISessionFactory factory, IEnumerable<string> entityNames, CancellationToken cancellationToken = default(CancellationToken))
62+
{
63+
cancellationToken.ThrowIfCancellationRequested();
64+
if (factory is SessionFactoryImpl sfi)
65+
{
66+
await (sfi.EvictEntityAsync(entityNames, cancellationToken)).ConfigureAwait(false);
67+
}
68+
else
69+
{
70+
if (entityNames == null)
71+
throw new ArgumentNullException(nameof(entityNames));
72+
foreach (var name in entityNames)
73+
{
74+
await (factory.EvictEntityAsync(name, cancellationToken)).ConfigureAwait(false);
75+
}
76+
}
77+
}
78+
79+
/// <summary>
80+
/// Evict all entries from the process-level cache. This method occurs outside
81+
/// of any transaction; it performs an immediate "hard" remove, so does not respect
82+
/// any transaction isolation semantics of the usage strategy. Use with care.
83+
/// </summary>
84+
/// <param name="factory">The session factory.</param>
85+
/// <param name="roleNames">The names of the collections to evict.</param>
86+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
87+
public static async Task EvictCollectionAsync(this ISessionFactory factory, IEnumerable<string> roleNames, CancellationToken cancellationToken = default(CancellationToken))
88+
{
89+
cancellationToken.ThrowIfCancellationRequested();
90+
if (factory is SessionFactoryImpl sfi)
91+
{
92+
await (sfi.EvictCollectionAsync(roleNames, cancellationToken)).ConfigureAwait(false);
93+
}
94+
else
95+
{
96+
if (roleNames == null)
97+
throw new ArgumentNullException(nameof(roleNames));
98+
foreach (var role in roleNames)
99+
{
100+
await (factory.EvictCollectionAsync(role, cancellationToken)).ConfigureAwait(false);
101+
}
102+
}
103+
}
104+
}
105+
24106
public partial interface ISessionFactory : IDisposable
25107
{
26108

@@ -42,15 +124,6 @@ public partial interface ISessionFactory : IDisposable
42124
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
43125
Task EvictAsync(System.Type persistentClass, CancellationToken cancellationToken = default(CancellationToken));
44126

45-
/// <summary>
46-
/// Evict all entries from the process-level cache. This method occurs outside
47-
/// of any transaction; it performs an immediate "hard" remove, so does not respect
48-
/// any transaction isolation semantics of the usage strategy. Use with care.
49-
/// </summary>
50-
/// <param name="persistentClasses"></param>
51-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
52-
Task EvictAsync(IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken = default(CancellationToken));
53-
54127
/// <summary>
55128
/// Evict an entry from the process-level cache. This method occurs outside
56129
/// of any transaction; it performs an immediate "hard" remove, so does not respect
@@ -68,13 +141,6 @@ public partial interface ISessionFactory : IDisposable
68141
/// </summary>
69142
Task EvictEntityAsync(string entityName, CancellationToken cancellationToken = default(CancellationToken));
70143

71-
/// <summary>
72-
/// Evict all entries from the second-level cache. This method occurs outside
73-
/// of any transaction; it performs an immediate "hard" remove, so does not respect
74-
/// any transaction isolation semantics of the usage strategy. Use with care.
75-
/// </summary>
76-
Task EvictEntityAsync(IEnumerable<string> entityNames, CancellationToken cancellationToken = default(CancellationToken));
77-
78144
/// <summary>
79145
/// Evict an entry from the second-level cache. This method occurs outside
80146
/// of any transaction; it performs an immediate "hard" remove, so does not respect
@@ -91,15 +157,6 @@ public partial interface ISessionFactory : IDisposable
91157
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
92158
Task EvictCollectionAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken));
93159

94-
/// <summary>
95-
/// Evict all entries from the process-level cache. This method occurs outside
96-
/// of any transaction; it performs an immediate "hard" remove, so does not respect
97-
/// any transaction isolation semantics of the usage strategy. Use with care.
98-
/// </summary>
99-
/// <param name="roleNames"></param>
100-
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
101-
Task EvictCollectionAsync(IEnumerable<string> roleNames, CancellationToken cancellationToken = default(CancellationToken));
102-
103160
/// <summary>
104161
/// Evict an entry from the process-level cache. This method occurs outside
105162
/// of any transaction; it performs an immediate "hard" remove, so does not respect

src/NHibernate/Async/Impl/SessionFactoryImpl.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public sealed partial class SessionFactoryImpl : ISessionFactoryImplementor, IOb
165165
}
166166
}
167167

168-
public Task EvictAsync(IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken = default(CancellationToken))
168+
public Task EvictAsync(IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken)
169169
{
170170
if (persistentClasses == null)
171171
throw new ArgumentNullException(nameof(persistentClasses));
@@ -208,7 +208,7 @@ public sealed partial class SessionFactoryImpl : ISessionFactoryImplementor, IOb
208208
}
209209
}
210210

211-
public Task EvictEntityAsync(IEnumerable<string> entityNames, CancellationToken cancellationToken = default(CancellationToken))
211+
public Task EvictEntityAsync(IEnumerable<string> entityNames, CancellationToken cancellationToken)
212212
{
213213
if (entityNames == null)
214214
throw new ArgumentNullException(nameof(entityNames));
@@ -224,10 +224,8 @@ async Task InternalEvictEntityAsync()
224224
{
225225
if (log.IsDebugEnabled())
226226
{
227-
foreach (var p in cacheGroup)
228-
{
229-
log.Debug("evicting second-level cache: " + p.EntityName);
230-
}
227+
log.Debug("evicting second-level cache for: {0}",
228+
string.Join(", ", cacheGroup.Select(p => p.EntityName)));
231229
}
232230
await (cacheGroup.Key.ClearAsync(cancellationToken)).ConfigureAwait(false);
233231
}
@@ -311,7 +309,7 @@ async Task InternalEvictEntityAsync()
311309
}
312310
}
313311

314-
public Task EvictCollectionAsync(IEnumerable<string> roleNames, CancellationToken cancellationToken = default(CancellationToken))
312+
public Task EvictCollectionAsync(IEnumerable<string> roleNames, CancellationToken cancellationToken)
315313
{
316314
if (roleNames == null)
317315
throw new ArgumentNullException(nameof(roleNames));
@@ -325,13 +323,10 @@ async Task InternalEvictCollectionAsync()
325323

326324
foreach (var cacheGroup in roleNames.Select(GetCollectionPersister).Where(x => x.HasCache).GroupBy(x => x.Cache))
327325
{
328-
329326
if (log.IsDebugEnabled())
330327
{
331-
foreach (var p in cacheGroup)
332-
{
333-
log.Debug("evicting second-level cache: " + p.Role);
334-
}
328+
log.Debug("evicting second-level cache for: {0}",
329+
string.Join(", ", cacheGroup.Select(p => p.Role)));
335330
}
336331
await (cacheGroup.Key.ClearAsync(cancellationToken)).ConfigureAwait(false);
337332
}

src/NHibernate/Async/Impl/SqlQueryImpl.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace NHibernate.Impl
2121
{
2222
using System.Threading.Tasks;
2323
using System.Threading;
24-
public partial class SqlQueryImpl : AbstractQueryImpl, ISQLQuery
24+
public partial class SqlQueryImpl : AbstractQueryImpl, ISQLQuery, ISynchronizableSQLQuery
2525
{
2626

2727
public override async Task<IList> ListAsync(CancellationToken cancellationToken = default(CancellationToken))
@@ -121,6 +121,5 @@ protected internal override Task<IEnumerable<ITranslator>> GetTranslatorsAsync(I
121121
return Task.FromException<IEnumerable<ITranslator>>(ex);
122122
}
123123
}
124-
125124
}
126125
}

0 commit comments

Comments
 (0)