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 java.util.Iterator;
19
20 import org.mybatis.generator.api.IntrospectedColumn;
21 import org.mybatis.generator.api.dom.OutputUtilities;
22 import org.mybatis.generator.api.dom.xml.Attribute;
23 import org.mybatis.generator.api.dom.xml.TextElement;
24 import org.mybatis.generator.api.dom.xml.XmlElement;
25 import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
26
27
28
29
30
31
32 public class UpdateByExampleWithoutBLOBsElementGenerator extends
33 AbstractXmlElementGenerator {
34
35 public UpdateByExampleWithoutBLOBsElementGenerator() {
36 super();
37 }
38
39 @Override
40 public void addElements(XmlElement parentElement) {
41 XmlElement answer = new XmlElement("update");
42
43 answer.addAttribute(new Attribute("id",
44 introspectedTable.getUpdateByExampleStatementId()));
45
46 answer.addAttribute(new Attribute("parameterType", "map"));
47
48 context.getCommentGenerator().addComment(answer);
49
50 StringBuilder sb = new StringBuilder();
51 sb.append("update ");
52 sb.append(introspectedTable
53 .getAliasedFullyQualifiedTableNameAtRuntime());
54 answer.addElement(new TextElement(sb.toString()));
55
56
57 sb.setLength(0);
58 sb.append("set ");
59
60 Iterator<IntrospectedColumn> iter = introspectedTable
61 .getNonBLOBColumns().iterator();
62 while (iter.hasNext()) {
63 IntrospectedColumn introspectedColumn = iter.next();
64
65 sb.append(MyBatis3FormattingUtilities
66 .getAliasedEscapedColumnName(introspectedColumn));
67 sb.append(" = ");
68 sb.append(MyBatis3FormattingUtilities.getParameterClause(
69 introspectedColumn, "record."));
70
71 if (iter.hasNext()) {
72 sb.append(',');
73 }
74
75 answer.addElement(new TextElement(sb.toString()));
76
77
78 if (iter.hasNext()) {
79 sb.setLength(0);
80 OutputUtilities.xmlIndent(sb, 1);
81 }
82 }
83
84 answer.addElement(getUpdateByExampleIncludeElement());
85
86 if (context.getPlugins()
87 .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
88 introspectedTable)) {
89 parentElement.addElement(answer);
90 }
91 }
92 }