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 ExtendedDAOMethodNameCalculator implements DAOMethodNameCalculator {
27  
28      /**
29       * 
30       */
31      public ExtendedDAOMethodNameCalculator() {
32          super();
33      }
34  
35      public String getInsertMethodName(IntrospectedTable introspectedTable) {
36          StringBuilder sb = new StringBuilder();
37          sb.append("insert"); //$NON-NLS-1$
38          sb.append(introspectedTable.getFullyQualifiedTable()
39                  .getDomainObjectName());
40  
41          return sb.toString();
42      }
43  
44      /**
45       * 1. if this will be the only updateByPrimaryKey, then the result should be
46       * updateByPrimaryKey. 2. If the other method is enabled, but there are
47       * seperate base and blob classes, then the method name should be
48       * updateByPrimaryKey 3. Else the method name should be
49       * updateByPrimaryKeyWithoutBLOBs
50       */
51      public String getUpdateByPrimaryKeyWithoutBLOBsMethodName(
52              IntrospectedTable introspectedTable) {
53          StringBuilder sb = new StringBuilder();
54  
55          sb.append("update"); //$NON-NLS-1$
56          sb.append(introspectedTable.getFullyQualifiedTable()
57                  .getDomainObjectName());
58  
59          Rules rules = introspectedTable.getRules();
60  
61          if (!rules.generateUpdateByPrimaryKeyWithBLOBs()) {
62              sb.append("ByPrimaryKey"); //$NON-NLS-1$
63          } else if (rules.generateRecordWithBLOBsClass()) {
64              sb.append("ByPrimaryKey"); //$NON-NLS-1$
65          } else {
66              sb.append("ByPrimaryKeyWithoutBLOBs"); //$NON-NLS-1$
67          }
68  
69          return sb.toString();
70      }
71  
72      /**
73       * 1. if this will be the only updateByPrimaryKey, then the result should be
74       * updateByPrimaryKey. 2. If the other method is enabled, but there are
75       * seperate base and blob classes, then the method name should be
76       * updateByPrimaryKey 3. Else the method name should be
77       * updateByPrimaryKeyWithBLOBs
78       */
79      public String getUpdateByPrimaryKeyWithBLOBsMethodName(
80              IntrospectedTable introspectedTable) {
81          StringBuilder sb = new StringBuilder();
82          sb.append("update"); //$NON-NLS-1$
83          sb.append(introspectedTable.getFullyQualifiedTable()
84                  .getDomainObjectName());
85  
86          Rules rules = introspectedTable.getRules();
87  
88          if (!rules.generateUpdateByPrimaryKeyWithoutBLOBs()) {
89              sb.append("ByPrimaryKey"); //$NON-NLS-1$
90          } else if (rules.generateRecordWithBLOBsClass()) {
91              sb.append("ByPrimaryKey"); //$NON-NLS-1$
92          } else {
93              sb.append("ByPrimaryKeyWithBLOBs"); //$NON-NLS-1$
94          }
95  
96          return sb.toString();
97      }
98  
99      public String getDeleteByExampleMethodName(
100             IntrospectedTable introspectedTable) {
101         StringBuilder sb = new StringBuilder();
102         sb.append("delete"); //$NON-NLS-1$
103         sb.append(introspectedTable.getFullyQualifiedTable()
104                 .getDomainObjectName());
105         sb.append("ByExample"); //$NON-NLS-1$
106 
107         return sb.toString();
108     }
109 
110     public String getDeleteByPrimaryKeyMethodName(
111             IntrospectedTable introspectedTable) {
112         StringBuilder sb = new StringBuilder();
113         sb.append("delete"); //$NON-NLS-1$
114         sb.append(introspectedTable.getFullyQualifiedTable()
115                 .getDomainObjectName());
116         sb.append("ByPrimaryKey"); //$NON-NLS-1$
117 
118         return sb.toString();
119     }
120 
121     /**
122      * 1. if this will be the only selectByExample, then the result should be
123      * selectByExample. 2. Else the method name should be
124      * selectByExampleWithoutBLOBs
125      */
126     public String getSelectByExampleWithoutBLOBsMethodName(
127             IntrospectedTable introspectedTable) {
128         StringBuilder sb = new StringBuilder();
129         sb.append("select"); //$NON-NLS-1$
130         sb.append(introspectedTable.getFullyQualifiedTable()
131                 .getDomainObjectName());
132         sb.append("ByExample"); //$NON-NLS-1$
133 
134         Rules rules = introspectedTable.getRules();
135 
136         if (rules.generateSelectByExampleWithBLOBs()) {
137             sb.append("WithoutBLOBs"); //$NON-NLS-1$
138         }
139 
140         return sb.toString();
141     }
142 
143     /**
144      * 1. if this will be the only selectByExample, then the result should be
145      * selectByExample. 2. Else the method name should be
146      * selectByExampleWithBLOBs
147      */
148     public String getSelectByExampleWithBLOBsMethodName(
149             IntrospectedTable introspectedTable) {
150         StringBuilder sb = new StringBuilder();
151         sb.append("select"); //$NON-NLS-1$
152         sb.append(introspectedTable.getFullyQualifiedTable()
153                 .getDomainObjectName());
154         sb.append("ByExample"); //$NON-NLS-1$
155 
156         Rules rules = introspectedTable.getRules();
157 
158         if (rules.generateSelectByExampleWithoutBLOBs()) {
159             sb.append("WithBLOBs"); //$NON-NLS-1$
160         }
161 
162         return sb.toString();
163     }
164 
165     public String getSelectByPrimaryKeyMethodName(
166             IntrospectedTable introspectedTable) {
167         StringBuilder sb = new StringBuilder();
168         sb.append("select"); //$NON-NLS-1$
169         sb.append(introspectedTable.getFullyQualifiedTable()
170                 .getDomainObjectName());
171         sb.append("ByPrimaryKey"); //$NON-NLS-1$
172 
173         return sb.toString();
174     }
175 
176     public String getUpdateByPrimaryKeySelectiveMethodName(
177             IntrospectedTable introspectedTable) {
178         StringBuilder sb = new StringBuilder();
179         sb.append("update"); //$NON-NLS-1$
180         sb.append(introspectedTable.getFullyQualifiedTable()
181                 .getDomainObjectName());
182         sb.append("ByPrimaryKeySelective"); //$NON-NLS-1$
183 
184         return sb.toString();
185     }
186 
187     public String getCountByExampleMethodName(
188             IntrospectedTable introspectedTable) {
189         StringBuilder sb = new StringBuilder();
190         sb.append("count"); //$NON-NLS-1$
191         sb.append(introspectedTable.getFullyQualifiedTable()
192                 .getDomainObjectName());
193         sb.append("ByExample"); //$NON-NLS-1$
194 
195         return sb.toString();
196     }
197 
198     public String getUpdateByExampleSelectiveMethodName(
199             IntrospectedTable introspectedTable) {
200         StringBuilder sb = new StringBuilder();
201         sb.append("update"); //$NON-NLS-1$
202         sb.append(introspectedTable.getFullyQualifiedTable()
203                 .getDomainObjectName());
204         sb.append("ByExampleSelective"); //$NON-NLS-1$
205 
206         return sb.toString();
207     }
208 
209     public String getUpdateByExampleWithBLOBsMethodName(
210             IntrospectedTable introspectedTable) {
211         StringBuilder sb = new StringBuilder();
212         sb.append("update"); //$NON-NLS-1$
213         sb.append(introspectedTable.getFullyQualifiedTable()
214                 .getDomainObjectName());
215 
216         Rules rules = introspectedTable.getRules();
217 
218         if (!rules.generateUpdateByExampleWithoutBLOBs()) {
219             sb.append("ByExample"); //$NON-NLS-1$
220         } else if (rules.generateRecordWithBLOBsClass()) {
221             sb.append("ByExample"); //$NON-NLS-1$
222         } else {
223             sb.append("ByExampleWithBLOBs"); //$NON-NLS-1$
224         }
225 
226         return sb.toString();
227     }
228 
229     public String getUpdateByExampleWithoutBLOBsMethodName(
230             IntrospectedTable introspectedTable) {
231         StringBuilder sb = new StringBuilder();
232 
233         sb.append("update"); //$NON-NLS-1$
234         sb.append(introspectedTable.getFullyQualifiedTable()
235                 .getDomainObjectName());
236 
237         Rules rules = introspectedTable.getRules();
238 
239         if (!rules.generateUpdateByExampleWithBLOBs()) {
240             sb.append("ByExample"); //$NON-NLS-1$
241         } else if (rules.generateRecordWithBLOBsClass()) {
242             sb.append("ByExample"); //$NON-NLS-1$
243         } else {
244             sb.append("ByExampleWithoutBLOBs"); //$NON-NLS-1$
245         }
246 
247         return sb.toString();
248     }
249 
250     public String getInsertSelectiveMethodName(
251             IntrospectedTable introspectedTable) {
252         StringBuilder sb = new StringBuilder();
253         sb.append("insert"); //$NON-NLS-1$
254         sb.append(introspectedTable.getFullyQualifiedTable()
255                 .getDomainObjectName());
256         sb.append("Selective"); //$NON-NLS-1$
257 
258         return sb.toString();
259     }
260 }