forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISession.cs
648 lines (596 loc) · 34.7 KB
/
ISession.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
//------------------------------------------------------------------------------
// <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.Event;
using NHibernate.Event.Default;
using NHibernate.Impl;
using NHibernate.Multi;
using NHibernate.Stat;
using NHibernate.Type;
using NHibernate.Util;
namespace NHibernate
{
using System.Threading.Tasks;
using System.Threading;
public static partial class SessionExtensions
{
/// <summary>
/// Return the persistent instance of the given entity class 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>
/// <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 Task<object> GetAsync(this ISession session, string entityName, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken))
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<object>(cancellationToken);
}
try
{
return
ReflectHelper
.CastOrThrow<SessionImpl>(session, "Get with entityName and lockMode")
.GetAsync(entityName, id, lockMode, cancellationToken);
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
//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 ISession 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 ISession session, string entityName, object id, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
return (T) await (session.GetAsync(entityName, id, cancellationToken)).ConfigureAwait(false);
}
}
public partial interface ISession : IDisposable
{
/// <summary>
/// Force the <c>ISession</c> to flush.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// Must be called at the end of a unit of work, before committing the transaction and closing
/// the session (<c>Transaction.Commit()</c> calls this method). <i>Flushing</i> is the process
/// of synchronizing the underlying persistent store with persistable state held in memory.
/// </remarks>
Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Does this <c>ISession</c> contain any changes which must be
/// synchronized with the database? Would any SQL be executed if
/// we flushed this session? May trigger save cascades, which could
/// cause themselves some SQL to be executed, especially if the
/// <c>identity</c> id generator is used.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// <para>
/// The default implementation first checks if it contains saved or deleted entities to be flushed. If not, it
/// then delegate the check to its <see cref="IDirtyCheckEventListener" />, which by default is
/// <see cref="DefaultDirtyCheckEventListener" />.
/// </para>
/// <para>
/// <see cref="DefaultDirtyCheckEventListener" /> replicates all the beginning of the flush process, checking
/// dirtiness of entities loaded in the session and triggering their pending cascade operations in order to
/// detect new and removed children. This can have the side effect of performing the <see cref="Save(object)"/>
/// of children, causing their id to be generated. Depending on their id generator, this can trigger calls to
/// the database and even actually insert them if using an <c>identity</c> generator.
/// </para>
/// </remarks>
Task<bool> IsDirtyAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Remove this instance from the session cache.
/// </summary>
/// <remarks>
/// Changes to the instance will not be synchronized with the database.
/// This operation cascades to associated instances if the association is mapped
/// with <c>cascade="all"</c> or <c>cascade="all-delete-orphan"</c>.
/// </remarks>
/// <param name="obj">a persistent instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task EvictAsync(Object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// obtaining the specified lock mode.
/// </summary>
/// <param name="theType">A persistent class</param>
/// <param name="id">A valid identifier of an existing persistent instance of the class</param>
/// <param name="lockMode">The lock level</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>the persistent instance</returns>
Task<object> LoadAsync(System.Type theType, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// obtaining the specified lock mode, assuming the instance exists.
/// </summary>
/// <param name="entityName">The entity-name of a persistent class</param>
/// <param name="id">a valid identifier of an existing persistent instance of the class </param>
/// <param name="lockMode">the lock level </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> the persistent instance or proxy </returns>
Task<object> LoadAsync(string entityName, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// assuming that the instance exists.
/// </summary>
/// <remarks>
/// You should not use this method to determine if an instance exists (use a query or
/// <see cref="Get(System.Type, object)" /> instead). Use this only to retrieve an instance
/// that you assume exists, where non-existence would be an actual error.
/// </remarks>
/// <param name="theType">A persistent class</param>
/// <param name="id">A valid identifier of an existing persistent instance of the class</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The persistent instance or proxy</returns>
Task<object> LoadAsync(System.Type theType, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// obtaining the specified lock mode.
/// </summary>
/// <typeparam name="T">A persistent class</typeparam>
/// <param name="id">A valid identifier of an existing persistent instance of the class</param>
/// <param name="lockMode">The lock level</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>the persistent instance</returns>
Task<T> LoadAsync<T>(object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// assuming that the instance exists.
/// </summary>
/// <remarks>
/// You should not use this method to determine if an instance exists (use a query or
/// <see cref="Get{T}(object)" /> instead). Use this only to retrieve an instance that you
/// assume exists, where non-existence would be an actual error.
/// </remarks>
/// <typeparam name="T">A persistent class</typeparam>
/// <param name="id">A valid identifier of an existing persistent instance of the class</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The persistent instance or proxy</returns>
Task<T> LoadAsync<T>(object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given <paramref name="entityName"/> with the given identifier,
/// assuming that the instance exists.
/// </summary>
/// <param name="entityName">The entity-name of a persistent class</param>
/// <param name="id">a valid identifier of an existing persistent instance of the class </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> The persistent instance or proxy </returns>
/// <remarks>
/// You should not use this method to determine if an instance exists (use <see cref="Get(string,object)"/>
/// instead). Use this only to retrieve an instance that you assume exists, where non-existence
/// would be an actual error.
/// </remarks>
Task<object> LoadAsync(string entityName, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Read the persistent state associated with the given identifier into the given transient
/// instance.
/// </summary>
/// <param name="obj">An "empty" instance of the persistent class</param>
/// <param name="id">A valid identifier of an existing persistent instance of the class</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task LoadAsync(object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist all reachable transient objects, reusing the current identifier
/// values. Note that this will not trigger the Interceptor of the Session.
/// </summary>
/// <param name="obj">a detached instance of a persistent class</param>
/// <param name="replicationMode"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task ReplicateAsync(object obj, ReplicationMode replicationMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist the state of the given detached instance, reusing the current
/// identifier value. This operation cascades to associated instances if
/// the association is mapped with <tt>cascade="replicate"</tt>.
/// </summary>
/// <param name="entityName"></param>
/// <param name="obj">a detached instance of a persistent class </param>
/// <param name="replicationMode"></param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task ReplicateAsync(string entityName, object obj, ReplicationMode replicationMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist the given transient instance, first assigning a generated identifier.
/// </summary>
/// <remarks>
/// Save will use the current value of the identifier property if the <c>Assigned</c>
/// generator is used.
/// </remarks>
/// <param name="obj">A transient instance of a persistent class</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The generated identifier</returns>
Task<object> SaveAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist the given transient instance, using the given identifier.
/// </summary>
/// <param name="obj">A transient instance of a persistent class</param>
/// <param name="id">An unused valid identifier</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task SaveAsync(object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist the given transient instance, first assigning a generated identifier. (Or
/// using the current value of the identifier property if the <tt>assigned</tt>
/// generator is used.)
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a transient instance of a persistent class </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> the generated identifier </returns>
/// <remarks>
/// This operation cascades to associated instances if the
/// association is mapped with <tt>cascade="save-update"</tt>.
/// </remarks>
Task<object> SaveAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Persist the given transient instance, using the given identifier.
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a transient instance of a persistent class </param>
/// <param name="id">An unused valid identifier</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// This operation cascades to associated instances if the
/// association is mapped with <tt>cascade="save-update"</tt>.
/// </remarks>
Task SaveAsync(string entityName, object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Either <c>Save()</c> or <c>Update()</c> the given instance, depending upon the value of
/// its identifier property.
/// </summary>
/// <remarks>
/// By default the instance is always saved. This behaviour may be adjusted by specifying
/// an <c>unsaved-value</c> attribute of the identifier property mapping
/// </remarks>
/// <param name="obj">A transient instance containing new or updated state</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task SaveOrUpdateAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Either <see cref="Save(String,Object)"/> or <see cref="Update(String,Object)"/>
/// the given instance, depending upon resolution of the unsaved-value checks
/// (see the manual for discussion of unsaved-value checking).
/// </summary>
/// <param name="entityName">The name of the entity </param>
/// <param name="obj">a transient or detached instance containing new or updated state </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <seealso cref="ISession.Save(String,Object)"/>
/// <seealso cref="ISession.Update(String,Object)"/>
/// <remarks>
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="save-update"</tt>.
/// </remarks>
Task SaveOrUpdateAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Either <c>Save()</c> or <c>Update()</c> the given instance, depending upon the value of
/// its identifier property.
/// </summary>
/// <remarks>
/// By default the instance is always saved. This behaviour may be adjusted by specifying
/// an <c>unsaved-value</c> attribute of the identifier property mapping
/// </remarks>
/// <param name="entityName">The name of the entity</param>
/// <param name="obj">A transient instance containing new or updated state</param>
/// <param name="id">Identifier of persistent instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task SaveOrUpdateAsync(string entityName, object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update the persistent instance with the identifier of the given transient instance.
/// </summary>
/// <remarks>
/// If there is a persistent instance with the same identifier, an exception is thrown. If
/// the given transient instance has a <see langword="null" /> identifier, an exception will be thrown.
/// </remarks>
/// <param name="obj">A transient instance containing updated state</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task UpdateAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update the persistent state associated with the given identifier.
/// </summary>
/// <remarks>
/// An exception is thrown if there is a persistent instance with the same identifier
/// in the current session.
/// </remarks>
/// <param name="obj">A transient instance containing updated state</param>
/// <param name="id">Identifier of persistent instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task UpdateAsync(object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update the persistent instance with the identifier of the given detached
/// instance.
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a detached instance containing updated state </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// If there is a persistent instance with the same identifier,
/// an exception is thrown. This operation cascades to associated instances
/// if the association is mapped with <tt>cascade="save-update"</tt>.
/// </remarks>
Task UpdateAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update the persistent instance associated with the given identifier.
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a detached instance containing updated state </param>
/// <param name="id">Identifier of persistent instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// If there is a persistent instance with the same identifier,
/// an exception is thrown. This operation cascades to associated instances
/// if the association is mapped with <tt>cascade="save-update"</tt>.
/// </remarks>
Task UpdateAsync(string entityName, object obj, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Copy the state of the given object onto the persistent object with the same
/// identifier. If there is no persistent instance currently associated with
/// the session, it will be loaded. Return the persistent instance. If the
/// given instance is unsaved, save a copy of and return it as a newly persistent
/// instance. The given instance does not become associated with the session.
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="merge"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="obj">a detached instance with state to be copied </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> an updated persistent instance </returns>
Task<object> MergeAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Copy the state of the given object onto the persistent object with the same
/// identifier. If there is no persistent instance currently associated with
/// the session, it will be loaded. Return the persistent instance. If the
/// given instance is unsaved, save a copy of and return it as a newly persistent
/// instance. The given instance does not become associated with the session.
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="merge"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="entityName">Name of the entity.</param>
/// <param name="obj">a detached instance with state to be copied </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> an updated persistent instance </returns>
Task<object> MergeAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Copy the state of the given object onto the persistent object with the same
/// identifier. If there is no persistent instance currently associated with
/// the session, it will be loaded. Return the persistent instance. If the
/// given instance is unsaved, save a copy of and return it as a newly persistent
/// instance. The given instance does not become associated with the session.
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="merge"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="entity">a detached instance with state to be copied </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> an updated persistent instance </returns>
Task<T> MergeAsync<T>(T entity, CancellationToken cancellationToken = default(CancellationToken)) where T : class;
/// <summary>
/// Copy the state of the given object onto the persistent object with the same
/// identifier. If there is no persistent instance currently associated with
/// the session, it will be loaded. Return the persistent instance. If the
/// given instance is unsaved, save a copy of and return it as a newly persistent
/// instance. The given instance does not become associated with the session.
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="merge"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="entityName">Name of the entity.</param>
/// <param name="entity">a detached instance with state to be copied </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> an updated persistent instance </returns>
Task<T> MergeAsync<T>(string entityName, T entity, CancellationToken cancellationToken = default(CancellationToken)) where T : class;
/// <summary>
/// Make a transient instance persistent. This operation cascades to associated
/// instances if the association is mapped with <tt>cascade="persist"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="obj">a transient instance to be made persistent </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task PersistAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Make a transient instance persistent. This operation cascades to associated
/// instances if the association is mapped with <tt>cascade="persist"</tt>.<br/>
/// The semantics of this method are defined by JSR-220.
/// </summary>
/// <param name="entityName">Name of the entity.</param>
/// <param name="obj">a transient instance to be made persistent</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task PersistAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Remove a persistent instance from the datastore.
/// </summary>
/// <remarks>
/// The argument may be an instance associated with the receiving <c>ISession</c> or a
/// transient instance with an identifier associated with existing persistent state.
/// </remarks>
/// <param name="obj">The instance to be removed</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task DeleteAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Remove a persistent instance from the datastore. The <b>object</b> argument may be
/// an instance associated with the receiving <see cref="ISession"/> or a transient
/// instance with an identifier associated with existing persistent state.
/// This operation cascades to associated instances if the association is mapped
/// with <tt>cascade="delete"</tt>.
/// </summary>
/// <param name="entityName">The entity name for the instance to be removed. </param>
/// <param name="obj">the instance to be removed </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task DeleteAsync(string entityName, object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Delete all objects returned by the query.
/// </summary>
/// <param name="query">The query string</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>Returns the number of objects deleted.</returns>
Task<int> DeleteAsync(string query, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Delete all objects returned by the query.
/// </summary>
/// <param name="query">The query string</param>
/// <param name="value">A value to be written to a "?" placeholer in the query</param>
/// <param name="type">The hibernate type of value.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The number of instances deleted</returns>
Task<int> DeleteAsync(string query, object value, IType type, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Delete all objects returned by the query.
/// </summary>
/// <param name="query">The query string</param>
/// <param name="values">A list of values to be written to "?" placeholders in the query</param>
/// <param name="types">A list of Hibernate types of the values</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>The number of instances deleted</returns>
Task<int> DeleteAsync(string query, object[] values, IType[] types, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Obtain the specified lock level upon the given object.
/// </summary>
/// <param name="obj">A persistent instance</param>
/// <param name="lockMode">The lock level</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task LockAsync(object obj, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Obtain the specified lock level upon the given object.
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a persistent or transient instance </param>
/// <param name="lockMode">the lock level </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <remarks>
/// This may be used to perform a version check (<see cref="LockMode.Read"/>), to upgrade to a pessimistic
/// lock (<see cref="LockMode.Upgrade"/>), or to simply reassociate a transient instance
/// with a session (<see cref="LockMode.None"/>). This operation cascades to associated
/// instances if the association is mapped with <tt>cascade="lock"</tt>.
/// </remarks>
Task LockAsync(string entityName, object obj, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Re-read the state of the given instance from the underlying database.
/// </summary>
/// <remarks>
/// <para>
/// It is inadvisable to use this to implement long-running sessions that span many
/// business tasks. This method is, however, useful in certain special circumstances.
/// </para>
/// <para>
/// For example,
/// <list>
/// <item>Where a database trigger alters the object state upon insert or update</item>
/// <item>After executing direct SQL (eg. a mass update) in the same session</item>
/// <item>After inserting a <c>Blob</c> or <c>Clob</c></item>
/// </list>
/// </para>
/// </remarks>
/// <param name="obj">A persistent instance</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Re-read the state of the given instance from the underlying database, with
/// the given <c>LockMode</c>.
/// </summary>
/// <remarks>
/// It is inadvisable to use this to implement long-running sessions that span many
/// business tasks. This method is, however, useful in certain special circumstances.
/// </remarks>
/// <param name="obj">a persistent or transient instance</param>
/// <param name="lockMode">the lock mode to use</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
Task RefreshAsync(object obj, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Create a new instance of <c>Query</c> for the given collection and filter string
/// </summary>
/// <param name="collection">A persistent collection</param>
/// <param name="queryString">A hibernate query</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>A query</returns>
Task<IQuery> CreateFilterAsync(object collection, string queryString, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class 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>
/// <param name="clazz">a persistent class</param>
/// <param name="id">an identifier</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>a persistent instance or null</returns>
Task<object> GetAsync(System.Type clazz, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier, or null
/// if there is no such persistent instance. Obtain the specified lock mode if the instance
/// exists.
/// </summary>
/// <param name="clazz">a persistent class</param>
/// <param name="id">an identifier</param>
/// <param name="lockMode">the lock mode</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>a persistent instance or null</returns>
Task<object> GetAsync(System.Type clazz, object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the persistent instance of the given named entity 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>
/// <param name="entityName">the entity name </param>
/// <param name="id">an identifier </param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> a persistent instance or null </returns>
Task<object> GetAsync(string entityName, object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Strongly-typed version of <see cref="Get(System.Type, object)" />
/// </summary>
Task<T> GetAsync<T>(object id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Strongly-typed version of <see cref="Get(System.Type, object, LockMode)" />
/// </summary>
Task<T> GetAsync<T>(object id, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Return the entity name for a persistent entity
/// </summary>
/// <param name="obj">a persistent entity</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns> the entity name </returns>
Task<string> GetEntityNameAsync(object obj, CancellationToken cancellationToken = default(CancellationToken));
}
}