|
1 | 1 | namespace NHibernate.Linq
|
2 | 2 | {
|
3 |
| - public class NhQueryableOptions: IQueryableOptions |
| 3 | + /// <summary> |
| 4 | + /// Expose NH queryable options. |
| 5 | + /// </summary> |
| 6 | + public class NhQueryableOptions |
| 7 | +#pragma warning disable 618 |
| 8 | + : IQueryableOptions |
| 9 | +#pragma warning restore 618 |
4 | 10 | {
|
5 |
| - protected internal bool? Cacheable { get; private set; } |
6 |
| - protected internal CacheMode? CacheMode{ get; private set; } |
7 |
| - protected internal string CacheRegion { get; private set; } |
8 |
| - protected internal int? Timeout { get; private set; } |
| 11 | + protected bool? Cacheable { get; private set; } |
| 12 | + protected CacheMode? CacheMode { get; private set; } |
| 13 | + protected string CacheRegion { get; private set; } |
| 14 | + protected int? Timeout { get; private set; } |
| 15 | + protected bool? ReadOnly { get; private set; } |
9 | 16 |
|
10 |
| - public IQueryableOptions SetCacheable(bool cacheable) |
| 17 | +#pragma warning disable 618 |
| 18 | + /// <inheritdoc /> |
| 19 | + IQueryableOptions IQueryableOptions.SetCacheable(bool cacheable) => SetCacheable(cacheable); |
| 20 | + |
| 21 | + /// <inheritdoc /> |
| 22 | + IQueryableOptions IQueryableOptions.SetCacheMode(CacheMode cacheMode) => SetCacheMode(cacheMode); |
| 23 | + |
| 24 | + /// <inheritdoc /> |
| 25 | + IQueryableOptions IQueryableOptions.SetCacheRegion(string cacheRegion) => SetCacheRegion(cacheRegion); |
| 26 | + |
| 27 | + /// <inheritdoc /> |
| 28 | + IQueryableOptions IQueryableOptions.SetTimeout(int timeout) => SetTimeout(timeout); |
| 29 | +#pragma warning restore 618 |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Enable caching of this query result set. |
| 33 | + /// </summary> |
| 34 | + /// <param name="cacheable">Should the query results be cacheable?</param> |
| 35 | + /// <returns><see langword="this"/> (for method chaining).</returns> |
| 36 | + public NhQueryableOptions SetCacheable(bool cacheable) |
11 | 37 | {
|
12 | 38 | Cacheable = cacheable;
|
13 | 39 | return this;
|
14 | 40 | }
|
15 | 41 |
|
16 |
| - public IQueryableOptions SetCacheMode(CacheMode cacheMode) |
| 42 | + /// <summary> |
| 43 | + /// Override the current session cache mode, just for this query. |
| 44 | + /// </summary> |
| 45 | + /// <param name="cacheMode">The cache mode to use.</param> |
| 46 | + /// <returns><see langword="this"/> (for method chaining).</returns> |
| 47 | + public NhQueryableOptions SetCacheMode(CacheMode cacheMode) |
17 | 48 | {
|
18 | 49 | CacheMode = cacheMode;
|
19 | 50 | return this;
|
20 | 51 | }
|
21 | 52 |
|
22 |
| - public IQueryableOptions SetCacheRegion(string cacheRegion) |
| 53 | + /// <summary> |
| 54 | + /// Set the name of the cache region. |
| 55 | + /// </summary> |
| 56 | + /// <param name="cacheRegion">The name of a query cache region, or <see langword="null" /> |
| 57 | + /// for the default query cache</param> |
| 58 | + /// <returns><see langword="this"/> (for method chaining).</returns> |
| 59 | + public NhQueryableOptions SetCacheRegion(string cacheRegion) |
23 | 60 | {
|
24 | 61 | CacheRegion = cacheRegion;
|
25 | 62 | return this;
|
26 | 63 | }
|
27 | 64 |
|
28 |
| - public IQueryableOptions SetTimeout(int timeout) |
| 65 | + /// <summary> |
| 66 | + /// Set the timeout for the underlying ADO query. |
| 67 | + /// </summary> |
| 68 | + /// <param name="timeout">The timeout in seconds.</param> |
| 69 | + /// <returns><see langword="this"/> (for method chaining).</returns> |
| 70 | + public NhQueryableOptions SetTimeout(int timeout) |
29 | 71 | {
|
30 | 72 | Timeout = timeout;
|
31 | 73 | return this;
|
32 | 74 | }
|
33 | 75 |
|
34 |
| - internal NhQueryableOptions Clone() |
| 76 | + /// <summary> |
| 77 | + /// Set the read-only mode for entities (and proxies) loaded by this query. This setting |
| 78 | + /// overrides the default setting for the session (see <see cref="ISession.DefaultReadOnly" />). |
| 79 | + /// </summary> |
| 80 | + /// <remarks> |
| 81 | + /// <para> |
| 82 | + /// Read-only entities can be modified, but changes are not persisted. They are not |
| 83 | + /// dirty-checked and snapshots of persistent state are not maintained. |
| 84 | + /// </para> |
| 85 | + /// <para> |
| 86 | + /// When a proxy is initialized, the loaded entity will have the same read-only setting |
| 87 | + /// as the uninitialized proxy, regardless of the session's current setting. |
| 88 | + /// </para> |
| 89 | + /// <para> |
| 90 | + /// The read-only setting has no impact on entities or proxies returned by the criteria |
| 91 | + /// that existed in the session before the criteria was executed. |
| 92 | + /// </para> |
| 93 | + /// </remarks> |
| 94 | + /// <param name="readOnly"> |
| 95 | + /// If <c>true</c>, entities (and proxies) loaded by the query will be read-only. |
| 96 | + /// </param> |
| 97 | + /// <returns><c>this</c> (for method chaining)</returns> |
| 98 | + public NhQueryableOptions SetReadOnly(bool readOnly) |
| 99 | + { |
| 100 | + ReadOnly = readOnly; |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + protected internal NhQueryableOptions Clone() |
35 | 105 | {
|
36 | 106 | return new NhQueryableOptions
|
37 | 107 | {
|
38 | 108 | Cacheable = Cacheable,
|
39 | 109 | CacheMode = CacheMode,
|
40 | 110 | CacheRegion = CacheRegion,
|
41 |
| - Timeout = Timeout |
| 111 | + Timeout = Timeout, |
| 112 | + ReadOnly = ReadOnly |
42 | 113 | };
|
43 | 114 | }
|
| 115 | + |
| 116 | + protected internal void Apply(IQuery query) |
| 117 | + { |
| 118 | + if (Timeout.HasValue) |
| 119 | + query.SetTimeout(Timeout.Value); |
| 120 | + |
| 121 | + if (Cacheable.HasValue) |
| 122 | + query.SetCacheable(Cacheable.Value); |
| 123 | + |
| 124 | + if (CacheMode.HasValue) |
| 125 | + query.SetCacheMode(CacheMode.Value); |
| 126 | + |
| 127 | + if (CacheRegion != null) |
| 128 | + query.SetCacheRegion(CacheRegion); |
| 129 | + |
| 130 | + if (ReadOnly.HasValue) |
| 131 | + query.SetReadOnly(ReadOnly.Value); |
| 132 | + } |
44 | 133 | }
|
45 | 134 | }
|
0 commit comments