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.ibatis2.dao.templates;
17  
18  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
19  import org.mybatis.generator.api.dom.java.JavaVisibility;
20  import org.mybatis.generator.api.dom.java.Method;
21  import org.mybatis.generator.api.dom.java.Parameter;
22  
23  /**
24   * @author Jeff Butler
25   */
26  public class IbatisDAOTemplate extends AbstractDAOTemplate {
27  
28      private FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
29              "com.ibatis.dao.client.DaoManager"); //$NON-NLS-1$
30  
31      /**
32       *  
33       */
34      public IbatisDAOTemplate() {
35          super();
36      }
37  
38      @Override
39      protected void configureConstructorTemplate() {
40          Method method = new Method();
41          method.setConstructor(true);
42          method.setVisibility(JavaVisibility.PUBLIC);
43          method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$
44          method.addBodyLine("super(daoManager);"); //$NON-NLS-1$
45          setConstructorTemplate(method);
46      }
47  
48      @Override
49      protected void configureDeleteMethodTemplate() {
50          setDeleteMethodTemplate("delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
51      }
52  
53      @Override
54      protected void configureImplementationImports() {
55          addImplementationImport(fqjt);
56      }
57  
58      @Override
59      protected void configureInsertMethodTemplate() {
60          setInsertMethodTemplate("insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
61      }
62  
63      @Override
64      protected void configureQueryForListMethodTemplate() {
65          setQueryForListMethodTemplate("queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
66      }
67  
68      @Override
69      protected void configureQueryForObjectMethodTemplate() {
70          setQueryForObjectMethodTemplate("queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
71      }
72  
73      @Override
74      protected void configureSuperClass() {
75          setSuperClass(new FullyQualifiedJavaType(
76                  "com.ibatis.dao.client.template.SqlMapDaoTemplate")); //$NON-NLS-1$
77      }
78  
79      @Override
80      protected void configureUpdateMethodTemplate() {
81          setUpdateMethodTemplate("update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
82      }
83  }