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 SelectByExampleWithBLOBsElementGenerator extends
30 AbstractXmlElementGenerator {
31
32 public SelectByExampleWithBLOBsElementGenerator() {
33 super();
34 }
35
36 @Override
37 public void addElements(XmlElement parentElement) {
38 XmlElement answer = new XmlElement("select");
39 answer
40 .addAttribute(new Attribute(
41 "id", introspectedTable.getSelectByExampleWithBLOBsStatementId()));
42 answer.addAttribute(new Attribute(
43 "resultMap", introspectedTable.getResultMapWithBLOBsId()));
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 answer.addElement(new TextElement(","));
69 answer.addElement(getBlobColumnListElement());
70
71 sb.setLength(0);
72 sb.append("from ");
73 sb.append(introspectedTable
74 .getAliasedFullyQualifiedTableNameAtRuntime());
75 answer.addElement(new TextElement(sb.toString()));
76
77 XmlElement isParameterPresenteElement = new XmlElement(
78 "isParameterPresent");
79 answer.addElement(isParameterPresenteElement);
80
81 XmlElement includeElement = new XmlElement("include");
82 includeElement.addAttribute(new Attribute("refid",
83 introspectedTable.getIbatis2SqlMapNamespace()
84 + "." + introspectedTable.getExampleWhereClauseId()));
85 isParameterPresenteElement.addElement(includeElement);
86
87 XmlElement isNotNullElement = new XmlElement("isNotNull");
88 isNotNullElement
89 .addAttribute(new Attribute("property", "orderByClause"));
90 isNotNullElement
91 .addElement(new TextElement("order by $orderByClause$"));
92 isParameterPresenteElement.addElement(isNotNullElement);
93
94 if (context.getPlugins()
95 .sqlMapSelectByExampleWithBLOBsElementGenerated(answer,
96 introspectedTable)) {
97 parentElement.addElement(answer);
98 }
99 }
100 }