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 System.Collections.Specialized;
|
32
|
|
using System.Xml.Serialization;
|
33
|
|
using IBatisNet.DataMapper.Scope;
|
34
|
|
|
35
|
|
#endregion
|
36
|
|
|
37
|
|
namespace IBatisNet.DataMapper.Configuration.ResultMapping
|
38
|
|
{
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
[Serializable]
|
43
|
|
[XmlRoot("discriminator")]
|
44
|
|
public class Discriminator
|
45
|
|
{
|
46
|
|
|
47
|
|
#region Fields
|
48
|
|
[NonSerialized]
|
49
|
|
private ResultProperty _mapping = null;
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
|
[NonSerialized]
|
54
|
|
private HybridDictionary _resultMaps = null;
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
[NonSerialized]
|
59
|
|
private ArrayList _subMaps = null;
|
60
|
|
|
61
|
|
[NonSerialized]
|
62
|
|
private string _nullValue = string.Empty;
|
63
|
|
[NonSerialized]
|
64
|
|
private string _columnName = string.Empty;
|
65
|
|
[NonSerialized]
|
66
|
|
private int _columnIndex = ResultProperty.UNKNOWN_COLUMN_INDEX;
|
67
|
|
[NonSerialized]
|
68
|
|
private string _dbType = string.Empty;
|
69
|
|
[NonSerialized]
|
70
|
|
private string _clrType = string.Empty;
|
71
|
|
[NonSerialized]
|
72
|
|
private string _callBackName= string.Empty;
|
73
|
|
#endregion
|
74
|
|
|
75
|
|
#region Properties
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
[XmlAttribute("typeHandler")]
|
82
|
|
public string CallBackName
|
83
|
|
{
|
84
|
0
|
get { return _callBackName; }
|
85
|
170
|
set { _callBackName = value; }
|
86
|
|
}
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
0
|
[XmlAttribute("dbType")]
|
97
|
|
public string DbType
|
98
|
|
{
|
99
|
|
get { return _dbType; }
|
100
|
|
set { _dbType = value; }
|
101
|
|
}
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
|
|
111
|
|
[XmlAttribute("type")]
|
112
|
|
public string CLRType
|
113
|
|
{
|
114
|
0
|
get { return _clrType; }
|
115
|
170
|
set { _clrType = value; }
|
116
|
|
}
|
117
|
|
|
118
|
|
|
119
|
|
|
120
|
|
|
121
|
0
|
[XmlAttribute("columnIndex")]
|
122
|
|
public int ColumnIndex
|
123
|
|
{
|
124
|
|
get { return _columnIndex; }
|
125
|
|
set { _columnIndex = value; }
|
126
|
|
}
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
|
[XmlAttribute("column")]
|
132
|
|
public string ColumnName
|
133
|
|
{
|
134
|
0
|
get { return _columnName; }
|
135
|
340
|
set { _columnName = value; }
|
136
|
|
}
|
137
|
|
|
138
|
|
|
139
|
|
|
140
|
|
|
141
|
|
|
142
|
0
|
[XmlAttribute("nullValue")]
|
143
|
|
public string NullValue
|
144
|
|
{
|
145
|
|
get { return _nullValue; }
|
146
|
|
set { _nullValue = value; }
|
147
|
|
}
|
148
|
|
|
149
|
|
|
150
|
|
|
151
|
|
|
152
|
|
[XmlIgnore]
|
153
|
|
public ResultProperty ResultProperty
|
154
|
|
{
|
155
|
18
|
get { return _mapping; }
|
156
|
|
}
|
157
|
|
#endregion
|
158
|
|
|
159
|
|
#region Constructor
|
160
|
|
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
340
|
public Discriminator()
|
165
|
|
{
|
166
|
340
|
_resultMaps = new HybridDictionary();
|
167
|
340
|
_subMaps = new ArrayList();
|
168
|
|
}
|
169
|
|
#endregion
|
170
|
|
|
171
|
|
#region Methods
|
172
|
|
|
173
|
|
|
174
|
|
|
175
|
|
|
176
|
|
|
177
|
|
|
178
|
340
|
public void SetMapping(ConfigurationScope configScope, Type resultClass)
|
179
|
|
{
|
180
|
340
|
configScope.ErrorContext.MoreInfo = "Initialize discriminator mapping";
|
181
|
340
|
_mapping = new ResultProperty();
|
182
|
340
|
_mapping.ColumnName = _columnName;
|
183
|
340
|
_mapping.ColumnIndex = _columnIndex;
|
184
|
340
|
_mapping.CLRType = _clrType;
|
185
|
340
|
_mapping.CallBackName = _callBackName;
|
186
|
340
|
_mapping.DbType = _dbType;
|
187
|
340
|
_mapping.NullValue = _nullValue;
|
188
|
|
|
189
|
340
|
_mapping.Initialize( configScope, resultClass );
|
190
|
|
}
|
191
|
|
|
192
|
|
|
193
|
|
|
194
|
|
|
195
|
|
|
196
|
340
|
public void Initialize(ConfigurationScope configScope)
|
197
|
|
{
|
198
|
|
|
199
|
1020
|
for(int index=0; index<_subMaps.Count; index++)
|
200
|
|
{
|
201
|
680
|
SubMap subMap = _subMaps[index] as SubMap;
|
202
|
680
|
_resultMaps.Add(subMap.DiscriminatorValue, configScope.SqlMapper.GetResultMap( subMap.ResultMapName ) );
|
203
|
|
}
|
204
|
|
}
|
205
|
|
|
206
|
|
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
680
|
public void Add(SubMap subMap)
|
211
|
|
{
|
212
|
680
|
_subMaps.Add(subMap);
|
213
|
|
}
|
214
|
|
|
215
|
|
|
216
|
|
|
217
|
|
|
218
|
|
|
219
|
|
|
220
|
18
|
public ResultMap GetSubMap(string discriminatorValue)
|
221
|
|
{
|
222
|
18
|
return _resultMaps[discriminatorValue] as ResultMap;
|
223
|
|
}
|
224
|
|
|
225
|
|
#endregion
|
226
|
|
|
227
|
|
|
228
|
|
}
|
229
|
|
}
|
230
|
|
|