View Javadoc
1   /**
2    *    Copyright 2006-2016 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    *       http://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
30   * for the methods that don't require SQL provider support
31   * 
32   * @author Jeff Butler
33   *
34   */
35  public class MixedClientGenerator extends JavaMapperGenerator {
36  
37      public MixedClientGenerator() {
38          super(true);
39      }
40  
41      @Override
42      protected void addDeleteByPrimaryKeyMethod(Interface interfaze) {
43          if (introspectedTable.getRules().generateDeleteByPrimaryKey()) {
44              AbstractJavaMapperMethodGenerator methodGenerator = new AnnotatedDeleteByPrimaryKeyMethodGenerator(false);
45              initializeAndExecuteGenerator(methodGenerator, interfaze);
46          }
47      }
48  
49      @Override
50      protected void addInsertMethod(Interface interfaze) {
51          if (introspectedTable.getRules().generateInsert()) {
52              AbstractJavaMapperMethodGenerator methodGenerator = new AnnotatedInsertMethodGenerator(false);
53              initializeAndExecuteGenerator(methodGenerator, interfaze);
54          }
55      }
56  
57      @Override
58      protected void addSelectByPrimaryKeyMethod(Interface interfaze) {
59          if (introspectedTable.getRules().generateSelectByPrimaryKey()) {
60              AbstractJavaMapperMethodGenerator methodGenerator = 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 = new AnnotatedUpdateByPrimaryKeyWithBLOBsMethodGenerator();
69              initializeAndExecuteGenerator(methodGenerator, interfaze);
70          }
71      }
72  
73      @Override
74      protected void addUpdateByPrimaryKeyWithoutBLOBsMethod(Interface interfaze) {
75          if (introspectedTable.getRules()
76                  .generateUpdateByPrimaryKeyWithoutBLOBs()) {
77              AbstractJavaMapperMethodGenerator methodGenerator = new AnnotatedUpdateByPrimaryKeyWithoutBLOBsMethodGenerator(false);
78              initializeAndExecuteGenerator(methodGenerator, interfaze);
79          }
80      }
81  
82      @Override
83      public AbstractXmlGenerator getMatchedXMLGenerator() {
84          return new MixedMapperGenerator();
85      }
86  }