1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.codegen.mybatis3.xmlmapper.elements;
17
18 import org.mybatis.generator.api.IntrospectedColumn;
19 import org.mybatis.generator.api.dom.xml.Attribute;
20 import org.mybatis.generator.api.dom.xml.TextElement;
21 import org.mybatis.generator.api.dom.xml.XmlElement;
22 import org.mybatis.generator.codegen.AbstractGenerator;
23 import org.mybatis.generator.config.GeneratedKey;
24
25
26
27
28
29
30 public abstract class AbstractXmlElementGenerator extends AbstractGenerator {
31 public abstract void addElements(XmlElement parentElement);
32
33 public AbstractXmlElementGenerator() {
34 super();
35 }
36
37
38
39
40
41
42
43
44
45
46
47 protected XmlElement getSelectKey(IntrospectedColumn introspectedColumn,
48 GeneratedKey generatedKey) {
49 String identityColumnType = introspectedColumn
50 .getFullyQualifiedJavaType().getFullyQualifiedName();
51
52 XmlElement answer = new XmlElement("selectKey");
53 answer.addAttribute(new Attribute("resultType", identityColumnType));
54 answer.addAttribute(new Attribute(
55 "keyProperty", introspectedColumn.getJavaProperty()));
56 answer.addAttribute(new Attribute("order",
57 generatedKey.getMyBatis3Order()));
58
59 answer.addElement(new TextElement(generatedKey
60 .getRuntimeSqlStatement()));
61
62 return answer;
63 }
64
65 protected XmlElement getBaseColumnListElement() {
66 XmlElement answer = new XmlElement("include");
67 answer.addAttribute(new Attribute("refid",
68 introspectedTable.getBaseColumnListId()));
69 return answer;
70 }
71
72 protected XmlElement getBlobColumnListElement() {
73 XmlElement answer = new XmlElement("include");
74 answer.addAttribute(new Attribute("refid",
75 introspectedTable.getBlobColumnListId()));
76 return answer;
77 }
78
79 protected XmlElement getExampleIncludeElement() {
80 XmlElement ifElement = new XmlElement("if");
81 ifElement.addAttribute(new Attribute("test", "_parameter != null"));
82
83 XmlElement includeElement = new XmlElement("include");
84 includeElement.addAttribute(new Attribute("refid",
85 introspectedTable.getExampleWhereClauseId()));
86 ifElement.addElement(includeElement);
87
88 return ifElement;
89 }
90
91 protected XmlElement getUpdateByExampleIncludeElement() {
92 XmlElement ifElement = new XmlElement("if");
93 ifElement.addAttribute(new Attribute("test", "_parameter != null"));
94
95 XmlElement includeElement = new XmlElement("include");
96 includeElement.addAttribute(new Attribute("refid",
97 introspectedTable.getMyBatis3UpdateByExampleWhereClauseId()));
98 ifElement.addElement(includeElement);
99
100 return ifElement;
101 }
102 }