forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetachedCriteria.cs
269 lines (223 loc) · 6.15 KB
/
DetachedCriteria.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
using System;
using System.Collections;
using NHibernate.Impl;
using NHibernate.SqlCommand;
using NHibernate.Transform;
namespace NHibernate.Expression
{
/// <summary>
/// Some applications need to create criteria queries in "detached
/// mode", where the Hibernate session is not available. This class
/// may be instantiated anywhere, and then a <c>ICriteria</c>
/// may be obtained by passing a session to
/// <c>GetExecutableCriteria()</c>. All methods have the
/// same semantics and behavior as the corresponding methods of the
/// <c>ICriteria</c> interface.
/// </summary>
[Serializable]
public class DetachedCriteria
{
private CriteriaImpl impl;
private ICriteria criteria;
protected DetachedCriteria(System.Type entityType)
{
impl = new CriteriaImpl(entityType, null);
criteria = impl;
}
protected DetachedCriteria(System.Type entityType, string alias)
{
impl = new CriteriaImpl(entityType, alias, null);
criteria = impl;
}
protected DetachedCriteria(CriteriaImpl impl, ICriteria criteria)
{
this.impl = impl;
this.criteria = criteria;
}
/// <summary>
/// Get an executable instance of <c>Criteria</c>,
/// to actually run the query.</summary>
public ICriteria GetExecutableCriteria(ISession session)
{
impl.Session = session.GetSessionImplementation();
return impl;
}
public static DetachedCriteria For(System.Type entityType)
{
return new DetachedCriteria(entityType);
}
public static DetachedCriteria For<T>()
{
return new DetachedCriteria(typeof(T));
}
public static DetachedCriteria For<T>(string alias)
{
return new DetachedCriteria(typeof(T), alias);
}
public static DetachedCriteria For(System.Type entityType, string alias)
{
return new DetachedCriteria(entityType, alias);
}
public DetachedCriteria Add(ICriterion criterion)
{
criteria.Add(criterion);
return this;
}
public DetachedCriteria AddOrder(Order order)
{
criteria.AddOrder(order);
return this;
}
public DetachedCriteria CreateAlias(string associationPath, string alias)
{
criteria.CreateAlias(associationPath, alias);
return this;
}
public DetachedCriteria CreateAlias(string associationPath, string alias, JoinType joinType)
{
criteria.CreateAlias(associationPath, alias, joinType);
return this;
}
public DetachedCriteria CreateCriteria(string associationPath, string alias)
{
return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, alias));
}
public DetachedCriteria CreateCriteria(string associationPath)
{
return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath));
}
public DetachedCriteria CreateCriteria(string associationPath, JoinType joinType)
{
return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, joinType));
}
public DetachedCriteria CreateCriteria(string associationPath, string alias, JoinType joinType)
{
return new DetachedCriteria(impl, criteria.CreateCriteria(associationPath, alias, joinType));
}
public string Alias
{
get { return criteria.Alias; }
}
public DetachedCriteria SetFetchMode(string associationPath, FetchMode mode)
{
criteria.SetFetchMode(associationPath, mode);
return this;
}
public DetachedCriteria SetCacheMode(CacheMode cacheMode)
{
criteria.SetCacheMode(cacheMode);
return this;
}
public DetachedCriteria SetProjection(IProjection projection)
{
criteria.SetProjection(projection);
return this;
}
public DetachedCriteria SetResultTransformer(IResultTransformer resultTransformer)
{
criteria.SetResultTransformer(resultTransformer);
return this;
}
public DetachedCriteria SetFirstResult(int firstResult)
{
criteria.SetFirstResult(firstResult);
return this;
}
public DetachedCriteria SetMaxResults(int maxResults)
{
criteria.SetMaxResults(maxResults);
return this;
}
public override string ToString()
{
return "DetachableCriteria(" + criteria.ToString() + ')';
}
protected internal CriteriaImpl GetCriteriaImpl()
{
return impl;
}
protected internal void SetCriteriaImpl(CriteriaImpl impl)
{
this.impl = impl;
this.criteria = impl;
}
public DetachedCriteria GetCriteriaByPath(string path)
{
ICriteria tmpCrit = criteria.GetCriteriaByPath(path);
if(tmpCrit==null)
return null;
return new DetachedCriteria(impl, tmpCrit);
}
public DetachedCriteria GetCriteriaByAlias(string alias)
{
ICriteria tmpCrit = criteria.GetCriteriaByAlias(alias);
if (tmpCrit == null)
return null;
return new DetachedCriteria(impl, tmpCrit);
}
public int MaxResults
{
get { return impl.MaxResults; }
}
public int FirstResult
{
get { return impl.FirstResult; }
}
public int Timeout
{
get { return impl.Timeout; }
}
public int FetchSize
{
get { return impl.FetchSize; }
}
public System.Type CriteriaClass
{
get { return impl.CriteriaClass; }
}
public IDictionary LockModes
{
get { return impl.LockModes; }
}
public IResultTransformer ResultTransformer
{
get { return impl.ResultTransformer; }
}
public bool Cacheable
{
get { return impl.Cacheable; }
}
public string CacheRegion
{
get { return impl.CacheRegion; }
}
public IProjection Projection
{
get { return impl.Projection; }
}
public ICriteria ProjectionCriteria
{
get { return impl.ProjectionCriteria; }
}
public IList Restrictions
{
get { return impl.Restrictions; }
}
public IList Orders
{
get { return impl.Orders; }
}
public IDictionary FetchModes
{
get { return impl.FetchModes; }
}
public IList SubcriteriaList
{
get { return impl.SubcriteriaList; }
}
public string RootAlias
{
get { return impl.RootAlias; }
}
}
}