@@ -30,6 +30,8 @@ public class CriteriaLoader : OuterJoinLoader
30
30
private readonly string [ ] userAliases ;
31
31
private readonly bool [ ] includeInResultRow ;
32
32
private readonly int resultRowLength ;
33
+ // caching NH-3486
34
+ private readonly string [ ] cachedProjectedColumnAliases ;
33
35
34
36
public CriteriaLoader ( IOuterJoinLoadable persister , ISessionFactoryImplementor factory , CriteriaImpl rootCriteria ,
35
37
string rootEntityName , IDictionary < string , IFilter > enabledFilters )
@@ -48,6 +50,11 @@ public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor f
48
50
resultTypes = walker . ResultTypes ;
49
51
includeInResultRow = walker . IncludeInResultRow ;
50
52
resultRowLength = ArrayHelper . CountTrue ( IncludeInResultRow ) ;
53
+ // fill caching objects only if there is a projection
54
+ if ( translator . HasProjection )
55
+ {
56
+ cachedProjectedColumnAliases = translator . ProjectedColumnAliases ;
57
+ }
51
58
52
59
PostInstantiate ( ) ;
53
60
}
@@ -74,7 +81,7 @@ public IType[] ResultTypes
74
81
get { return resultTypes ; }
75
82
}
76
83
77
- protected override string [ ] ResultRowAliases
84
+ protected override string [ ] ResultRowAliases
78
85
{
79
86
get { return userAliases ; }
80
87
}
@@ -113,22 +120,20 @@ protected override object[] GetResultRow(object[] row, IDataReader rs, ISessionI
113
120
114
121
if ( translator . HasProjection )
115
122
{
116
- IType [ ] types = translator . ProjectedTypes ;
117
- result = new object [ types . Length ] ;
118
- string [ ] columnAliases = translator . ProjectedColumnAliases ;
119
-
123
+ result = new object [ ResultTypes . Length ] ;
124
+
120
125
for ( int i = 0 , position = 0 ; i < result . Length ; i ++ )
121
126
{
122
- int numColumns = types [ i ] . GetColumnSpan ( session . Factory ) ;
123
-
124
- if ( numColumns > 1 )
127
+ int numColumns = ResultTypes [ i ] . GetColumnSpan ( session . Factory ) ;
128
+
129
+ if ( numColumns > 1 )
125
130
{
126
- string [ ] typeColumnAliases = ArrayHelper . Slice ( columnAliases , position , numColumns ) ;
127
- result [ i ] = types [ i ] . NullSafeGet ( rs , typeColumnAliases , session , null ) ;
131
+ string [ ] typeColumnAliases = ArrayHelper . Slice ( cachedProjectedColumnAliases , position , numColumns ) ;
132
+ result [ i ] = ResultTypes [ i ] . NullSafeGet ( rs , typeColumnAliases , session , null ) ;
128
133
}
129
134
else
130
135
{
131
- result [ i ] = types [ i ] . NullSafeGet ( rs , columnAliases [ position ] , session , null ) ;
136
+ result [ i ] = ResultTypes [ i ] . NullSafeGet ( rs , cachedProjectedColumnAliases [ position ] , session , null ) ;
132
137
}
133
138
position += numColumns ;
134
139
}
@@ -222,4 +227,4 @@ protected override IEnumerable<IParameterSpecification> GetParameterSpecificatio
222
227
return translator . CollectedParameterSpecifications ;
223
228
}
224
229
}
225
- }
230
+ }
0 commit comments