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.internal;
17  
18  import org.mybatis.generator.api.DAOMethodNameCalculator;
19  import org.mybatis.generator.api.IntrospectedTable;
20  import org.mybatis.generator.internal.rules.Rules;
21  
22  /**
23   * @author Jeff Butler
24   * 
25   */
26  public class DefaultDAOMethodNameCalculator implements DAOMethodNameCalculator {
27  
28      /**
29       * 
30       */
31      public DefaultDAOMethodNameCalculator() {
32          super();
33      }
34  
35      public String getInsertMethodName(IntrospectedTable introspectedTable) {
36          return "insert"; //$NON-NLS-1$
37      }
38  
39      /**
40       * 1. if this will be the only updateByPrimaryKey, then the result should be
41       * updateByPrimaryKey. 2. If the other method is enabled, but there are
42       * seperate base and blob classes, then the method name should be
43       * updateByPrimaryKey 3. Else the method name should be
44       * updateByPrimaryKeyWithoutBLOBs
45       */
46      public String getUpdateByPrimaryKeyWithoutBLOBsMethodName(
47              IntrospectedTable introspectedTable) {
48          Rules rules = introspectedTable.getRules();
49  
50          if (!rules.generateUpdateByPrimaryKeyWithBLOBs()) {
51              return "updateByPrimaryKey"; //$NON-NLS-1$
52          } else if (rules.generateRecordWithBLOBsClass()) {
53              return "updateByPrimaryKey"; //$NON-NLS-1$
54          } else {
55              return "updateByPrimaryKeyWithoutBLOBs"; //$NON-NLS-1$
56          }
57      }
58  
59      /**
60       * 1. if this will be the only updateByPrimaryKey, then the result should be
61       * updateByPrimaryKey. 2. If the other method is enabled, but there are
62       * seperate base and blob classes, then the method name should be
63       * updateByPrimaryKey 3. Else the method name should be
64       * updateByPrimaryKeyWithBLOBs
65       */
66      public String getUpdateByPrimaryKeyWithBLOBsMethodName(
67              IntrospectedTable introspectedTable) {
68          Rules rules = introspectedTable.getRules();
69  
70          if (!rules.generateUpdateByPrimaryKeyWithoutBLOBs()) {
71              return "updateByPrimaryKey"; //$NON-NLS-1$
72          } else if (rules.generateRecordWithBLOBsClass()) {
73              return "updateByPrimaryKey"; //$NON-NLS-1$
74          } else {
75              return "updateByPrimaryKeyWithBLOBs"; //$NON-NLS-1$
76          }
77      }
78  
79      public String getDeleteByExampleMethodName(
80              IntrospectedTable introspectedTable) {
81          return "deleteByExample"; //$NON-NLS-1$
82      }
83  
84      public String getDeleteByPrimaryKeyMethodName(
85              IntrospectedTable introspectedTable) {
86          return "deleteByPrimaryKey"; //$NON-NLS-1$
87      }
88  
89      /**
90       * 1. if this will be the only selectByExample, then the result should be
91       * selectByExample. 2. Else the method name should be
92       * selectByExampleWithoutBLOBs
93       */
94      public String getSelectByExampleWithoutBLOBsMethodName(
95              IntrospectedTable introspectedTable) {
96          Rules rules = introspectedTable.getRules();
97  
98          if (!rules.generateSelectByExampleWithBLOBs()) {
99              return "selectByExample"; //$NON-NLS-1$
100         } else {
101             return "selectByExampleWithoutBLOBs"; //$NON-NLS-1$
102         }
103     }
104 
105     /**
106      * 1. if this will be the only selectByExample, then the result should be
107      * selectByExample. 2. Else the method name should be
108      * selectByExampleWithBLOBs
109      */
110     public String getSelectByExampleWithBLOBsMethodName(
111             IntrospectedTable introspectedTable) {
112         Rules rules = introspectedTable.getRules();
113 
114         if (!rules.generateSelectByExampleWithoutBLOBs()) {
115             return "selectByExample"; //$NON-NLS-1$
116         } else {
117             return "selectByExampleWithBLOBs"; //$NON-NLS-1$
118         }
119     }
120 
121     public String getSelectByPrimaryKeyMethodName(
122             IntrospectedTable introspectedTable) {
123         return "selectByPrimaryKey"; //$NON-NLS-1$
124     }
125 
126     public String getUpdateByPrimaryKeySelectiveMethodName(
127             IntrospectedTable introspectedTable) {
128         return "updateByPrimaryKeySelective"; //$NON-NLS-1$
129     }
130 
131     public String getCountByExampleMethodName(
132             IntrospectedTable introspectedTable) {
133         return "countByExample"; //$NON-NLS-1$
134     }
135 
136     public String getUpdateByExampleSelectiveMethodName(
137             IntrospectedTable introspectedTable) {
138         return "updateByExampleSelective"; //$NON-NLS-1$
139     }
140 
141     public String getUpdateByExampleWithBLOBsMethodName(
142             IntrospectedTable introspectedTable) {
143         Rules rules = introspectedTable.getRules();
144 
145         if (!rules.generateUpdateByExampleWithoutBLOBs()) {
146             return "updateByExample"; //$NON-NLS-1$
147         } else if (rules.generateRecordWithBLOBsClass()) {
148             return "updateByExample"; //$NON-NLS-1$
149         } else {
150             return "updateByExampleWithBLOBs"; //$NON-NLS-1$
151         }
152     }
153 
154     public String getUpdateByExampleWithoutBLOBsMethodName(
155             IntrospectedTable introspectedTable) {
156         Rules rules = introspectedTable.getRules();
157 
158         if (!rules.generateUpdateByExampleWithBLOBs()) {
159             return "updateByExample"; //$NON-NLS-1$
160         } else if (rules.generateRecordWithBLOBsClass()) {
161             return "updateByExample"; //$NON-NLS-1$
162         } else {
163             return "updateByExampleWithoutBLOBs"; //$NON-NLS-1$
164         }
165     }
166 
167     public String getInsertSelectiveMethodName(
168             IntrospectedTable introspectedTable) {
169         return "insertSelective"; //$NON-NLS-1$
170     }
171 }