13
13
namespace NHibernate . Cache
14
14
{
15
15
[ Serializable ]
16
- public class QueryKey : IDeserializationCallback
16
+ public class QueryKey : IDeserializationCallback , IEquatable < QueryKey >
17
17
{
18
18
private readonly ISessionFactoryImplementor _factory ;
19
19
private readonly SqlString _sqlQueryString ;
@@ -93,47 +93,51 @@ public QueryKey SetMaxRows(int[] maxRows)
93
93
94
94
public override bool Equals ( object other )
95
95
{
96
- QueryKey that = ( QueryKey ) other ;
97
- if ( ! _sqlQueryString . Equals ( that . _sqlQueryString ) )
96
+ return Equals ( other as QueryKey ) ;
97
+ }
98
+
99
+ public bool Equals ( QueryKey other )
100
+ {
101
+ if ( other == null || ! _sqlQueryString . Equals ( other . _sqlQueryString ) )
98
102
{
99
103
return false ;
100
104
}
101
- if ( _firstRow != that . _firstRow
102
- || _maxRows != that . _maxRows )
105
+
106
+ if ( _firstRow != other . _firstRow || _maxRows != other . _maxRows )
103
107
{
104
108
return false ;
105
109
}
106
110
107
- if ( ! Equals ( _customTransformer , that . _customTransformer ) )
111
+ if ( ! Equals ( _customTransformer , other . _customTransformer ) )
108
112
{
109
113
return false ;
110
114
}
111
115
112
116
if ( _types == null )
113
117
{
114
- if ( that . _types != null )
118
+ if ( other . _types != null )
115
119
{
116
120
return false ;
117
121
}
118
122
}
119
123
else
120
124
{
121
- if ( that . _types == null )
125
+ if ( other . _types == null )
122
126
{
123
127
return false ;
124
128
}
125
- if ( _types . Length != that . _types . Length )
129
+ if ( _types . Length != other . _types . Length )
126
130
{
127
131
return false ;
128
132
}
129
133
130
134
for ( int i = 0 ; i < _types . Length ; i ++ )
131
135
{
132
- if ( ! _types [ i ] . Equals ( that . _types [ i ] ) )
136
+ if ( ! _types [ i ] . Equals ( other . _types [ i ] ) )
133
137
{
134
138
return false ;
135
139
}
136
- if ( ! Equals ( _values [ i ] , that . _values [ i ] ) )
140
+ if ( ! Equals ( _values [ i ] , other . _values [ i ] ) )
137
141
{
138
142
return false ;
139
143
}
@@ -144,16 +148,16 @@ public override bool Equals(object other)
144
148
// issues on deserialization if GetHashCode or Equals are called in its deserialization callback. And
145
149
// building sets or dictionaries on the fly will in most cases be worst than BagEquals, unless re-coding
146
150
// its short-circuits.
147
- if ( ! CollectionHelper . BagEquals ( _filters , that . _filters ) )
151
+ if ( ! CollectionHelper . BagEquals ( _filters , other . _filters ) )
148
152
return false ;
149
- if ( ! CollectionHelper . BagEquals ( _namedParameters , that . _namedParameters , NamedParameterComparer . Instance ) )
153
+ if ( ! CollectionHelper . BagEquals ( _namedParameters , other . _namedParameters , NamedParameterComparer . Instance ) )
150
154
return false ;
151
155
152
- if ( ! CollectionHelper . SequenceEquals < int > ( _multiQueriesFirstRows , that . _multiQueriesFirstRows ) )
156
+ if ( ! CollectionHelper . SequenceEquals ( _multiQueriesFirstRows , other . _multiQueriesFirstRows ) )
153
157
{
154
158
return false ;
155
159
}
156
- if ( ! CollectionHelper . SequenceEquals < int > ( _multiQueriesMaxRows , that . _multiQueriesMaxRows ) )
160
+ if ( ! CollectionHelper . SequenceEquals ( _multiQueriesMaxRows , other . _multiQueriesMaxRows ) )
157
161
{
158
162
return false ;
159
163
}
0 commit comments