View Javadoc
1   /*
2    *    Copyright 2006-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (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
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.codegen.mybatis3.javamapper;
17  
18  import org.mybatis.generator.api.dom.java.Interface;
19  import org.mybatis.generator.codegen.AbstractXmlGenerator;
20  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.AbstractJavaMapperMethodGenerator;
21  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated.AnnotatedDeleteByPrimaryKeyMethodGenerator;
22  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated.AnnotatedInsertMethodGenerator;
23  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated.AnnotatedSelectByPrimaryKeyMethodGenerator;
24  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated.AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator;
25  import org.mybatis.generator.codegen.mybatis3.javamapper.elements.annotated.AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator;
26  import org.mybatis.generator.codegen.mybatis3.xmlmapper.MixedMapperGenerator;
27  
28  /**
29   * This class overrides the base mapper to provide annotated methods for the
30   * methods that don't require SQL provider support.
31   *
32   * @author Jeff Butler
33   */
34  public class MixedClientGenerator extends JavaMapperGenerator {
35  
36      public MixedClientGenerator(String project) {
37          super(project, true);
38      }
39  
40      @Override
41      protected void addDeleteByPrimaryKeyMethod(Interface interfaze) {
42          if (introspectedTable.getRules().generateDeleteByPrimaryKey()) {
43              AbstractJavaMapperMethodGenerator methodGenerator = new AnnotatedDeleteByPrimaryKeyMethodGenerator(false);
44              initializeAndExecuteGenerator(methodGenerator, interfaze);
45          }
46      }
47  
48      @Override
49      protected void addInsertMethod(Interface interfaze) {
50          if (introspectedTable.getRules().generateInsert()) {
51              AbstractJavaMapperMethodGenerator methodGenerator = new AnnotatedInsertMethodGenerator(false);
52              initializeAndExecuteGenerator(methodGenerator, interfaze);
53          }
54      }
55  
56      @Override
57      protected void addSelectByPrimaryKeyMethod(Interface interfaze) {
58          if (introspectedTable.getRules().generateSelectByPrimaryKey()) {
59              AbstractJavaMapperMethodGenerator methodGenerator =
60                      new AnnotatedSelectByPrimaryKeyMethodGenerator(true, false);
61              initializeAndExecuteGenerator(methodGenerator, interfaze);
62          }
63      }
64  
65      @Override
66      protected void addUpdateByPrimaryKeyWithBLOBsMethod(Interface interfaze) {
67          if (introspectedTable.getRules().generateUpdateByPrimaryKeyWithBLOBs()) {
68              AbstractJavaMapperMethodGenerator methodGenerator =
69                      new AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator();
70              initializeAndExecuteGenerator(methodGenerator, interfaze);
71          }
72      }
73  
74      @Override
75      protected void addUpdateByPrimaryKeyWithoutBLOBsMethod(Interface interfaze) {
76          if (introspectedTable.getRules().generateUpdateByPrimaryKeyWithoutBLOBs()) {
77              AbstractJavaMapperMethodGenerator methodGenerator =
78                      new AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator(false);
79              initializeAndExecuteGenerator(methodGenerator, interfaze);
80          }
81      }
82  
83      @Override
84      public AbstractXmlGenerator getMatchedXMLGenerator() {
85          return new MixedMapperGenerator();
86      }
87  }