Skip to content

Commit 7e33de9

Browse files
committed
Re-generate with cancellation tokens
1 parent 9b6e15b commit 7e33de9

File tree

279 files changed

+4234
-2103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+4234
-2103
lines changed

src/NHibernate/Async/Action/BulkOperationCleanupAction.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace NHibernate.Action
1818
{
1919
using System.Threading.Tasks;
20+
using System.Threading;
2021
/// <content>
2122
/// Contains generated async methods
2223
/// </content>
@@ -25,8 +26,12 @@ public partial class BulkOperationCleanupAction: IExecutable
2526

2627
#region IExecutable Members
2728

28-
public Task ExecuteAsync()
29+
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
2930
{
31+
if (cancellationToken.IsCancellationRequested)
32+
{
33+
return Task.FromCanceled<object>(cancellationToken);
34+
}
3035
try
3136
{
3237
Execute();

src/NHibernate/Async/Action/CollectionAction.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace NHibernate.Action
2222
{
2323
using System.Threading.Tasks;
24+
using System.Threading;
2425
/// <content>
2526
/// Contains generated async methods
2627
/// </content>
@@ -30,7 +31,8 @@ public abstract partial class CollectionAction : IExecutable, IComparable<Collec
3031
#region IExecutable Members
3132

3233
/// <summary>Execute this action</summary>
33-
public abstract Task ExecuteAsync();
34+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
35+
public abstract Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
3436

3537
#endregion
3638

src/NHibernate/Async/Action/CollectionRecreateAction.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
namespace NHibernate.Action
1919
{
2020
using System.Threading.Tasks;
21+
using System.Threading;
2122
/// <content>
2223
/// Contains generated async methods
2324
/// </content>
2425
public sealed partial class CollectionRecreateAction : CollectionAction
2526
{
2627

2728
/// <summary> Execute this action</summary>
29+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
2830
/// <remarks>
2931
/// This method is called when a new non-null collection is persisted
3032
/// or when an existing (non-null) collection is moved to a new owner
3133
/// </remarks>
32-
public override async Task ExecuteAsync()
34+
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
3335
{
36+
cancellationToken.ThrowIfCancellationRequested();
3437
bool statsEnabled = Session.Factory.Statistics.IsStatisticsEnabled;
3538
Stopwatch stopwatch = null;
3639
if (statsEnabled)
@@ -39,44 +42,46 @@ public override async Task ExecuteAsync()
3942
}
4043
IPersistentCollection collection = Collection;
4144

42-
await (PreRecreateAsync()).ConfigureAwait(false);
45+
await (PreRecreateAsync(cancellationToken)).ConfigureAwait(false);
4346

44-
await (Persister.RecreateAsync(collection, Key, Session)).ConfigureAwait(false);
47+
await (Persister.RecreateAsync(collection, Key, Session, cancellationToken)).ConfigureAwait(false);
4548

4649
Session.PersistenceContext.GetCollectionEntry(collection).AfterAction(collection);
4750

4851
Evict();
4952

50-
await (PostRecreateAsync()).ConfigureAwait(false);
53+
await (PostRecreateAsync(cancellationToken)).ConfigureAwait(false);
5154
if (statsEnabled)
5255
{
5356
stopwatch.Stop();
5457
Session.Factory.StatisticsImplementor.RecreateCollection(Persister.Role, stopwatch.Elapsed);
5558
}
5659
}
5760

58-
private async Task PreRecreateAsync()
61+
private async Task PreRecreateAsync(CancellationToken cancellationToken = default(CancellationToken))
5962
{
63+
cancellationToken.ThrowIfCancellationRequested();
6064
IPreCollectionRecreateEventListener[] preListeners = Session.Listeners.PreCollectionRecreateEventListeners;
6165
if (preListeners.Length > 0)
6266
{
6367
PreCollectionRecreateEvent preEvent = new PreCollectionRecreateEvent(Persister, Collection, (IEventSource)Session);
6468
for (int i = 0; i < preListeners.Length; i++)
6569
{
66-
await (preListeners[i].OnPreRecreateCollectionAsync(preEvent)).ConfigureAwait(false);
70+
await (preListeners[i].OnPreRecreateCollectionAsync(preEvent, cancellationToken)).ConfigureAwait(false);
6771
}
6872
}
6973
}
7074

71-
private async Task PostRecreateAsync()
75+
private async Task PostRecreateAsync(CancellationToken cancellationToken = default(CancellationToken))
7276
{
77+
cancellationToken.ThrowIfCancellationRequested();
7378
IPostCollectionRecreateEventListener[] postListeners = Session.Listeners.PostCollectionRecreateEventListeners;
7479
if (postListeners.Length > 0)
7580
{
7681
PostCollectionRecreateEvent postEvent = new PostCollectionRecreateEvent(Persister, Collection, (IEventSource)Session);
7782
for (int i = 0; i < postListeners.Length; i++)
7883
{
79-
await (postListeners[i].OnPostRecreateCollectionAsync(postEvent)).ConfigureAwait(false);
84+
await (postListeners[i].OnPostRecreateCollectionAsync(postEvent, cancellationToken)).ConfigureAwait(false);
8085
}
8186
}
8287
}

src/NHibernate/Async/Action/CollectionRemoveAction.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,28 @@
1818
namespace NHibernate.Action
1919
{
2020
using System.Threading.Tasks;
21+
using System.Threading;
2122
/// <content>
2223
/// Contains generated async methods
2324
/// </content>
2425
public sealed partial class CollectionRemoveAction : CollectionAction
2526
{
2627

27-
public override async Task ExecuteAsync()
28+
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
2829
{
30+
cancellationToken.ThrowIfCancellationRequested();
2931
bool statsEnabled = Session.Factory.Statistics.IsStatisticsEnabled;
3032
Stopwatch stopwatch = null;
3133
if (statsEnabled)
3234
{
3335
stopwatch = Stopwatch.StartNew();
3436
}
3537

36-
await (PreRemoveAsync()).ConfigureAwait(false);
38+
await (PreRemoveAsync(cancellationToken)).ConfigureAwait(false);
3739

3840
if (!emptySnapshot)
3941
{
40-
await (Persister.RemoveAsync(Key, Session)).ConfigureAwait(false);
42+
await (Persister.RemoveAsync(Key, Session, cancellationToken)).ConfigureAwait(false);
4143
}
4244

4345
IPersistentCollection collection = Collection;
@@ -48,7 +50,7 @@ public override async Task ExecuteAsync()
4850

4951
Evict();
5052

51-
await (PostRemoveAsync()).ConfigureAwait(false);
53+
await (PostRemoveAsync(cancellationToken)).ConfigureAwait(false);
5254

5355
if (statsEnabled)
5456
{
@@ -57,30 +59,32 @@ public override async Task ExecuteAsync()
5759
}
5860
}
5961

60-
private async Task PreRemoveAsync()
62+
private async Task PreRemoveAsync(CancellationToken cancellationToken = default(CancellationToken))
6163
{
64+
cancellationToken.ThrowIfCancellationRequested();
6265
IPreCollectionRemoveEventListener[] preListeners = Session.Listeners.PreCollectionRemoveEventListeners;
6366
if (preListeners.Length > 0)
6467
{
6568
PreCollectionRemoveEvent preEvent = new PreCollectionRemoveEvent(Persister, Collection, (IEventSource) Session,
6669
affectedOwner);
6770
for (int i = 0; i < preListeners.Length; i++)
6871
{
69-
await (preListeners[i].OnPreRemoveCollectionAsync(preEvent)).ConfigureAwait(false);
72+
await (preListeners[i].OnPreRemoveCollectionAsync(preEvent, cancellationToken)).ConfigureAwait(false);
7073
}
7174
}
7275
}
7376

74-
private async Task PostRemoveAsync()
77+
private async Task PostRemoveAsync(CancellationToken cancellationToken = default(CancellationToken))
7578
{
79+
cancellationToken.ThrowIfCancellationRequested();
7680
IPostCollectionRemoveEventListener[] postListeners = Session.Listeners.PostCollectionRemoveEventListeners;
7781
if (postListeners.Length > 0)
7882
{
7983
PostCollectionRemoveEvent postEvent = new PostCollectionRemoveEvent(Persister, Collection, (IEventSource) Session,
8084
affectedOwner);
8185
for (int i = 0; i < postListeners.Length; i++)
8286
{
83-
await (postListeners[i].OnPostRemoveCollectionAsync(postEvent)).ConfigureAwait(false);
87+
await (postListeners[i].OnPostRemoveCollectionAsync(postEvent, cancellationToken)).ConfigureAwait(false);
8488
}
8589
}
8690
}

src/NHibernate/Async/Action/CollectionUpdateAction.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
namespace NHibernate.Action
2222
{
2323
using System.Threading.Tasks;
24+
using System.Threading;
2425
/// <content>
2526
/// Contains generated async methods
2627
/// </content>
2728
public sealed partial class CollectionUpdateAction : CollectionAction
2829
{
2930

30-
public override async Task ExecuteAsync()
31+
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
3132
{
33+
cancellationToken.ThrowIfCancellationRequested();
3234
object id = Key;
3335
ISessionImplementor session = Session;
3436
ICollectionPersister persister = Persister;
@@ -42,7 +44,7 @@ public override async Task ExecuteAsync()
4244
stopwatch = Stopwatch.StartNew();
4345
}
4446

45-
await (PreUpdateAsync()).ConfigureAwait(false);
47+
await (PreUpdateAsync(cancellationToken)).ConfigureAwait(false);
4648

4749
if (!collection.WasInitialized)
4850
{
@@ -56,7 +58,7 @@ public override async Task ExecuteAsync()
5658
{
5759
if (!emptySnapshot)
5860
{
59-
await (persister.RemoveAsync(id, session)).ConfigureAwait(false);
61+
await (persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false);
6062
}
6163
}
6264
else if (collection.NeedsRecreate(persister))
@@ -68,22 +70,22 @@ public override async Task ExecuteAsync()
6870
}
6971
if (!emptySnapshot)
7072
{
71-
await (persister.RemoveAsync(id, session)).ConfigureAwait(false);
73+
await (persister.RemoveAsync(id, session, cancellationToken)).ConfigureAwait(false);
7274
}
73-
await (persister.RecreateAsync(collection, id, session)).ConfigureAwait(false);
75+
await (persister.RecreateAsync(collection, id, session, cancellationToken)).ConfigureAwait(false);
7476
}
7577
else
7678
{
77-
await (persister.DeleteRowsAsync(collection, id, session)).ConfigureAwait(false);
78-
await (persister.UpdateRowsAsync(collection, id, session)).ConfigureAwait(false);
79-
await (persister.InsertRowsAsync(collection, id, session)).ConfigureAwait(false);
79+
await (persister.DeleteRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false);
80+
await (persister.UpdateRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false);
81+
await (persister.InsertRowsAsync(collection, id, session, cancellationToken)).ConfigureAwait(false);
8082
}
8183

8284
Session.PersistenceContext.GetCollectionEntry(collection).AfterAction(collection);
8385

8486
Evict();
8587

86-
await (PostUpdateAsync()).ConfigureAwait(false);
88+
await (PostUpdateAsync(cancellationToken)).ConfigureAwait(false);
8789

8890
if (statsEnabled)
8991
{
@@ -92,28 +94,30 @@ public override async Task ExecuteAsync()
9294
}
9395
}
9496

95-
private async Task PreUpdateAsync()
97+
private async Task PreUpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
9698
{
99+
cancellationToken.ThrowIfCancellationRequested();
97100
IPreCollectionUpdateEventListener[] preListeners = Session.Listeners.PreCollectionUpdateEventListeners;
98101
if (preListeners.Length > 0)
99102
{
100103
PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(Persister, Collection, (IEventSource)Session);
101104
for (int i = 0; i < preListeners.Length; i++)
102105
{
103-
await (preListeners[i].OnPreUpdateCollectionAsync(preEvent)).ConfigureAwait(false);
106+
await (preListeners[i].OnPreUpdateCollectionAsync(preEvent, cancellationToken)).ConfigureAwait(false);
104107
}
105108
}
106109
}
107110

108-
private async Task PostUpdateAsync()
111+
private async Task PostUpdateAsync(CancellationToken cancellationToken = default(CancellationToken))
109112
{
113+
cancellationToken.ThrowIfCancellationRequested();
110114
IPostCollectionUpdateEventListener[] postListeners = Session.Listeners.PostCollectionUpdateEventListeners;
111115
if (postListeners.Length > 0)
112116
{
113117
PostCollectionUpdateEvent postEvent = new PostCollectionUpdateEvent(Persister, Collection, (IEventSource)Session);
114118
for (int i = 0; i < postListeners.Length; i++)
115119
{
116-
await (postListeners[i].OnPostUpdateCollectionAsync(postEvent)).ConfigureAwait(false);
120+
await (postListeners[i].OnPostUpdateCollectionAsync(postEvent, cancellationToken)).ConfigureAwait(false);
117121
}
118122
}
119123
}

src/NHibernate/Async/Action/EntityAction.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace NHibernate.Action
2020
{
2121
using System.Threading.Tasks;
22+
using System.Threading;
2223
/// <content>
2324
/// Contains generated async methods
2425
/// </content>
@@ -27,10 +28,14 @@ public abstract partial class EntityAction : IExecutable, IComparable<EntityActi
2728

2829
#region IExecutable Members
2930

30-
public abstract Task ExecuteAsync();
31+
public abstract Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
3132

32-
protected virtual Task AfterTransactionCompletionProcessImplAsync(bool success)
33+
protected virtual Task AfterTransactionCompletionProcessImplAsync(bool success, CancellationToken cancellationToken = default(CancellationToken))
3334
{
35+
if (cancellationToken.IsCancellationRequested)
36+
{
37+
return Task.FromCanceled<object>(cancellationToken);
38+
}
3439
try
3540
{
3641
AfterTransactionCompletionProcessImpl(success);

0 commit comments

Comments
 (0)