1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.codegen.ibatis2.sqlmap.elements;
17
18 import static org.mybatis.generator.internal.util.StringUtility.isTrue;
19 import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
20
21 import org.mybatis.generator.api.IntrospectedColumn;
22 import org.mybatis.generator.api.dom.xml.Attribute;
23 import org.mybatis.generator.api.dom.xml.XmlElement;
24 import org.mybatis.generator.codegen.ibatis2.Ibatis2FormattingUtilities;
25 import org.mybatis.generator.config.PropertyRegistry;
26
27
28
29
30
31
32 public class ResultMapWithoutBLOBsElementGenerator extends
33 AbstractXmlElementGenerator {
34
35 public ResultMapWithoutBLOBsElementGenerator() {
36 super();
37 }
38
39 @Override
40 public void addElements(XmlElement parentElement) {
41 boolean useColumnIndex = isTrue(introspectedTable
42 .getTableConfigurationProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES));
43 XmlElement answer = new XmlElement("resultMap");
44 answer.addAttribute(new Attribute("id",
45 introspectedTable.getBaseResultMapId()));
46
47 String returnType;
48 if (introspectedTable.getRules().generateBaseRecordClass()) {
49 returnType = introspectedTable.getBaseRecordType();
50 } else {
51 returnType = introspectedTable.getPrimaryKeyType();
52 }
53
54 answer.addAttribute(new Attribute("class",
55 returnType));
56
57 context.getCommentGenerator().addComment(answer);
58
59 int i = 1;
60 if (stringHasValue(introspectedTable
61 .getSelectByPrimaryKeyQueryId())
62 || stringHasValue(introspectedTable
63 .getSelectByExampleQueryId())) {
64 i++;
65 }
66
67 for (IntrospectedColumn introspectedColumn : introspectedTable
68 .getNonBLOBColumns()) {
69 XmlElement resultElement = new XmlElement("result");
70
71 if (useColumnIndex) {
72 resultElement.addAttribute(new Attribute(
73 "columnIndex", Integer.toString(i++)));
74 } else {
75 resultElement
76 .addAttribute(new Attribute(
77 "column", Ibatis2FormattingUtilities.getRenamedColumnNameForResultMap(introspectedColumn)));
78 }
79
80 resultElement.addAttribute(new Attribute(
81 "property", introspectedColumn.getJavaProperty()));
82 resultElement.addAttribute(new Attribute("jdbcType",
83 introspectedColumn.getJdbcTypeName()));
84
85 if (stringHasValue(introspectedColumn
86 .getTypeHandler())) {
87 resultElement.addAttribute(new Attribute(
88 "typeHandler", introspectedColumn.getTypeHandler()));
89 }
90
91 answer.addElement(resultElement);
92 }
93
94 if (context.getPlugins()
95 .sqlMapResultMapWithoutBLOBsElementGenerated(answer,
96 introspectedTable)) {
97 parentElement.addElement(answer);
98 }
99 }
100 }