1 /*
2 * Copyright 2004-2022 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.ibatis.sqlmap.engine.mapping.result;
17
18 import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
19 import com.ibatis.sqlmap.engine.type.TypeHandler;
20
21 /**
22 * Basic implementation of ResultMapping.
23 */
24 public class ResultMapping {
25
26 /** The property name. */
27 private String propertyName;
28
29 /** The column name. */
30 private String columnName;
31
32 /** The column index. */
33 private int columnIndex;
34
35 /** The type handler. */
36 private TypeHandler typeHandler;
37
38 /** The jdbc type. */
39 private int jdbcType;
40
41 /** The jdbc type name. */
42 private String jdbcTypeName;
43
44 /** The null value. */
45 private String nullValue;
46
47 /** The not null column. */
48 private String notNullColumn;
49
50 /** The statement name. */
51 private String statementName;
52
53 /** The java type. */
54 private Class javaType;
55
56 /** The nested result map name. */
57 private String nestedResultMapName;
58
59 /** The error string. */
60 private String errorString;
61
62 /**
63 * Gets the property name.
64 *
65 * @return the property name
66 */
67 public String getPropertyName() {
68 return propertyName;
69 }
70
71 /**
72 * Setter for the object property name (used by the automap, and the builder).
73 *
74 * @param propertyName
75 * - the property name
76 */
77 public void setPropertyName(String propertyName) {
78 this.errorString = "Check the result mapping for the '" + propertyName + "' property.";
79 this.propertyName = propertyName;
80 }
81
82 /**
83 * Getter for the error message when something goes wrong mapping this property.
84 *
85 * @return - the error message
86 */
87 public String getErrorString() {
88 return errorString;
89 }
90
91 /**
92 * Getter for the column name that we are mapping.
93 *
94 * @return - the column name
95 */
96 public String getColumnName() {
97 return columnName;
98 }
99
100 /**
101 * Setter for the column name we are mapping (used by the automap or builder).
102 *
103 * @param columnName
104 * - the column name
105 */
106 public void setColumnName(String columnName) {
107 this.columnName = columnName;
108 }
109
110 /**
111 * Getter for the column index that we are mapping.
112 *
113 * @return - the column index
114 */
115 public int getColumnIndex() {
116 return columnIndex;
117 }
118
119 /**
120 * Setter for the column index we are mapping (used by the automap or builder).
121 *
122 * @param columnIndex
123 * - the column index
124 */
125 public void setColumnIndex(int columnIndex) {
126 this.columnIndex = columnIndex;
127 }
128
129 /**
130 * Getter for the type handler for the column.
131 *
132 * @return - the type handler
133 */
134 public TypeHandler getTypeHandler() {
135 return typeHandler;
136 }
137
138 /**
139 * Setter for the type handler for the column.
140 *
141 * @param typeHandler
142 * - the type handler
143 */
144 public void setTypeHandler(TypeHandler typeHandler) {
145 this.typeHandler = typeHandler;
146 }
147
148 /**
149 * Setter for the Java type of the column.
150 *
151 * @return - the Java type
152 */
153 public Class getJavaType() {
154 return javaType;
155 }
156
157 /**
158 * Setter for the Java type of the column.
159 *
160 * @param javaType
161 * - the Java type
162 */
163 public void setJavaType(Class javaType) {
164 this.javaType = javaType;
165 }
166
167 /**
168 * Getter for the JDBC type of the column.
169 *
170 * @return - the JDBC type
171 */
172 public int getJdbcType() {
173 return jdbcType;
174 }
175
176 /**
177 * Getter for the JDBC type name of the column.
178 *
179 * @return - the JDBC type name
180 */
181 public String getJdbcTypeName() {
182 return jdbcTypeName;
183 }
184
185 /**
186 * Setter for the JDBC type name of the column.
187 *
188 * @param jdbcTypeName
189 * - the JDBC type name
190 */
191 public void setJdbcTypeName(String jdbcTypeName) {
192 this.jdbcTypeName = jdbcTypeName;
193 this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
194 }
195
196 /**
197 * Getter for what to return if the column is null.
198 *
199 * @return - the null substitution
200 */
201 public String getNullValue() {
202 return nullValue;
203 }
204
205 /**
206 * Setter for what to return if the column is null.
207 *
208 * @param nullValue
209 * - the null substitution
210 */
211 public void setNullValue(String nullValue) {
212 this.nullValue = nullValue;
213 }
214
215 /**
216 * Getter for the name of the column to check for null before instantiating a nested resultMapping value.
217 *
218 * @return - the null substitution
219 */
220 public String getNotNullColumn() {
221 return notNullColumn;
222 }
223
224 /**
225 * Setter for the name of the column to check for null before instantiating a nested resultMapping value.
226 *
227 * @param notNullColumn
228 * - the column name
229 */
230 public void setNotNullColumn(String notNullColumn) {
231 this.notNullColumn = notNullColumn;
232 }
233
234 /**
235 * Getter for the name of the statement.
236 *
237 * @return - the name
238 */
239 public String getStatementName() {
240 return statementName;
241 }
242
243 /**
244 * Setter for the name of the statement.
245 *
246 * @param statementName
247 * - the name
248 */
249 public void setStatementName(String statementName) {
250 this.statementName = statementName;
251 }
252
253 /**
254 * Gets the nested result map name.
255 *
256 * @return the nested result map name
257 */
258 public String getNestedResultMapName() {
259 return nestedResultMapName;
260 }
261
262 /**
263 * Sets the nested result map name.
264 *
265 * @param nestedResultMapName
266 * the new nested result map name
267 */
268 public void setNestedResultMapName(String nestedResultMapName) {
269 this.nestedResultMapName = nestedResultMapName;
270 }
271
272 }