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.Field;
19  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
20  import org.mybatis.generator.api.dom.java.JavaVisibility;
21  import org.mybatis.generator.api.dom.java.Method;
22  import org.mybatis.generator.api.dom.java.Parameter;
23  
24  /**
25   * @author Jeff Butler
26   */
27  public class GenericCIDAOTemplate extends AbstractDAOTemplate {
28  
29      private FullyQualifiedJavaType sqlMapClientType = new FullyQualifiedJavaType(
30              "com.ibatis.sqlmap.client.SqlMapClient"); //$NON-NLS-1$
31  
32      /**
33       *  
34       */
35      public GenericCIDAOTemplate() {
36          super();
37      }
38  
39      @Override
40      protected void configureCheckedExceptions() {
41          addCheckedException(new FullyQualifiedJavaType("java.sql.SQLException")); //$NON-NLS-1$
42      }
43  
44      @Override
45      protected void configureConstructorTemplate() {
46          Method constructor = new Method();
47          constructor.setConstructor(true);
48          constructor.setVisibility(JavaVisibility.PUBLIC);
49          constructor
50                  .addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$
51          constructor.addBodyLine("super();"); //$NON-NLS-1$
52          constructor.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$
53          setConstructorTemplate(constructor);
54      }
55  
56      @Override
57      protected void configureDeleteMethodTemplate() {
58          setDeleteMethodTemplate("sqlMapClient.delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
59      }
60  
61      @Override
62      protected void configureFields() {
63          Field field = new Field();
64          field.setVisibility(JavaVisibility.PRIVATE);
65          field.setType(sqlMapClientType);
66          field.setName("sqlMapClient"); //$NON-NLS-1$
67          addField(field);
68      }
69  
70      @Override
71      protected void configureImplementationImports() {
72          addImplementationImport(sqlMapClientType);
73      }
74  
75      @Override
76      protected void configureInsertMethodTemplate() {
77          setInsertMethodTemplate("sqlMapClient.insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
78      }
79  
80      @Override
81      protected void configureQueryForListMethodTemplate() {
82          setQueryForListMethodTemplate("sqlMapClient.queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
83      }
84  
85      @Override
86      protected void configureQueryForObjectMethodTemplate() {
87          setQueryForObjectMethodTemplate("sqlMapClient.queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
88      }
89  
90      @Override
91      protected void configureUpdateMethodTemplate() {
92          setUpdateMethodTemplate("sqlMapClient.update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
93      }
94  }