1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.api;
17
18 import java.sql.Types;
19 import java.util.Properties;
20
21 import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
22 import org.mybatis.generator.config.Context;
23 import org.mybatis.generator.internal.util.StringUtility;
24
25
26
27
28
29
30 public class IntrospectedColumn {
31 protected String actualColumnName;
32
33 protected int jdbcType;
34
35
36
37
38 protected String actualTypeName;
39
40 protected String jdbcTypeName;
41
42 protected boolean nullable;
43
44 protected int length;
45
46 protected int scale;
47
48 protected boolean identity;
49
50 protected boolean isSequenceColumn;
51
52 protected String javaProperty;
53
54 protected FullyQualifiedJavaType fullyQualifiedJavaType;
55
56 protected String tableAlias;
57
58 protected String typeHandler;
59
60 protected Context context;
61
62 protected boolean isColumnNameDelimited;
63
64 protected IntrospectedTable introspectedTable;
65
66 protected final Properties properties;
67
68
69 protected String remarks;
70
71 protected String defaultValue;
72
73
74
75
76 protected boolean isAutoIncrement;
77
78
79
80
81 protected boolean isGeneratedColumn;
82
83
84
85
86 protected boolean isGeneratedAlways;
87
88
89
90
91
92 public IntrospectedColumn() {
93 super();
94 properties = new Properties();
95 }
96
97 public int getJdbcType() {
98 return jdbcType;
99 }
100
101 public void setJdbcType(int jdbcType) {
102 this.jdbcType = jdbcType;
103 }
104
105 public int getLength() {
106 return length;
107 }
108
109 public void setLength(int length) {
110 this.length = length;
111 }
112
113 public boolean isNullable() {
114 return nullable;
115 }
116
117 public void setNullable(boolean nullable) {
118 this.nullable = nullable;
119 }
120
121 public int getScale() {
122 return scale;
123 }
124
125 public void setScale(int scale) {
126 this.scale = scale;
127 }
128
129
130
131
132
133 @Override
134 public String toString() {
135 return "Actual Column Name: "
136 + actualColumnName
137 + ", JDBC Type: "
138 + jdbcType
139 + ", Nullable: "
140 + nullable
141 + ", Length: "
142 + length
143 + ", Scale: "
144 + scale
145 + ", Identity: "
146 + identity;
147 }
148
149 public void setActualColumnName(String actualColumnName) {
150 this.actualColumnName = actualColumnName;
151 isColumnNameDelimited = StringUtility
152 .stringContainsSpace(actualColumnName);
153 }
154
155 public boolean isIdentity() {
156 return identity;
157 }
158
159 public void setIdentity(boolean identity) {
160 this.identity = identity;
161 }
162
163 public boolean isBLOBColumn() {
164 String typeName = getJdbcTypeName();
165
166 return "BINARY".equals(typeName) || "BLOB".equals(typeName)
167 || "CLOB".equals(typeName) || "LONGNVARCHAR".equals(typeName)
168 || "LONGVARBINARY".equals(typeName) || "LONGVARCHAR".equals(typeName)
169 || "NCLOB".equals(typeName) || "VARBINARY".equals(typeName);
170 }
171
172 public boolean isStringColumn() {
173 return fullyQualifiedJavaType.equals(FullyQualifiedJavaType
174 .getStringInstance());
175 }
176
177 public boolean isJdbcCharacterColumn() {
178 return jdbcType == Types.CHAR || jdbcType == Types.CLOB
179 || jdbcType == Types.LONGVARCHAR || jdbcType == Types.VARCHAR
180 || jdbcType == Types.LONGNVARCHAR || jdbcType == Types.NCHAR
181 || jdbcType == Types.NCLOB || jdbcType == Types.NVARCHAR;
182 }
183
184 public String getJavaProperty() {
185 return getJavaProperty(null);
186 }
187
188 public String getJavaProperty(String prefix) {
189 if (prefix == null) {
190 return javaProperty;
191 }
192
193 return prefix + javaProperty;
194 }
195
196 public void setJavaProperty(String javaProperty) {
197 this.javaProperty = javaProperty;
198 }
199
200 public boolean isJDBCDateColumn() {
201 return fullyQualifiedJavaType.equals(FullyQualifiedJavaType
202 .getDateInstance())
203 && "DATE".equalsIgnoreCase(jdbcTypeName);
204 }
205
206 public boolean isJDBCTimeColumn() {
207 return fullyQualifiedJavaType.equals(FullyQualifiedJavaType
208 .getDateInstance())
209 && "TIME".equalsIgnoreCase(jdbcTypeName);
210 }
211
212 public String getTypeHandler() {
213 return typeHandler;
214 }
215
216 public void setTypeHandler(String typeHandler) {
217 this.typeHandler = typeHandler;
218 }
219
220 public String getActualColumnName() {
221 return actualColumnName;
222 }
223
224 public void setColumnNameDelimited(boolean isColumnNameDelimited) {
225 this.isColumnNameDelimited = isColumnNameDelimited;
226 }
227
228 public boolean isColumnNameDelimited() {
229 return isColumnNameDelimited;
230 }
231
232 public String getJdbcTypeName() {
233 if (jdbcTypeName == null) {
234 return "OTHER";
235 }
236
237 return jdbcTypeName;
238 }
239
240 public void setJdbcTypeName(String jdbcTypeName) {
241 this.jdbcTypeName = jdbcTypeName;
242 }
243
244 public FullyQualifiedJavaType getFullyQualifiedJavaType() {
245 return fullyQualifiedJavaType;
246 }
247
248 public void setFullyQualifiedJavaType(
249 FullyQualifiedJavaType fullyQualifiedJavaType) {
250 this.fullyQualifiedJavaType = fullyQualifiedJavaType;
251 }
252
253 public String getTableAlias() {
254 return tableAlias;
255 }
256
257 public void setTableAlias(String tableAlias) {
258 this.tableAlias = tableAlias;
259 }
260
261 public Context getContext() {
262 return context;
263 }
264
265 public void setContext(Context context) {
266 this.context = context;
267 }
268
269 public IntrospectedTable getIntrospectedTable() {
270 return introspectedTable;
271 }
272
273 public void setIntrospectedTable(IntrospectedTable introspectedTable) {
274 this.introspectedTable = introspectedTable;
275 }
276
277 public Properties getProperties() {
278 return properties;
279 }
280
281 public void setProperties(Properties properties) {
282 this.properties.putAll(properties);
283 }
284
285 public String getRemarks() {
286 return remarks;
287 }
288
289 public void setRemarks(String remarks) {
290 this.remarks = remarks;
291 }
292
293 public String getDefaultValue() {
294 return defaultValue;
295 }
296
297 public void setDefaultValue(String defaultValue) {
298 this.defaultValue = defaultValue;
299 }
300
301 public boolean isSequenceColumn() {
302 return isSequenceColumn;
303 }
304
305 public void setSequenceColumn(boolean isSequenceColumn) {
306 this.isSequenceColumn = isSequenceColumn;
307 }
308
309 public boolean isAutoIncrement() {
310 return isAutoIncrement;
311 }
312
313 public void setAutoIncrement(boolean isAutoIncrement) {
314 this.isAutoIncrement = isAutoIncrement;
315 }
316
317 public boolean isGeneratedColumn() {
318 return isGeneratedColumn;
319 }
320
321 public void setGeneratedColumn(boolean isGeneratedColumn) {
322 this.isGeneratedColumn = isGeneratedColumn;
323 }
324
325 public boolean isGeneratedAlways() {
326 return isGeneratedAlways;
327 }
328
329 public void setGeneratedAlways(boolean isGeneratedAlways) {
330 this.isGeneratedAlways = isGeneratedAlways;
331 }
332
333
334
335
336
337
338
339
340 public String getActualTypeName() {
341 return actualTypeName;
342 }
343
344 public void setActualTypeName(String actualTypeName) {
345 this.actualTypeName = actualTypeName;
346 }
347 }