8
8
namespace NHibernate . Criterion
9
9
{
10
10
/// <summary>
11
- /// Defines a "switch" projection which supports multiple "cases" ("when/then's") using <see cref="ConditionalCriterionProjectionPair "/>.
11
+ /// Defines a "switch" projection which supports multiple "cases" ("when/then's") using <see cref="ConditionalProjectionCase "/>.
12
12
/// Can be used in Orderby for example.
13
13
/// </summary>
14
14
/// <seealso cref="SimpleProjection" />
15
- /// <seealso cref="ConditionalCriterionProjectionPair " />
15
+ /// <seealso cref="ConditionalProjectionCase " />
16
16
[ Serializable ]
17
17
public sealed class ConditionalsProjection : SimpleProjection
18
18
{
19
- private readonly ConditionalCriterionProjectionPair [ ] criterionProjections ;
19
+ private readonly ConditionalProjectionCase [ ] _cases ;
20
20
private readonly IProjection elseProjection ;
21
21
22
22
/// <summary>
23
23
/// Initializes a new instance of the <see cref="ConditionalsProjection"/> class.
24
24
/// </summary>
25
- /// <param name="conditionalProjections ">The <see cref="ConditionalCriterionProjectionPair "/>s containg your <see cref="ICriterion"/> and <see cref="IProjection"/> pairs.</param>
25
+ /// <param name="cases ">The <see cref="ConditionalProjectionCase "/>s containg your <see cref="ICriterion"/> and <see cref="IProjection"/> pairs.</param>
26
26
/// <param name="elseProjection">The else <see cref="IProjection"/>.</param>
27
- /// <exception cref="ArgumentNullException"><paramref name="conditionalProjections "/> is null.</exception>
27
+ /// <exception cref="ArgumentNullException"><paramref name="cases "/> is null.</exception>
28
28
/// <exception cref="ArgumentNullException"><paramref name="elseProjection"/> is null.</exception>
29
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="conditionalProjections "/> should not be empty.</exception>
30
- public ConditionalsProjection ( ConditionalCriterionProjectionPair [ ] conditionalProjections , IProjection elseProjection )
29
+ /// <exception cref="ArgumentOutOfRangeException"><paramref name="cases "/> should not be empty.</exception>
30
+ public ConditionalsProjection ( ConditionalProjectionCase [ ] cases , IProjection elseProjection )
31
31
{
32
32
if ( elseProjection is null )
33
33
{
34
34
throw new ArgumentNullException ( nameof ( elseProjection ) ) ;
35
35
}
36
36
37
- if ( conditionalProjections is null )
37
+ if ( cases is null )
38
38
{
39
- throw new ArgumentNullException ( nameof ( conditionalProjections ) ) ;
39
+ throw new ArgumentNullException ( nameof ( cases ) ) ;
40
40
}
41
41
42
- if ( conditionalProjections . Length == 0 )
42
+ if ( cases . Length == 0 )
43
43
{
44
- throw new ArgumentOutOfRangeException ( nameof ( this . criterionProjections ) , "Array should not be empty." ) ;
44
+ throw new ArgumentOutOfRangeException ( nameof ( cases ) , "Array should not be empty." ) ;
45
45
}
46
46
47
- this . criterionProjections = conditionalProjections . ToArray ( ) ;
47
+ _cases = cases ;
48
48
this . elseProjection = elseProjection ;
49
49
}
50
50
@@ -55,28 +55,28 @@ public override bool IsAggregate
55
55
if ( this . elseProjection . IsAggregate )
56
56
return true ;
57
57
58
- for ( int i = 0 ; i < this . criterionProjections . Length ; i ++ )
58
+ for ( int i = 0 ; i < _cases . Length ; i ++ )
59
59
{
60
- if ( this . CalcIsAggregate ( this . criterionProjections [ i ] ) )
60
+ if ( this . CalcIsAggregate ( _cases [ i ] ) )
61
61
return true ;
62
62
}
63
63
64
64
return false ;
65
65
}
66
66
}
67
67
68
- public override bool IsGrouped => this . elseProjection . IsGrouped || this . CalcIsGrouped ( this . criterionProjections ) ;
68
+ public override bool IsGrouped => this . elseProjection . IsGrouped || this . CalcIsGrouped ( _cases ) ;
69
69
70
70
public override SqlString ToSqlString ( ICriteria criteria , int position , ICriteriaQuery criteriaQuery )
71
71
{
72
- object [ ] parts = new object [ 5 + ( this . criterionProjections . Length * 4 ) ] ;
72
+ object [ ] parts = new object [ 5 + ( _cases . Length * 4 ) ] ;
73
73
var index = 0 ;
74
74
75
75
parts [ index ++ ] = "(case" ;
76
76
77
- for ( int i = 0 ; i < criterionProjections . Length ; i ++ )
77
+ for ( int i = 0 ; i < _cases . Length ; i ++ )
78
78
{
79
- ConditionalCriterionProjectionPair conditional = this . criterionProjections [ i ] ;
79
+ ConditionalProjectionCase conditional = _cases [ i ] ;
80
80
parts [ index ++ ] = " when " ;
81
81
parts [ index ++ ] = conditional . Criterion . ToSqlString ( criteria , criteriaQuery ) ;
82
82
parts [ index ++ ] = " then " ;
@@ -96,9 +96,9 @@ public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuer
96
96
{
97
97
var elseTypes = this . elseProjection . GetTypes ( criteria , criteriaQuery ) ;
98
98
99
- for ( int i = 0 ; i < this . criterionProjections . Length ; i ++ )
99
+ for ( int i = 0 ; i < _cases . Length ; i ++ )
100
100
{
101
- var subsequentTypes = this . criterionProjections [ i ] . Projection . GetTypes ( criteria , criteriaQuery ) ;
101
+ var subsequentTypes = _cases [ i ] . Projection . GetTypes ( criteria , criteriaQuery ) ;
102
102
103
103
this . AssertAreEqualTypes ( elseTypes , subsequentTypes , i . ToString ( ) ) ;
104
104
}
@@ -110,10 +110,10 @@ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery c
110
110
{
111
111
List < TypedValue > typedValues = new List < TypedValue > ( ) ;
112
112
113
- for ( int i = 0 ; i < this . criterionProjections . Length ; i ++ )
113
+ for ( int i = 0 ; i < _cases . Length ; i ++ )
114
114
{
115
- typedValues . AddRange ( this . criterionProjections [ i ] . Criterion . GetTypedValues ( criteria , criteriaQuery ) ) ;
116
- typedValues . AddRange ( this . criterionProjections [ i ] . Projection . GetTypedValues ( criteria , criteriaQuery ) ) ;
115
+ typedValues . AddRange ( _cases [ i ] . Criterion . GetTypedValues ( criteria , criteriaQuery ) ) ;
116
+ typedValues . AddRange ( _cases [ i ] . Projection . GetTypedValues ( criteria , criteriaQuery ) ) ;
117
117
}
118
118
119
119
typedValues . AddRange ( this . elseProjection . GetTypedValues ( criteria , criteriaQuery ) ) ;
@@ -125,7 +125,7 @@ public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery cr
125
125
{
126
126
SqlStringBuilder sqlBuilder = new SqlStringBuilder ( ) ;
127
127
128
- this . AddToGroupedSql ( sqlBuilder , this . criterionProjections , criteria , criteriaQuery ) ;
128
+ this . AddToGroupedSql ( sqlBuilder , _cases , criteria , criteriaQuery ) ;
129
129
this . AddToGroupedSql ( sqlBuilder , this . elseProjection , criteria , criteriaQuery ) ;
130
130
131
131
// ??
@@ -137,7 +137,7 @@ public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery cr
137
137
return sqlBuilder . ToSqlString ( ) ;
138
138
}
139
139
140
- private bool CalcIsGrouped ( IList < ConditionalCriterionProjectionPair > criterionProjections )
140
+ private bool CalcIsGrouped ( IList < ConditionalProjectionCase > criterionProjections )
141
141
{
142
142
for ( int i = 0 ; i < criterionProjections . Count ; i ++ )
143
143
{
@@ -187,7 +187,7 @@ private bool CalcIsGrouped(IProjection[] projections)
187
187
return false ;
188
188
}
189
189
190
- private bool CalcIsAggregate ( ConditionalCriterionProjectionPair criterionProjection )
190
+ private bool CalcIsAggregate ( ConditionalProjectionCase criterionProjection )
191
191
{
192
192
if ( criterionProjection . Projection . IsAggregate )
193
193
return true ;
@@ -202,15 +202,15 @@ private bool CalcIsAggregate(ConditionalCriterionProjectionPair criterionProject
202
202
return false ;
203
203
}
204
204
205
- private void AddToGroupedSql ( SqlStringBuilder sqlBuilder , ConditionalCriterionProjectionPair [ ] criterionProjections , ICriteria criteria , ICriteriaQuery criteriaQuery )
205
+ private void AddToGroupedSql ( SqlStringBuilder sqlBuilder , ConditionalProjectionCase [ ] criterionProjections , ICriteria criteria , ICriteriaQuery criteriaQuery )
206
206
{
207
207
for ( int i = 0 ; i < criterionProjections . Length ; i ++ )
208
208
{
209
209
this . AddToGroupedSql ( sqlBuilder , criterionProjections [ i ] , criteria , criteriaQuery ) ;
210
210
}
211
211
}
212
212
213
- private void AddToGroupedSql ( SqlStringBuilder sqlBuilder , ConditionalCriterionProjectionPair criterionProjection , ICriteria criteria , ICriteriaQuery criteriaQuery )
213
+ private void AddToGroupedSql ( SqlStringBuilder sqlBuilder , ConditionalProjectionCase criterionProjection , ICriteria criteria , ICriteriaQuery criteriaQuery )
214
214
{
215
215
this . AddToGroupedSql ( sqlBuilder , criterionProjection . Criterion , criteria , criteriaQuery ) ;
216
216
this . AddToGroupedSql ( sqlBuilder , criterionProjection . Projection , criteria , criteriaQuery ) ;
0 commit comments