forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectionAction.cs
118 lines (106 loc) · 3.56 KB
/
CollectionAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Runtime.Serialization;
using NHibernate.Cache;
using NHibernate.Cache.Access;
using NHibernate.Collection;
using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.Persister;
using NHibernate.Persister.Collection;
using NHibernate.Persister.Entity;
using NHibernate.Util;
namespace NHibernate.Action
{
using System.Threading.Tasks;
using System.Threading;
public abstract partial class CollectionAction :
IAsyncExecutable,
IComparable<CollectionAction>,
IDeserializationCallback,
IAfterTransactionCompletionProcess,
ICacheableExecutable
{
protected async Task<object> GetKeyAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
if (key is DelayedPostInsertIdentifier)
{
// need to look it up
var finalKey = await (persister.CollectionType.GetKeyOfOwnerAsync(collection.Owner, session, cancellationToken)).ConfigureAwait(false);
if (finalKey == key)
{
// we may be screwed here since the collection action is about to execute
// and we do not know the final owner key value
}
return finalKey;
}
return key;
}
#region IExecutable Members
/// <summary> Called before executing any actions</summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public virtual async Task BeforeExecutionsAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
// we need to obtain the lock before any actions are
// executed, since this may be an inverse="true"
// bidirectional association and it is one of the
// earlier entity actions which actually updates
// the database (this action is responsible for
// second-level cache invalidation only)
if (persister.HasCache)
{
CacheKey ck = session.GenerateCacheKey(key, persister.KeyType, persister.Role);
softLock = await (persister.Cache.LockAsync(ck, null, cancellationToken)).ConfigureAwait(false);
}
}
/// <summary>Execute this action</summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public abstract Task ExecuteAsync(CancellationToken cancellationToken);
public virtual Task ExecuteAfterTransactionCompletionAsync(bool success, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
var ck = session.GenerateCacheKey(key, persister.KeyType, persister.Role);
return persister.Cache.ReleaseAsync(ck, softLock, cancellationToken);
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
#endregion
protected internal Task EvictAsync(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
if (persister.HasCache)
{
CacheKey ck = session.GenerateCacheKey(key, persister.KeyType, persister.Role);
return persister.Cache.EvictAsync(ck, cancellationToken);
}
return Task.CompletedTask;
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}