/src/NHibernate/Async/ISessionFactory.cs

https://github.com/RogerKratz/nhibernate-core · C# · 222 lines · 95 code · 19 blank · 108 comment · 13 complexity · 9a8da84c103ba58761230f8146247acf MD5 · raw file

  1. //------------------------------------------------------------------------------
  2. // <auto-generated>
  3. // This code was generated by AsyncGenerator.
  4. //
  5. // Changes to this file may cause incorrect behavior and will be lost if
  6. // the code is regenerated.
  7. // </auto-generated>
  8. //------------------------------------------------------------------------------
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data.Common;
  13. using NHibernate.Connection;
  14. using NHibernate.Engine;
  15. using NHibernate.Impl;
  16. using NHibernate.Metadata;
  17. using NHibernate.Stat;
  18. using NHibernate.Util;
  19. namespace NHibernate
  20. {
  21. using System.Threading.Tasks;
  22. using System.Threading;
  23. public static partial class SessionFactoryExtension
  24. {
  25. /// <summary>
  26. /// Evict an entry from the second-level cache. This method occurs outside
  27. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  28. /// any transaction isolation semantics of the usage strategy. Use with care.
  29. /// </summary>
  30. /// <param name="factory">The session factory.</param>
  31. /// <param name="entityName">The name of the entity to evict.</param>
  32. /// <param name="id"></param>
  33. /// <param name="tenantIdentifier">Tenant identifier</param>
  34. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  35. public static async Task EvictEntityAsync(this ISessionFactory factory, string entityName, object id, string tenantIdentifier, CancellationToken cancellationToken = default(CancellationToken))
  36. {
  37. cancellationToken.ThrowIfCancellationRequested();
  38. if (tenantIdentifier == null)
  39. await (factory.EvictEntityAsync(entityName, id, cancellationToken)).ConfigureAwait(false);
  40. await (ReflectHelper.CastOrThrow<SessionFactoryImpl>(factory, "multi-tenancy").EvictEntityAsync(entityName, id, tenantIdentifier, cancellationToken)).ConfigureAwait(false);
  41. }
  42. /// <summary>
  43. /// Evict an entry from the process-level cache. This method occurs outside
  44. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  45. /// any transaction isolation semantics of the usage strategy. Use with care.
  46. /// </summary>
  47. /// <param name="factory">The session factory.</param>
  48. /// <param name="roleName">Collection role name.</param>
  49. /// <param name="id">Collection id</param>
  50. /// <param name="tenantIdentifier">Tenant identifier</param>
  51. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  52. public static async Task EvictCollectionAsync(this ISessionFactory factory, string roleName, object id, string tenantIdentifier, CancellationToken cancellationToken = default(CancellationToken))
  53. {
  54. cancellationToken.ThrowIfCancellationRequested();
  55. if (tenantIdentifier == null)
  56. await (factory.EvictCollectionAsync(roleName, id, cancellationToken)).ConfigureAwait(false);
  57. await (ReflectHelper.CastOrThrow<SessionFactoryImpl>(factory, "multi-tenancy").EvictCollectionAsync(roleName, id, tenantIdentifier, cancellationToken)).ConfigureAwait(false);
  58. }
  59. /// <summary>
  60. /// Evict all entries from the process-level cache. This method occurs outside
  61. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  62. /// any transaction isolation semantics of the usage strategy. Use with care.
  63. /// </summary>
  64. /// <param name="factory">The session factory.</param>
  65. /// <param name="persistentClasses">The classes of the entities to evict.</param>
  66. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  67. public static async Task EvictAsync(this ISessionFactory factory, IEnumerable<System.Type> persistentClasses, CancellationToken cancellationToken = default(CancellationToken))
  68. {
  69. cancellationToken.ThrowIfCancellationRequested();
  70. if (factory is SessionFactoryImpl sfi)
  71. {
  72. await (sfi.EvictAsync(persistentClasses, cancellationToken)).ConfigureAwait(false);
  73. }
  74. else
  75. {
  76. if (persistentClasses == null)
  77. throw new ArgumentNullException(nameof(persistentClasses));
  78. foreach (var @class in persistentClasses)
  79. {
  80. await (factory.EvictAsync(@class, cancellationToken)).ConfigureAwait(false);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// Evict all entries from the second-level cache. This method occurs outside
  86. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  87. /// any transaction isolation semantics of the usage strategy. Use with care.
  88. /// </summary>
  89. /// <param name="factory">The session factory.</param>
  90. /// <param name="entityNames">The names of the entities to evict.</param>
  91. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  92. public static async Task EvictEntityAsync(this ISessionFactory factory, IEnumerable<string> entityNames, CancellationToken cancellationToken = default(CancellationToken))
  93. {
  94. cancellationToken.ThrowIfCancellationRequested();
  95. if (factory is SessionFactoryImpl sfi)
  96. {
  97. await (sfi.EvictEntityAsync(entityNames, cancellationToken)).ConfigureAwait(false);
  98. }
  99. else
  100. {
  101. if (entityNames == null)
  102. throw new ArgumentNullException(nameof(entityNames));
  103. foreach (var name in entityNames)
  104. {
  105. await (factory.EvictEntityAsync(name, cancellationToken)).ConfigureAwait(false);
  106. }
  107. }
  108. }
  109. /// <summary>
  110. /// Evict all entries from the process-level cache. This method occurs outside
  111. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  112. /// any transaction isolation semantics of the usage strategy. Use with care.
  113. /// </summary>
  114. /// <param name="factory">The session factory.</param>
  115. /// <param name="roleNames">The names of the collections to evict.</param>
  116. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  117. public static async Task EvictCollectionAsync(this ISessionFactory factory, IEnumerable<string> roleNames, CancellationToken cancellationToken = default(CancellationToken))
  118. {
  119. cancellationToken.ThrowIfCancellationRequested();
  120. if (factory is SessionFactoryImpl sfi)
  121. {
  122. await (sfi.EvictCollectionAsync(roleNames, cancellationToken)).ConfigureAwait(false);
  123. }
  124. else
  125. {
  126. if (roleNames == null)
  127. throw new ArgumentNullException(nameof(roleNames));
  128. foreach (var role in roleNames)
  129. {
  130. await (factory.EvictCollectionAsync(role, cancellationToken)).ConfigureAwait(false);
  131. }
  132. }
  133. }
  134. }
  135. public partial interface ISessionFactory : IDisposable
  136. {
  137. /// <summary>
  138. /// Destroy this <c>SessionFactory</c> and release all resources
  139. /// connection pools, etc). It is the responsibility of the application
  140. /// to ensure that there are no open <c>Session</c>s before calling
  141. /// <c>close()</c>.
  142. /// </summary>
  143. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  144. Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken));
  145. /// <summary>
  146. /// Evict all entries from the process-level cache. This method occurs outside
  147. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  148. /// any transaction isolation semantics of the usage strategy. Use with care.
  149. /// </summary>
  150. /// <param name="persistentClass"></param>
  151. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  152. Task EvictAsync(System.Type persistentClass, CancellationToken cancellationToken = default(CancellationToken));
  153. /// <summary>
  154. /// Evict an entry from the process-level cache. This method occurs outside
  155. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  156. /// any transaction isolation semantics of the usage strategy. Use with care.
  157. /// </summary>
  158. /// <param name="persistentClass"></param>
  159. /// <param name="id"></param>
  160. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  161. Task EvictAsync(System.Type persistentClass, object id, CancellationToken cancellationToken = default(CancellationToken));
  162. /// <summary>
  163. /// Evict all entries from the second-level cache. This method occurs outside
  164. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  165. /// any transaction isolation semantics of the usage strategy. Use with care.
  166. /// </summary>
  167. Task EvictEntityAsync(string entityName, CancellationToken cancellationToken = default(CancellationToken));
  168. /// <summary>
  169. /// Evict an entry from the second-level cache. This method occurs outside
  170. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  171. /// any transaction isolation semantics of the usage strategy. Use with care.
  172. /// </summary>
  173. Task EvictEntityAsync(string entityName, object id, CancellationToken cancellationToken = default(CancellationToken));
  174. /// <summary>
  175. /// Evict all entries from the process-level cache. This method occurs outside
  176. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  177. /// any transaction isolation semantics of the usage strategy. Use with care.
  178. /// </summary>
  179. /// <param name="roleName"></param>
  180. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  181. Task EvictCollectionAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken));
  182. /// <summary>
  183. /// Evict an entry from the process-level cache. This method occurs outside
  184. /// of any transaction; it performs an immediate "hard" remove, so does not respect
  185. /// any transaction isolation semantics of the usage strategy. Use with care.
  186. /// </summary>
  187. /// <param name="roleName"></param>
  188. /// <param name="id"></param>
  189. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  190. Task EvictCollectionAsync(string roleName, object id, CancellationToken cancellationToken = default(CancellationToken));
  191. /// <summary>
  192. /// Evict any query result sets cached in the default query cache region.
  193. /// </summary>
  194. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  195. Task EvictQueriesAsync(CancellationToken cancellationToken = default(CancellationToken));
  196. /// <summary>
  197. /// Evict any query result sets cached in the named query cache region.
  198. /// </summary>
  199. /// <param name="cacheRegion"></param>
  200. /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
  201. Task EvictQueriesAsync(string cacheRegion, CancellationToken cancellationToken = default(CancellationToken));
  202. }
  203. }