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