/
Projections.cs
245 lines (219 loc) · 7.06 KB
/
Projections.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
using System;
using NHibernate.Type;
namespace NHibernate.Criterion
{
using NHibernate.Dialect.Function;
/// <summary>
/// The <tt>criterion</tt> package may be used by applications as a framework for building
/// new kinds of <tt>Projection</tt>. However, it is intended that most applications will
/// simply use the built-in projection types via the static factory methods of this class.<br/>
/// <br/>
/// The factory methods that take an alias allow the projected value to be referred to by
/// criterion and order instances.
/// </summary>
public class Projections
{
private Projections()
{
// Private Constructor, never called.
}
/// <summary>
/// Create a distinct projection from a projection
/// </summary>
/// <param name="proj"></param>
/// <returns></returns>
public static IProjection Distinct(IProjection proj)
{
return new Distinct(proj);
}
/// <summary>
/// Create a new projection list
/// </summary>
/// <returns></returns>
public static ProjectionList ProjectionList()
{
return new ProjectionList();
}
/// <summary>
/// The query row count, ie. <tt>count(*)</tt>
/// </summary>
/// <returns>The RowCount projection mapped to an <see cref="Int32"/>.</returns>
public static IProjection RowCount()
{
return new RowCountProjection();
}
/// <summary>
/// The query row count, ie. <tt>count(*)</tt>
/// </summary>
/// <returns>The RowCount projection mapped to an <see cref="Int64"/>.</returns>
public static IProjection RowCountInt64()
{
return new RowCountInt64Projection();
}
/// <summary>
/// A property value count
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static CountProjection Count(string propertyName)
{
return new CountProjection(propertyName);
}
/// <summary>
/// A distinct property value count
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static CountProjection CountDistinct(string propertyName)
{
return new CountProjection(propertyName).SetDistinct();
}
/// <summary>
/// A property maximum value
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static AggregateProjection Max(String propertyName)
{
return new AggregateProjection("max", propertyName);
}
/// <summary>
/// A property minimum value
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static AggregateProjection Min(String propertyName)
{
return new AggregateProjection("min", propertyName);
}
/// <summary>
/// A property average value
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static AggregateProjection Avg(string propertyName)
{
return new AvgProjection(propertyName);
}
/// <summary>
/// A property value sum
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static AggregateProjection Sum(String propertyName)
{
return new AggregateProjection("sum", propertyName);
}
/// <summary>
/// A SQL projection, a typed select clause fragment
/// </summary>
/// <param name="sql"></param>
/// <param name="columnAliases"></param>
/// <param name="types"></param>
/// <returns></returns>
public static IProjection SqlProjection(string sql, string[] columnAliases, IType[] types)
{
return new SQLProjection(sql, columnAliases, types);
}
/// <summary>
/// A grouping SQL projection, specifying both select clause and group by clause fragments
/// </summary>
/// <param name="sql"></param>
/// <param name="groupBy"></param>
/// <param name="columnAliases"></param>
/// <param name="types"></param>
/// <returns></returns>
public static IProjection SqlGroupProjection(string sql, string groupBy, string[] columnAliases, IType[] types)
{
return new SQLProjection(sql, groupBy, columnAliases, types);
}
/// <summary>
/// A grouping property value
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static PropertyProjection GroupProperty(string propertyName)
{
return new PropertyProjection(propertyName, true);
}
/// <summary>
/// A projected property value
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static PropertyProjection Property(string propertyName)
{
return new PropertyProjection(propertyName);
}
/// <summary>
/// A projected identifier value
/// </summary>
/// <returns></returns>
public static IdentifierProjection Id()
{
return new IdentifierProjection();
}
/// <summary>
/// Assign an alias to a projection, by wrapping it
/// </summary>
/// <param name="projection"></param>
/// <param name="alias"></param>
/// <returns></returns>
public static IProjection Alias(IProjection projection, string alias)
{
return new AliasedProjection(projection, alias);
}
/// <summary>
/// Casts the projection result to the specified type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="projection">The projection.</param>
/// <returns></returns>
public static IProjection Cast(IType type, IProjection projection)
{
return new CastProjection(type, projection);
}
/// <summary>
/// Return a constant value
/// </summary>
/// <param name="obj">The obj.</param>
/// <returns></returns>
public static IProjection Constant(object obj)
{
return new ConstantProjection(obj);
}
/// <summary>
/// Calls the named <see cref="ISQLFunction"/>
/// </summary>
/// <param name="functionName">Name of the function.</param>
/// <param name="type">The type.</param>
/// <param name="projections">The projections.</param>
/// <returns></returns>
public static IProjection SqlFunction(string functionName, IType type, params IProjection [] projections)
{
return new SqlFunctionProjection(functionName, type, projections);
}
/// <summary>
/// Calls the specified <see cref="ISQLFunction"/>
/// </summary>
/// <param name="function">the function.</param>
/// <param name="type">The type.</param>
/// <param name="projections">The projections.</param>
/// <returns></returns>
public static IProjection SqlFunction(ISQLFunction function, IType type, params IProjection[] projections)
{
return new SqlFunctionProjection(function, type, projections);
}
/// <summary>
/// Conditionally return the true or false part, dependention on the criterion
/// </summary>
/// <param name="criterion">The criterion.</param>
/// <param name="whenTrue">The when true.</param>
/// <param name="whenFalse">The when false.</param>
/// <returns></returns>
public static IProjection Conditional(ICriterion criterion, IProjection whenTrue, IProjection whenFalse)
{
return new ConditionalProjection(criterion, whenTrue, whenFalse);
}
}
}