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 }
182 return javaType.getName();
183 }
184
185
186
187
188
189
190
191 public void setJavaTypeName(String javaTypeName) {
192 try {
193 if (javaTypeName == null) {
194 this.javaType = null;
195 } else {
196 this.javaType = Resources.classForName(javaTypeName);
197 }
198 } catch (ClassNotFoundException e) {
199 throw new SqlMapException("Error setting javaType property of ParameterMap. Cause: " + e, e);
200 }
201 }
202
203
204
205
206
207
208 public int getJdbcType() {
209 return jdbcType;
210 }
211
212
213
214
215
216
217 public String getJdbcTypeName() {
218 return jdbcTypeName;
219 }
220
221
222
223
224
225
226
227 public void setJdbcTypeName(String jdbcTypeName) {
228 this.jdbcTypeName = jdbcTypeName;
229 this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
230 }
231
232
233
234
235
236
237 public String getMode() {
238 return mode;
239 }
240
241
242
243
244
245
246
247 public void setMode(String mode) {
248 this.mode = mode;
249 inputAllowed = MODE_IN.equals(mode) || MODE_INOUT.equals(mode);
250 outputAllowed = MODE_OUT.equals(mode) || MODE_INOUT.equals(mode);
251 }
252
253
254
255
256
257
258 public boolean isInputAllowed() {
259 return inputAllowed;
260 }
261
262
263
264
265
266
267 public boolean isOutputAllowed() {
268 return outputAllowed;
269 }
270
271
272
273
274
275
276 public String getTypeName() {
277 return typeName;
278 }
279
280
281
282
283
284
285
286 public void setTypeName(String typeName) {
287 this.typeName = typeName;
288 }
289
290
291
292
293
294
295 public String getResultMapName() {
296 return resultMapName;
297 }
298
299
300
301
302
303
304
305 public void setResultMapName(String resultMapName) {
306 this.resultMapName = resultMapName;
307 }
308
309
310
311
312
313
314 public Integer getNumericScale() {
315 return numericScale;
316 }
317
318
319
320
321
322
323
324 public void setNumericScale(Integer numericScale) {
325 if (numericScale != null && numericScale.intValue() < 0) {
326 throw new RuntimeException(
327 "Error setting numericScale on parameter mapping. Cause: scale must be greater than or equal to zero");
328 }
329 this.numericScale = numericScale;
330 }
331
332 }