1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ibatis.sqlmap.engine.mapping.parameter;
17
18 import com.ibatis.common.resources.Resources;
19 import com.ibatis.sqlmap.client.SqlMapException;
20 import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
21 import com.ibatis.sqlmap.engine.type.TypeHandler;
22
23
24
25
26 public class ParameterMapping {
27
28
29 private static final String MODE_INOUT = "INOUT";
30
31
32 private static final String MODE_OUT = "OUT";
33
34
35 private static final String MODE_IN = "IN";
36
37
38 private String propertyName;
39
40
41 private TypeHandler typeHandler;
42
43
44 private String typeName;
45
46
47 private int jdbcType;
48
49
50 private String jdbcTypeName;
51
52
53 private String nullValue;
54
55
56 private String mode;
57
58
59 private boolean inputAllowed;
60
61
62 private boolean outputAllowed;
63
64
65 private Class javaType;
66
67
68 private String resultMapName;
69
70
71 private Integer numericScale;
72
73
74 private String errorString;
75
76
77
78
79 public ParameterMapping() {
80 mode = "IN";
81 inputAllowed = true;
82 outputAllowed = false;
83
84 jdbcType = JdbcTypeRegistry.UNKNOWN_TYPE;
85 }
86
87
88
89
90
91
92 public String getNullValue() {
93 return nullValue;
94 }
95
96
97
98
99
100
101
102 public void setNullValue(String nullValue) {
103 this.nullValue = nullValue;
104 }
105
106
107
108
109
110
111 public String getPropertyName() {
112 return propertyName;
113 }
114
115
116
117
118
119
120
121 public void setPropertyName(String propertyName) {
122 this.errorString = "Check the parameter mapping for the '" + propertyName + "' property.";
123 this.propertyName = propertyName;
124 }
125
126
127
128
129
130
131 public String getErrorString() {
132 return errorString;
133 }
134
135
136
137
138
139
140 public TypeHandler getTypeHandler() {
141 return typeHandler;
142 }
143
144
145
146
147
148
149
150 public void setTypeHandler(TypeHandler typeHandler) {
151 this.typeHandler = typeHandler;
152 }
153
154
155
156
157
158
159 public Class getJavaType() {
160 return javaType;
161 }
162
163
164
165
166
167
168
169 public void setJavaType(Class javaType) {
170 this.javaType = javaType;
171 }
172
173
174
175
176
177
178 public String getJavaTypeName() {
179 if (javaType == null) {
180 return null;
181 } else {
182 return javaType.getName();
183 }
184 }
185
186
187
188
189
190
191
192 public void setJavaTypeName(String javaTypeName) {
193 try {
194 if (javaTypeName == null) {
195 this.javaType = null;
196 } else {
197 this.javaType = Resources.classForName(javaTypeName);
198 }
199 } catch (ClassNotFoundException e) {
200 throw new SqlMapException("Error setting javaType property of ParameterMap. Cause: " + e, e);
201 }
202 }
203
204
205
206
207
208
209 public int getJdbcType() {
210 return jdbcType;
211 }
212
213
214
215
216
217
218 public String getJdbcTypeName() {
219 return jdbcTypeName;
220 }
221
222
223
224
225
226
227
228 public void setJdbcTypeName(String jdbcTypeName) {
229 this.jdbcTypeName = jdbcTypeName;
230 this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
231 }
232
233
234
235
236
237
238 public String getMode() {
239 return mode;
240 }
241
242
243
244
245
246
247
248 public void setMode(String mode) {
249 this.mode = mode;
250 inputAllowed = MODE_IN.equals(mode) || MODE_INOUT.equals(mode);
251 outputAllowed = MODE_OUT.equals(mode) || MODE_INOUT.equals(mode);
252 }
253
254
255
256
257
258
259 public boolean isInputAllowed() {
260 return inputAllowed;
261 }
262
263
264
265
266
267
268 public boolean isOutputAllowed() {
269 return outputAllowed;
270 }
271
272
273
274
275
276
277 public String getTypeName() {
278 return typeName;
279 }
280
281
282
283
284
285
286
287 public void setTypeName(String typeName) {
288 this.typeName = typeName;
289 }
290
291
292
293
294
295
296 public String getResultMapName() {
297 return resultMapName;
298 }
299
300
301
302
303
304
305
306 public void setResultMapName(String resultMapName) {
307 this.resultMapName = resultMapName;
308 }
309
310
311
312
313
314
315 public Integer getNumericScale() {
316 return numericScale;
317 }
318
319
320
321
322
323
324
325 public void setNumericScale(Integer numericScale) {
326 if (numericScale != null && numericScale.intValue() < 0) {
327 throw new RuntimeException(
328 "Error setting numericScale on parameter mapping. Cause: scale must be greater than or equal to zero");
329 }
330 this.numericScale = numericScale;
331 }
332
333 }