forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIStatelessSession.cs
180 lines (159 loc) · 8.66 KB
/
IStatelessSession.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
//------------------------------------------------------------------------------
// <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.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.Multi;
using NHibernate.Util;
namespace NHibernate
{
using System.Threading.Tasks;
using System.Threading;
public static partial class StatelessSessionExtensions
{
//NOTE: Keep it as extension
/// <summary>
/// Return the persistent instance of the given entity name with the given identifier, or null
/// if there is no such persistent instance. (If the instance, or a proxy for the instance, is
/// already associated with the session, return that instance or proxy.)
/// </summary>
/// <typeparam name="T">The entity class.</typeparam>
/// <param name="session">The session.</param>
/// <param name="entityName">The entity name.</param>
/// <param name="id">The entity identifier.</param>
/// <param name="lockMode">The lock mode to use for getting the entity.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>A persistent instance, or <see langword="null" />.</returns>
public static async Task<T> GetAsync<T>(this IStatelessSession session, string entityName, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
return (T) await (session.GetAsync(entityName, id, lockMode, cancellationToken)).ConfigureAwait(false);
}
//NOTE: Keep it as extension
/// <summary>
/// Return the persistent instance of the given entity name with the given identifier, or null
/// if there is no such persistent instance. (If the instance, or a proxy for the instance, is
/// already associated with the session, return that instance or proxy.)
/// </summary>
/// <typeparam name="T">The entity class.</typeparam>
/// <param name="session">The session.</param>
/// <param name="entityName">The entity name.</param>
/// <param name="id">The entity identifier.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>A persistent instance, or <see langword="null" />.</returns>
public static async Task<T> GetAsync<T>(this IStatelessSession session, string entityName, object id, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
return (T) await (session.GetAsync(entityName, id, cancellationToken)).ConfigureAwait(false);
}
/// <summary>
/// Flush the batcher. When batching is enabled, a stateless session is no more fully stateless. It may retain
/// in its batcher some state waiting to be flushed to the database.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
public static Task FlushBatcherAsync(this IStatelessSession session, CancellationToken cancellationToken = default(CancellationToken))
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return session.GetSessionImplementation().FlushAsync(cancellationToken);
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
public partial interface IStatelessSession : IDisposable
{
/// <summary>Insert an entity.</summary>
/// <param name="entity">A new transient instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The identifier of the instance</returns>
Task<object> InsertAsync(object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Insert a row.</summary>
/// <param name="entityName">The name of the entity to be inserted</param>
/// <param name="entity">A new transient instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The identifier of the instance</returns>
Task<object> InsertAsync(string entityName, object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Update an entity.</summary>
/// <param name="entity">A detached entity instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task UpdateAsync(object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Update an entity.</summary>
/// <param name="entityName">The name of the entity to be updated</param>
/// <param name="entity">A detached entity instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task UpdateAsync(string entityName, object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Delete an entity.</summary>
/// <param name="entity">A detached entity instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task DeleteAsync(object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Delete an entity.</summary>
/// <param name="entityName">The name of the entity to be deleted</param>
/// <param name="entity">A detached entity instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task DeleteAsync(string entityName, object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>Retrieve a entity.</summary>
/// <returns>A detached entity instance</returns>
Task<object> GetAsync(string entityName, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieve an entity.
/// </summary>
/// <returns>A detached entity instance</returns>
Task<T> GetAsync<T>(object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieve an entity, obtaining the specified lock mode.
/// </summary>
/// <returns>A detached entity instance</returns>
Task<object> GetAsync(string entityName, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieve an entity, obtaining the specified lock mode.
/// </summary>
/// <returns>A detached entity instance</returns>
Task<T> GetAsync<T>(object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Refresh the entity instance state from the database.
/// </summary>
/// <param name="entity">The entity to be refreshed.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Refresh the entity instance state from the database.
/// </summary>
/// <param name="entityName">The name of the entity to be refreshed.</param>
/// <param name="entity">The entity to be refreshed.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(string entityName, object entity, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Refresh the entity instance state from the database.
/// </summary>
/// <param name="entity">The entity to be refreshed.</param>
/// <param name="lockMode">The LockMode to be applied.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(object entity, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Refresh the entity instance state from the database.
/// </summary>
/// <param name="entityName">The name of the entity to be refreshed.</param>
/// <param name="entity">The entity to be refreshed.</param>
/// <param name="lockMode">The LockMode to be applied.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(string entityName, object entity, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
}
}