1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.runtime.dynamic.sql.elements;
17
18 import org.mybatis.generator.api.IntrospectedColumn;
19 import org.mybatis.generator.api.IntrospectedTable;
20 import org.mybatis.generator.api.dom.java.Interface;
21 import org.mybatis.generator.api.dom.java.Method;
22 import org.mybatis.generator.api.dom.java.Parameter;
23 import org.mybatis.generator.config.Context;
24
25 public abstract class AbstractMethodGenerator {
26 protected final Context context;
27 protected final IntrospectedTable introspectedTable;
28 protected final String tableFieldName;
29
30 protected AbstractMethodGenerator(BaseBuilder<?> builder) {
31 context = builder.context;
32 introspectedTable = builder.introspectedTable;
33 tableFieldName = builder.tableFieldName;
34 }
35
36 protected String calculateFieldName(IntrospectedColumn column) {
37 return calculateFieldName(tableFieldName, column);
38 }
39
40 public static String calculateFieldName(String tableFieldName, IntrospectedColumn column) {
41 String fieldName = column.getJavaProperty();
42 if (fieldName.equals(tableFieldName)) {
43
44 fieldName = tableFieldName + "." + fieldName;
45 }
46 return fieldName;
47 }
48
49 protected void acceptParts(MethodAndImports.Builder builder, Method method, MethodParts methodParts) {
50 for (Parameter parameter : methodParts.getParameters()) {
51 method.addParameter(parameter);
52 }
53
54 for (String annotation : methodParts.getAnnotations()) {
55 method.addAnnotation(annotation);
56 }
57
58 method.addBodyLines(methodParts.getBodyLines());
59 builder.withImports(methodParts.getImports());
60 }
61
62 public abstract MethodAndImports generateMethodAndImports();
63
64 public abstract boolean callPlugins(Method method, Interface interfaze);
65
66 public abstract static class BaseBuilder<T extends BaseBuilder<T>> {
67 private Context context;
68 private IntrospectedTable introspectedTable;
69 private String tableFieldName;
70
71 public T withContext(Context context) {
72 this.context = context;
73 return getThis();
74 }
75
76 public T withIntrospectedTable(IntrospectedTable introspectedTable) {
77 this.introspectedTable = introspectedTable;
78 return getThis();
79 }
80
81 public T withTableFieldName(String tableFieldName) {
82 this.tableFieldName = tableFieldName;
83 return getThis();
84 }
85
86 public abstract T getThis();
87 }
88 }