1
|
|
|
2
|
|
#region Apache Notice
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
#endregion
|
26
|
|
|
27
|
|
#region Using
|
28
|
|
|
29
|
|
using System;
|
30
|
|
using System.Collections;
|
31
|
|
using IBatisNet.Common.Utilities.Objects;
|
32
|
|
using IBatisNet.DataMapper.TypeHandlers;
|
33
|
|
|
34
|
|
#endregion
|
35
|
|
|
36
|
|
|
37
|
|
namespace IBatisNet.DataMapper
|
38
|
|
{
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
[Serializable]
|
43
|
|
internal class CacheKey
|
44
|
|
{
|
45
|
|
#region Fields
|
46
|
|
private string[] _properties = null;
|
47
|
|
private object _parameter = null;
|
48
|
|
private string _sql = string.Empty;
|
49
|
|
private string _statementName = string.Empty;
|
50
|
|
private int _maxResults = 0 ;
|
51
|
|
private int _skipRecords = 0;
|
52
|
|
private CacheKeyType _type = CacheKeyType.Object;
|
53
|
|
private TypeHandlerFactory _typeHandlerFactory = null;
|
54
|
|
|
55
|
|
private string _hashCodeString = string.Empty;
|
56
|
|
private int _hashCode = 0;
|
57
|
|
#endregion
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
13
|
internal CacheKey(TypeHandlerFactory typeHandlerFactory, string statementName, string sql, object parameter, string[] properties,
|
71
|
|
int skipRecords, int maxResults, CacheKeyType type)
|
72
|
|
{
|
73
|
13
|
_typeHandlerFactory = typeHandlerFactory;
|
74
|
13
|
_statementName = statementName;
|
75
|
13
|
_sql = sql;
|
76
|
13
|
_parameter = parameter;
|
77
|
13
|
_properties = properties;
|
78
|
13
|
_skipRecords = skipRecords;
|
79
|
13
|
_maxResults = maxResults;
|
80
|
13
|
_type = type;
|
81
|
13
|
_hashCode = GenerateHashCode();
|
82
|
13
|
_hashCodeString = Convert.ToString(_hashCode);
|
83
|
|
}
|
84
|
|
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
13
|
private int GenerateHashCode()
|
95
|
|
{
|
96
|
13
|
int result = 0;
|
97
|
|
|
98
|
13
|
if (_parameter is Hashtable)
|
99
|
|
{
|
100
|
0
|
result = (_parameter != null ? _parameter.GetHashCode() : 0);
|
101
|
|
}
|
102
|
13
|
else if ( _parameter != null && _typeHandlerFactory.IsSimpleType(_parameter.GetType()) )
|
103
|
|
{
|
104
|
1
|
result = (_parameter != null ? _parameter.GetHashCode() : 0);
|
105
|
|
}
|
106
|
|
else
|
107
|
|
{
|
108
|
12
|
result = (_parameter != null ? ObjectProbe.ObjectHashCode(_parameter, _properties) : 0);
|
109
|
|
}
|
110
|
13
|
result = 29 * result + (_statementName != null ? _statementName.GetHashCode() : 0);
|
111
|
13
|
result = 29 * result + (_sql != null ? _sql.GetHashCode() : 0);
|
112
|
13
|
result = 29 * result + _maxResults;
|
113
|
13
|
result = 29 * result + _skipRecords;
|
114
|
13
|
result = 29 * result + (int)_type;
|
115
|
13
|
return result;
|
116
|
|
}
|
117
|
|
|
118
|
|
|
119
|
|
|
120
|
|
|
121
|
|
|
122
|
|
|
123
|
5
|
public override bool Equals(object obj)
|
124
|
|
{
|
125
|
|
|
126
|
0
|
if (this == obj) return true;
|
127
|
0
|
if (!(obj is CacheKey)) return false;
|
128
|
|
|
129
|
5
|
CacheKey cacheKey = (CacheKey)obj;
|
130
|
|
|
131
|
0
|
if (_maxResults != cacheKey._maxResults) return false;
|
132
|
0
|
if (_skipRecords != cacheKey._skipRecords) return false;
|
133
|
0
|
if (_type != cacheKey._type) return false;
|
134
|
5
|
if (_parameter is Hashtable)
|
135
|
|
{
|
136
|
0
|
if (_hashCode != cacheKey._hashCode) return false;
|
137
|
0
|
if (!_parameter.Equals(cacheKey._parameter)) return false;
|
138
|
|
}
|
139
|
5
|
else if (_parameter != null && _typeHandlerFactory.IsSimpleType(_parameter.GetType()))
|
140
|
|
{
|
141
|
0
|
if (_parameter != null ? !_parameter.Equals(cacheKey._parameter) : cacheKey._parameter != null) return false;
|
142
|
|
}
|
143
|
|
else
|
144
|
|
{
|
145
|
0
|
if (_hashCode != cacheKey._hashCode) return false;
|
146
|
|
}
|
147
|
0
|
if (_sql != null ? !_sql.Equals(cacheKey._sql) : cacheKey._sql != null) return false;
|
148
|
|
|
149
|
5
|
return true;
|
150
|
|
}
|
151
|
|
|
152
|
|
|
153
|
|
|
154
|
|
|
155
|
|
|
156
|
|
|
157
|
21
|
public override int GetHashCode()
|
158
|
|
{
|
159
|
21
|
return _hashCode;
|
160
|
|
}
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
|
|
165
|
|
|
166
|
0
|
public override string ToString()
|
167
|
|
{
|
168
|
|
return _hashCodeString;
|
169
|
|
}
|
170
|
|
|
171
|
|
}
|
172
|
|
}
|
173
|
|
|