1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.codegen.ibatis2.dao.elements;
17
18 import java.util.Set;
19 import java.util.TreeSet;
20
21 import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
22 import org.mybatis.generator.api.dom.java.Interface;
23 import org.mybatis.generator.api.dom.java.JavaVisibility;
24 import org.mybatis.generator.api.dom.java.Method;
25 import org.mybatis.generator.api.dom.java.Parameter;
26 import org.mybatis.generator.api.dom.java.TopLevelClass;
27
28
29
30
31
32
33 public class UpdateByExampleWithBLOBsMethodGenerator extends
34 AbstractDAOElementGenerator {
35
36 public UpdateByExampleWithBLOBsMethodGenerator() {
37 super();
38 }
39
40 @Override
41 public void addImplementationElements(TopLevelClass topLevelClass) {
42 Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
43 Method method = getMethodShell(importedTypes);
44
45 method
46 .addBodyLine("UpdateByExampleParms parms = new UpdateByExampleParms(record, example);");
47
48 StringBuilder sb = new StringBuilder();
49 sb.append("int rows = ");
50 sb.append(daoTemplate.getUpdateMethod(introspectedTable
51 .getIbatis2SqlMapNamespace(), introspectedTable
52 .getUpdateByExampleWithBLOBsStatementId(), "parms"));
53 method.addBodyLine(sb.toString());
54
55 method.addBodyLine("return rows;");
56
57 if (context.getPlugins()
58 .clientUpdateByExampleWithBLOBsMethodGenerated(method,
59 topLevelClass, introspectedTable)) {
60 topLevelClass.addImportedTypes(importedTypes);
61 topLevelClass.addMethod(method);
62 }
63 }
64
65 @Override
66 public void addInterfaceElements(Interface interfaze) {
67 if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
68 Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
69 Method method = getMethodShell(importedTypes);
70
71 if (context.getPlugins()
72 .clientUpdateByExampleWithBLOBsMethodGenerated(method,
73 interfaze, introspectedTable)) {
74 interfaze.addImportedTypes(importedTypes);
75 interfaze.addMethod(method);
76 }
77 }
78 }
79
80 private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
81 FullyQualifiedJavaType parameterType;
82 if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
83 parameterType = new FullyQualifiedJavaType(introspectedTable
84 .getRecordWithBLOBsType());
85 } else {
86 parameterType = new FullyQualifiedJavaType(introspectedTable
87 .getBaseRecordType());
88 }
89
90 importedTypes.add(parameterType);
91
92 Method method = new Method();
93 method.setVisibility(getExampleMethodVisibility());
94 method.setReturnType(FullyQualifiedJavaType.getIntInstance());
95 method.setName(getDAOMethodNameCalculator()
96 .getUpdateByExampleWithBLOBsMethodName(introspectedTable));
97 method.addParameter(new Parameter(parameterType, "record"));
98 method.addParameter(new Parameter(new FullyQualifiedJavaType(
99 introspectedTable.getExampleType()), "example"));
100
101 for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
102 method.addException(fqjt);
103 importedTypes.add(fqjt);
104 }
105
106 context.getCommentGenerator().addGeneralMethodComment(method,
107 introspectedTable);
108
109 return method;
110 }
111 }