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.stringHasValue;
19
20 import org.mybatis.generator.api.dom.xml.Attribute;
21 import org.mybatis.generator.api.dom.xml.TextElement;
22 import org.mybatis.generator.api.dom.xml.XmlElement;
23
24
25
26
27
28
29 public class SelectByExampleWithoutBLOBsElementGenerator extends
30 AbstractXmlElementGenerator {
31
32 public SelectByExampleWithoutBLOBsElementGenerator() {
33 super();
34 }
35
36 @Override
37 public void addElements(XmlElement parentElement) {
38 XmlElement answer = new XmlElement("select");
39
40 answer.addAttribute(new Attribute("id",
41 introspectedTable.getSelectByExampleStatementId()));
42 answer.addAttribute(new Attribute(
43 "resultMap", introspectedTable.getBaseResultMapId()));
44 answer.addAttribute(new Attribute(
45 "parameterClass", introspectedTable.getExampleType()));
46
47 context.getCommentGenerator().addComment(answer);
48
49 answer.addElement(new TextElement("select"));
50 XmlElement isParameterPresent = new XmlElement("isParameterPresent");
51 XmlElement isEqualElement = new XmlElement("isEqual");
52 isEqualElement.addAttribute(new Attribute("property", "distinct"));
53 isEqualElement.addAttribute(new Attribute("compareValue", "true"));
54 isEqualElement.addElement(new TextElement("distinct"));
55 isParameterPresent.addElement(isEqualElement);
56 answer.addElement(isParameterPresent);
57
58 StringBuilder sb = new StringBuilder();
59 if (stringHasValue(introspectedTable
60 .getSelectByExampleQueryId())) {
61 sb.append('\'');
62 sb.append(introspectedTable.getSelectByExampleQueryId());
63 sb.append("' as QUERYID,");
64 answer.addElement(new TextElement(sb.toString()));
65 }
66
67 answer.addElement(getBaseColumnListElement());
68
69 sb.setLength(0);
70 sb.append("from ");
71 sb.append(introspectedTable
72 .getAliasedFullyQualifiedTableNameAtRuntime());
73 answer.addElement(new TextElement(sb.toString()));
74
75 XmlElement isParameterPresenteElement = new XmlElement(
76 "isParameterPresent");
77 answer.addElement(isParameterPresenteElement);
78
79 XmlElement includeElement = new XmlElement("include");
80 includeElement.addAttribute(new Attribute("refid",
81 introspectedTable.getIbatis2SqlMapNamespace()
82 + "." + introspectedTable.getExampleWhereClauseId()));
83 isParameterPresenteElement.addElement(includeElement);
84
85 XmlElement isNotNullElement = new XmlElement("isNotNull");
86 isNotNullElement
87 .addAttribute(new Attribute("property", "orderByClause"));
88 isNotNullElement
89 .addElement(new TextElement("order by $orderByClause$"));
90 isParameterPresenteElement.addElement(isNotNullElement);
91
92 if (context.getPlugins()
93 .sqlMapSelectByExampleWithoutBLOBsElementGenerated(answer,
94 introspectedTable)) {
95 parentElement.addElement(answer);
96 }
97 }
98 }