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 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.ibatis2.Ibatis2FormattingUtilities;
26
27
28
29
30
31
32 public class UpdateByPrimaryKeyWithoutBLOBsElementGenerator extends
33 AbstractXmlElementGenerator {
34
35 public UpdateByPrimaryKeyWithoutBLOBsElementGenerator() {
36 super();
37 }
38
39 @Override
40 public void addElements(XmlElement parentElement) {
41 XmlElement answer = new XmlElement("update");
42
43 answer.addAttribute(new Attribute(
44 "id", introspectedTable.getUpdateByPrimaryKeyStatementId()));
45 answer.addAttribute(new Attribute("parameterClass",
46 introspectedTable.getBaseRecordType()));
47
48 context.getCommentGenerator().addComment(answer);
49
50 StringBuilder sb = new StringBuilder();
51 sb.append("update ");
52 sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
53 answer.addElement(new TextElement(sb.toString()));
54
55
56 sb.setLength(0);
57 sb.append("set ");
58
59 Iterator<IntrospectedColumn> iter = introspectedTable.getBaseColumns()
60 .iterator();
61 while (iter.hasNext()) {
62 IntrospectedColumn introspectedColumn = iter.next();
63
64 sb.append(Ibatis2FormattingUtilities
65 .getEscapedColumnName(introspectedColumn));
66 sb.append(" = ");
67 sb.append(Ibatis2FormattingUtilities
68 .getParameterClause(introspectedColumn));
69
70 if (iter.hasNext()) {
71 sb.append(',');
72 }
73
74 answer.addElement(new TextElement(sb.toString()));
75
76
77 if (iter.hasNext()) {
78 sb.setLength(0);
79 OutputUtilities.xmlIndent(sb, 1);
80 }
81 }
82
83 boolean and = false;
84 for (IntrospectedColumn introspectedColumn : introspectedTable
85 .getPrimaryKeyColumns()) {
86 sb.setLength(0);
87 if (and) {
88 sb.append(" and ");
89 } else {
90 sb.append("where ");
91 and = true;
92 }
93
94 sb.append(Ibatis2FormattingUtilities
95 .getEscapedColumnName(introspectedColumn));
96 sb.append(" = ");
97 sb.append(Ibatis2FormattingUtilities
98 .getParameterClause(introspectedColumn));
99 answer.addElement(new TextElement(sb.toString()));
100 }
101
102 if (context.getPlugins()
103 .sqlMapUpdateByPrimaryKeyWithoutBLOBsElementGenerated(answer,
104 introspectedTable)) {
105 parentElement.addElement(answer);
106 }
107 }
108 }