forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISessionFactory.cs
222 lines (203 loc) · 10.5 KB
/
ISessionFactory.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//------------------------------------------------------------------------------
// <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.Collections;
using System.Collections.Generic;
using System.Data.Common;
using NHibernate.Connection;
using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.Metadata;
using NHibernate.Stat;
using NHibernate.Util;
namespace NHibernate
{
using System.Threading.Tasks;
using System.Threading;
public static partial class SessionFactoryExtension
{
/// <summary>
/// Evict an entry from the second-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="factory">The session factory.</param>
/// <param name="entityName">The name of the entity to evict.</param>
/// <param name="id"></param>
/// <param name="tenantIdentifier">Tenant identifier</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static async Task EvictEntityAsync(this ISessionFactory factory, string entityName, object id, string tenantIdentifier, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
if (tenantIdentifier == null)
await (factory.EvictEntityAsync(entityName, id, cancellationToken)).ConfigureAwait(false);
await (ReflectHelper.CastOrThrow<SessionFactoryImpl>(factory, "multi-tenancy").EvictEntityAsync(entityName, id, tenantIdentifier, cancellationToken)).ConfigureAwait(false);
}
/// <summary>
/// Evict an entry from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="factory">The session factory.</param>
/// <param name="roleName">Collection role name.</param>
/// <param name="id">Collection id</param>
/// <param name="tenantIdentifier">Tenant identifier</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static async Task EvictCollectionAsync(this ISessionFactory factory, string roleName, object id, string tenantIdentifier, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
if (tenantIdentifier == null)
await (factory.EvictCollectionAsync(roleName, id, cancellationToken)).ConfigureAwait(false);
await (ReflectHelper.CastOrThrow<SessionFactoryImpl>(factory, "multi-tenancy").EvictCollectionAsync(roleName, id, tenantIdentifier, cancellationToken)).ConfigureAwait(false);
}
/// <summary>
/// Evict all entries from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="factory">The session factory.</param>
/// <param name="persistentClasses">The classes of the entities to evict.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static async Task EvictAsync(this ISessionFactory factory, IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
if (factory is SessionFactoryImpl sfi)
{
await (sfi.EvictAsync(persistentClasses, cancellationToken)).ConfigureAwait(false);
}
else
{
if (persistentClasses == null)
throw new ArgumentNullException(nameof(persistentClasses));
foreach (var @class in persistentClasses)
{
await (factory.EvictAsync(@class, cancellationToken)).ConfigureAwait(false);
}
}
}
/// <summary>
/// Evict all entries from the second-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="factory">The session factory.</param>
/// <param name="entityNames">The names of the entities to evict.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static async Task EvictEntityAsync(this ISessionFactory factory, IEnumerable<string> entityNames, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
if (factory is SessionFactoryImpl sfi)
{
await (sfi.EvictEntityAsync(entityNames, cancellationToken)).ConfigureAwait(false);
}
else
{
if (entityNames == null)
throw new ArgumentNullException(nameof(entityNames));
foreach (var name in entityNames)
{
await (factory.EvictEntityAsync(name, cancellationToken)).ConfigureAwait(false);
}
}
}
/// <summary>
/// Evict all entries from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="factory">The session factory.</param>
/// <param name="roleNames">The names of the collections to evict.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static async Task EvictCollectionAsync(this ISessionFactory factory, IEnumerable<string> roleNames, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
if (factory is SessionFactoryImpl sfi)
{
await (sfi.EvictCollectionAsync(roleNames, cancellationToken)).ConfigureAwait(false);
}
else
{
if (roleNames == null)
throw new ArgumentNullException(nameof(roleNames));
foreach (var role in roleNames)
{
await (factory.EvictCollectionAsync(role, cancellationToken)).ConfigureAwait(false);
}
}
}
}
public partial interface ISessionFactory : IDisposable
{
/// <summary>
/// Destroy this <c>SessionFactory</c> and release all resources
/// connection pools, etc). It is the responsibility of the application
/// to ensure that there are no open <c>Session</c>s before calling
/// <c>close()</c>.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict all entries from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="persistentClass"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictAsync(System.Type persistentClass, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict an entry from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="persistentClass"></param>
/// <param name="id"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictAsync(System.Type persistentClass, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict all entries from the second-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
Task EvictEntityAsync(string entityName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict an entry from the second-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
Task EvictEntityAsync(string entityName, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict all entries from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="roleName"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictCollectionAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict an entry from the process-level cache. This method occurs outside
/// of any transaction; it performs an immediate "hard" remove, so does not respect
/// any transaction isolation semantics of the usage strategy. Use with care.
/// </summary>
/// <param name="roleName"></param>
/// <param name="id"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictCollectionAsync(string roleName, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict any query result sets cached in the default query cache region.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictQueriesAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Evict any query result sets cached in the named query cache region.
/// </summary>
/// <param name="cacheRegion"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictQueriesAsync(string cacheRegion, CancellationToken cancellationToken = default(CancellationToken));
}
}