forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNhQueryableOptions.cs
166 lines (147 loc) · 5.01 KB
/
NhQueryableOptions.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
namespace NHibernate.Linq
{
/// <summary>
/// Expose NH queryable options.
/// </summary>
public class NhQueryableOptions
#pragma warning disable 618
: IQueryableOptions
#pragma warning restore 618
{
protected bool? Cacheable { get; private set; }
protected CacheMode? CacheMode { get; private set; }
protected string CacheRegion { get; private set; }
protected int? Timeout { get; private set; }
protected bool? ReadOnly { get; private set; }
protected string Comment { get; private set; }
protected FlushMode? FlushMode { get; private set; }
#pragma warning disable 618
/// <inheritdoc />
IQueryableOptions IQueryableOptions.SetCacheable(bool cacheable) => SetCacheable(cacheable);
/// <inheritdoc />
IQueryableOptions IQueryableOptions.SetCacheMode(CacheMode cacheMode) => SetCacheMode(cacheMode);
/// <inheritdoc />
IQueryableOptions IQueryableOptions.SetCacheRegion(string cacheRegion) => SetCacheRegion(cacheRegion);
/// <inheritdoc />
IQueryableOptions IQueryableOptions.SetTimeout(int timeout) => SetTimeout(timeout);
#pragma warning restore 618
/// <summary>
/// Enable caching of this query result set.
/// </summary>
/// <param name="cacheable">Should the query results be cacheable?</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetCacheable(bool cacheable)
{
Cacheable = cacheable;
return this;
}
/// <summary>
/// Override the current session cache mode, just for this query.
/// </summary>
/// <param name="cacheMode">The cache mode to use.</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetCacheMode(CacheMode cacheMode)
{
CacheMode = cacheMode;
return this;
}
/// <summary>
/// Set the name of the cache region.
/// </summary>
/// <param name="cacheRegion">The name of a query cache region, or <see langword="null" />
/// for the default query cache</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetCacheRegion(string cacheRegion)
{
CacheRegion = cacheRegion;
return this;
}
/// <summary>
/// Set the timeout for the underlying ADO query.
/// </summary>
/// <param name="timeout">The timeout in seconds.</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetTimeout(int timeout)
{
Timeout = timeout;
return this;
}
/// <summary>
/// Set the read-only mode for entities (and proxies) loaded by this query. This setting
/// overrides the default setting for the session (see <see cref="ISession.DefaultReadOnly" />).
/// </summary>
/// <remarks>
/// <para>
/// Read-only entities can be modified, but changes are not persisted. They are not
/// dirty-checked and snapshots of persistent state are not maintained.
/// </para>
/// <para>
/// When a proxy is initialized, the loaded entity will have the same read-only setting
/// as the uninitialized proxy, regardless of the session's current setting.
/// </para>
/// <para>
/// The read-only setting has no impact on entities or proxies returned by the criteria
/// that existed in the session before the criteria was executed.
/// </para>
/// </remarks>
/// <param name="readOnly">
/// If <c>true</c>, entities (and proxies) loaded by the query will be read-only.
/// </param>
/// <returns><c>this</c> (for method chaining)</returns>
public NhQueryableOptions SetReadOnly(bool readOnly)
{
ReadOnly = readOnly;
return this;
}
/// <summary>
/// Set a comment that will be prepended before the generated SQL.
/// </summary>
/// <param name="comment">The comment to prepend.</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetComment(string comment)
{
Comment = comment;
return this;
}
/// <summary>
/// Override the current session flush mode, just for this query.
/// </summary>
/// <param name="flushMode">The flush mode to use for the query.</param>
/// <returns><see langword="this"/> (for method chaining).</returns>
public NhQueryableOptions SetFlushMode(FlushMode flushMode)
{
FlushMode = flushMode;
return this;
}
protected internal NhQueryableOptions Clone()
{
return new NhQueryableOptions
{
Cacheable = Cacheable,
CacheMode = CacheMode,
CacheRegion = CacheRegion,
Timeout = Timeout,
ReadOnly = ReadOnly,
Comment = Comment,
FlushMode = FlushMode
};
}
protected internal void Apply(IQuery query)
{
if (Timeout.HasValue)
query.SetTimeout(Timeout.Value);
if (Cacheable.HasValue)
query.SetCacheable(Cacheable.Value);
if (CacheMode.HasValue)
query.SetCacheMode(CacheMode.Value);
if (CacheRegion != null)
query.SetCacheRegion(CacheRegion);
if (ReadOnly.HasValue)
query.SetReadOnly(ReadOnly.Value);
if (!string.IsNullOrEmpty(Comment))
query.SetComment(Comment);
if (FlushMode.HasValue)
query.SetFlushMode(FlushMode.Value);
}
}
}