My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes  
Changes to /sub-projects/generator/trunk/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java
r3543 vs. r5433 Compare: vs.  Format:
Revision r5433
Go to: 
/sub-projects/generator/trunk/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java   r3543 /sub-projects/generator/trunk/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/mybatis3/javamapper/elements/sqlprovider/ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java   r5433
1 /* 1 /*
2 * Copyright 2010 The MyBatis Team 2 * Copyright 2010 The MyBatis Team
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider; 16 package org.mybatis.generator.codegen.mybatis3.javamapper.elements.sqlprovider;
17 17
18 import static org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities.getAliasedEscapedColumnName; 18 import static org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities.getAliasedEscapedColumnName;
19 import static org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities.getParameterClause; 19 import static org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities.getParameterClause;
20 import static org.mybatis.generator.internal.util.StringUtility.escapeStringForJava; 20 import static org.mybatis.generator.internal.util.StringUtility.escapeStringForJava;
21 21
22 import java.util.List; 22 import java.util.List;
23 import java.util.Set; 23 import java.util.Set;
24 import java.util.TreeSet; 24 import java.util.TreeSet;
25 25
26 import org.mybatis.generator.api.IntrospectedColumn; 26 import org.mybatis.generator.api.IntrospectedColumn;
27 import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 27 import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
28 import org.mybatis.generator.api.dom.java.JavaVisibility; 28 import org.mybatis.generator.api.dom.java.JavaVisibility;
29 import org.mybatis.generator.api.dom.java.Method; 29 import org.mybatis.generator.api.dom.java.Method;
30 import org.mybatis.generator.api.dom.java.Parameter; 30 import org.mybatis.generator.api.dom.java.Parameter;
31 import org.mybatis.generator.api.dom.java.TopLevelClass; 31 import org.mybatis.generator.api.dom.java.TopLevelClass;
32 32
33 /** 33 /**
34 * 34 *
35 * @author Jeff Butler 35 * @author Jeff Butler
36 * 36 *
37 */ 37 */
38 public class ProviderUpdateByExampleWithoutBLOBsMethodGenerator extends 38 public class ProviderUpdateByExampleWithoutBLOBsMethodGenerator extends
39 AbstractJavaProviderMethodGenerator { 39 AbstractJavaProviderMethodGenerator {
40 40
41 public ProviderUpdateByExampleWithoutBLOBsMethodGenerator() { 41 public ProviderUpdateByExampleWithoutBLOBsMethodGenerator(boolean useLegacyBuilder) {
42 super(); 42 super(useLegacyBuilder);
43 } 43 }
44 44
45 @Override 45 @Override
46 public void addClassElements(TopLevelClass topLevelClass) { 46 public void addClassElements(TopLevelClass topLevelClass) {
47 Set<String> staticImports = new TreeSet<String>(); 47 Set<String> staticImports = new TreeSet<String>();
48 Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); 48 Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
49 49
50 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$ 50 if (useLegacyBuilder) {
51 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); //$NON-NLS-1$ 51 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$
52 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); //$NON-NLS-1$ 52 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); //$NON-NLS-1$
53 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$ 53 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); //$NON-NLS-1$
54 staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$
55 } else {
56 importedTypes.add(NEW_BUILDER_IMPORT);
57 }
54 58
55 importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$ 59 importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$
56 60
57 Method method = new Method(getMethodName()); 61 Method method = new Method(getMethodName());
58 method.setReturnType(FullyQualifiedJavaType.getStringInstance()); 62 method.setReturnType(FullyQualifiedJavaType.getStringInstance());
59 method.setVisibility(JavaVisibility.PUBLIC); 63 method.setVisibility(JavaVisibility.PUBLIC);
60 method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$ 64 method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$
61 "parameter")); //$NON-NLS-1$ 65 "parameter")); //$NON-NLS-1$
62 66
63 context.getCommentGenerator().addGeneralMethodComment(method, 67 context.getCommentGenerator().addGeneralMethodComment(method,
64 introspectedTable); 68 introspectedTable);
65 69
66 method.addBodyLine("BEGIN();"); //$NON-NLS-1$ 70 if (useLegacyBuilder) {
71 method.addBodyLine("BEGIN();"); //$NON-NLS-1$
72 } else {
73 method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$
74 }
67 75
68 method.addBodyLine(String.format("UPDATE(\"%s\");", //$NON-NLS-1$ 76 method.addBodyLine(String.format("%sUPDATE(\"%s\");", //$NON-NLS-1$
69 escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()))); 77 builderPrefix,
78 escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())));
70 method.addBodyLine(""); //$NON-NLS-1$ 79 method.addBodyLine(""); //$NON-NLS-1$
71 80
72 for (IntrospectedColumn introspectedColumn : getColumns()) { 81 for (IntrospectedColumn introspectedColumn : getColumns()) {
73 StringBuilder sb = new StringBuilder(); 82 StringBuilder sb = new StringBuilder();
74 sb.append(getParameterClause(introspectedColumn)); 83 sb.append(getParameterClause(introspectedColumn));
75 sb.insert(2, "record."); //$NON-NLS-1$ 84 sb.insert(2, "record."); //$NON-NLS-1$
76 85
77 method.addBodyLine(String.format("SET(\"%s = %s\");", //$NON-NLS-1$ 86 method.addBodyLine(String.format("%sSET(\"%s = %s\");", //$NON-NLS-1$
78 escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)), 87 builderPrefix,
88 escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)),
79 sb.toString())); 89 sb.toString()));
80 } 90 }
81 91
82 method.addBodyLine(""); //$NON-NLS-1$ 92 method.addBodyLine(""); //$NON-NLS-1$
83 93
84 FullyQualifiedJavaType example = 94 FullyQualifiedJavaType example =
85 new FullyQualifiedJavaType(introspectedTable.getExampleType()); 95 new FullyQualifiedJavaType(introspectedTable.getExampleType());
86 importedTypes.add(example); 96 importedTypes.add(example);
87 method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$ 97 method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$
88 example.getShortName(), example.getShortName())); 98 example.getShortName(), example.getShortName()));
89 99
90 method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$ 100 if (useLegacyBuilder) {
91 method.addBodyLine("return SQL();"); //$NON-NLS-1$ 101 method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$
102 method.addBodyLine("return SQL();"); //$NON-NLS-1$
103 } else {
104 method.addBodyLine("applyWhere(sql, example, true);"); //$NON-NLS-1$
105 method.addBodyLine("return sql.toString();"); //$NON-NLS-1$
106 }
92 107
93 if (callPlugins(method, topLevelClass)) { 108 if (callPlugins(method, topLevelClass)) {
94 topLevelClass.addStaticImports(staticImports); 109 topLevelClass.addStaticImports(staticImports);
95 topLevelClass.addImportedTypes(importedTypes); 110 topLevelClass.addImportedTypes(importedTypes);
96 topLevelClass.addMethod(method); 111 topLevelClass.addMethod(method);
97 } 112 }
98 } 113 }
99 114
100 public String getMethodName() { 115 public String getMethodName() {
101 return introspectedTable.getUpdateByExampleStatementId(); 116 return introspectedTable.getUpdateByExampleStatementId();
102 } 117 }
103 118
104 public List<IntrospectedColumn> getColumns() { 119 public List<IntrospectedColumn> getColumns() {
105 return introspectedTable.getNonBLOBColumns(); 120 return introspectedTable.getNonBLOBColumns();
106 } 121 }
107 122
108 public boolean callPlugins(Method method, TopLevelClass topLevelClass) { 123 public boolean callPlugins(Method method, TopLevelClass topLevelClass) {
109 return context.getPlugins().providerUpdateByExampleWithoutBLOBsMethodGenerated(method, topLevelClass, 124 return context.getPlugins().providerUpdateByExampleWithoutBLOBsMethodGenerated(method, topLevelClass,
110 introspectedTable); 125 introspectedTable);
111 } 126 }
112 } 127 }
Powered by Google Project Hosting