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.rules;
17  
18  import org.mybatis.generator.api.IntrospectedTable;
19  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
20  
21  /**
22   * This interface centralizes all the rules related to code generation -
23   * including the methods and objects to create, and certain attributes related
24   * to those objects.
25   * 
26   * @author Jeff Butler
27   */
28  public interface Rules {
29  
30      /**
31       * Implements the rule for generating the insert SQL Map element and DAO
32       * method. If the insert statement is allowed, then generate the element and
33       * method.
34       * 
35       * @return true if the element and method should be generated
36       */
37      boolean generateInsert();
38  
39      /**
40       * Implements the rule for generating the insert selective SQL Map element
41       * and DAO method. If the insert statement is allowed, then generate the
42       * element and method.
43       * 
44       * @return true if the element and method should be generated
45       */
46      boolean generateInsertSelective();
47  
48      /**
49       * Calculates the class that contains all fields. This class is used as the
50       * insert statement parameter, as well as the returned value from the select
51       * by primary key method. The actual class depends on how the domain model
52       * is generated.
53       * 
54       * @return the type of the class that holds all fields
55       */
56      FullyQualifiedJavaType calculateAllFieldsClass();
57  
58      /**
59       * Implements the rule for generating the update by primary key without
60       * BLOBs SQL Map element and DAO method. If the table has a primary key as
61       * well as other non-BLOB fields, and the updateByPrimaryKey statement is
62       * allowed, then generate the element and method.
63       * 
64       * @return true if the element and method should be generated
65       */
66      boolean generateUpdateByPrimaryKeyWithoutBLOBs();
67  
68      /**
69       * Implements the rule for generating the update by primary key with BLOBs
70       * SQL Map element and DAO method. If the table has a primary key as well as
71       * other BLOB fields, and the updateByPrimaryKey statement is allowed, then
72       * generate the element and method.
73       * 
74       * @return true if the element and method should be generated
75       */
76      boolean generateUpdateByPrimaryKeyWithBLOBs();
77  
78      /**
79       * Implements the rule for generating the update by primary key selective
80       * SQL Map element and DAO method. If the table has a primary key as well as
81       * other fields, and the updateByPrimaryKey statement is allowed, then
82       * generate the element and method.
83       * 
84       * @return true if the element and method should be generated
85       */
86      boolean generateUpdateByPrimaryKeySelective();
87  
88      /**
89       * Implements the rule for generating the delete by primary key SQL Map
90       * element and DAO method. If the table has a primary key, and the
91       * deleteByPrimaryKey statement is allowed, then generate the element and
92       * method.
93       * 
94       * @return true if the element and method should be generated
95       */
96      boolean generateDeleteByPrimaryKey();
97  
98      /**
99       * Implements the rule for generating the delete by example SQL Map element
100      * and DAO method. If the deleteByExample statement is allowed, then
101      * generate the element and method.
102      * 
103      * @return true if the element and method should be generated
104      */
105     boolean generateDeleteByExample();
106 
107     /**
108      * Implements the rule for generating the result map without BLOBs. If
109      * either select method is allowed, then generate the result map.
110      * 
111      * @return true if the result map should be generated
112      */
113     boolean generateBaseResultMap();
114 
115     /**
116      * Implements the rule for generating the result map with BLOBs. If the
117      * table has BLOB columns, and either select method is allowed, then
118      * generate the result map.
119      * 
120      * @return true if the result map should be generated
121      */
122     boolean generateResultMapWithBLOBs();
123 
124     /**
125      * Implements the rule for generating the SQL example where clause element.
126      * 
127      * In iBATIS2, generate the element if the selectByExample, deleteByExample,
128      * updateByExample, or countByExample statements are allowed.
129      * 
130      * In MyBatis3, generate the element if the selectByExample,
131      * deleteByExample, or countByExample statements are allowed.
132      * 
133      * @return true if the SQL where clause element should be generated
134      */
135     boolean generateSQLExampleWhereClause();
136 
137     /**
138      * Implements the rule for generating the SQL example where clause element
139      * specifically for use in the update by example methods.
140      * 
141      * In iBATIS2, do not generate the element.
142      * 
143      * In MyBatis, generate the element if the updateByExample statements are
144      * allowed.
145      * 
146      * @return true if the SQL where clause element should be generated
147      */
148     boolean generateMyBatis3UpdateByExampleWhereClause();
149 
150     /**
151      * Implements the rule for generating the SQL base column list element.
152      * Generate the element if any of the select methods are enabled.
153      * 
154      * @return true if the SQL base column list element should be generated
155      */
156     boolean generateBaseColumnList();
157 
158     /**
159      * Implements the rule for generating the SQL blob column list element.
160      * Generate the element if any of the select methods are enabled, and the
161      * table contains BLOB columns.
162      * 
163      * @return true if the SQL blob column list element should be generated
164      */
165     boolean generateBlobColumnList();
166 
167     /**
168      * Implements the rule for generating the select by primary key SQL Map
169      * element and DAO method. If the table has a primary key as well as other
170      * fields, and the selectByPrimaryKey statement is allowed, then generate
171      * the element and method.
172      * 
173      * @return true if the element and method should be generated
174      */
175     boolean generateSelectByPrimaryKey();
176 
177     /**
178      * Implements the rule for generating the select by example without BLOBs
179      * SQL Map element and DAO method. If the selectByExample statement is
180      * allowed, then generate the element and method.
181      * 
182      * @return true if the element and method should be generated
183      */
184     boolean generateSelectByExampleWithoutBLOBs();
185 
186     /**
187      * Implements the rule for generating the select by example with BLOBs SQL
188      * Map element and DAO method. If the table has BLOB fields and the
189      * selectByExample statement is allowed, then generate the element and
190      * method.
191      * 
192      * @return true if the element and method should be generated
193      */
194     boolean generateSelectByExampleWithBLOBs();
195 
196     /**
197      * Implements the rule for generating an example class. The class should be
198      * generated if the selectByExample or deleteByExample or countByExample
199      * methods are allowed.
200      * 
201      * @return true if the example class should be generated
202      */
203     boolean generateExampleClass();
204 
205     boolean generateCountByExample();
206 
207     boolean generateUpdateByExampleSelective();
208 
209     boolean generateUpdateByExampleWithoutBLOBs();
210 
211     boolean generateUpdateByExampleWithBLOBs();
212 
213     /**
214      * Implements the rule for determining whether to generate a primary key
215      * class. If you return false from this method, and the table has primary
216      * key columns, then the primary key columns will be added to the base
217      * class.
218      * 
219      * @return true if a separate primary key class should be generated
220      */
221     boolean generatePrimaryKeyClass();
222 
223     /**
224      * Implements the rule for generating a base record.
225      * 
226      * @return true if the class should be generated
227      */
228     boolean generateBaseRecordClass();
229 
230     /**
231      * Implements the rule for generating a record with BLOBs. If you return
232      * false from this method, and the table had BLOB columns, then the BLOB
233      * columns will be added to the base class.
234      * 
235      * @return true if the record with BLOBs class should be generated
236      */
237     boolean generateRecordWithBLOBsClass();
238     
239     /**
240      * Implements the rule for generating a Java client.  This rule is
241      * only active when a javaClientGenerator configuration has been
242      * specified, but the table is designated as "modelOnly".  Do not
243      * generate the client if the table is designated as modelOnly.
244      * 
245      * @return true if the Java client should be generated
246      */
247     boolean generateJavaClient();
248 
249     IntrospectedTable getIntrospectedTable();
250 }