1 /* 2 * Copyright 2006-2023 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 * https://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 * <p>In MyBatis3, generate the element if the selectByExample, 128 * deleteByExample, or countByExample statements are allowed. 129 * 130 * @return true if the SQL where clause element should be generated 131 */ 132 boolean generateSQLExampleWhereClause(); 133 134 /** 135 * Implements the rule for generating the SQL example where clause element 136 * specifically for use in the update by example methods. 137 * 138 * <p>In MyBatis, generate the element if the updateByExample statements are 139 * allowed. 140 * 141 * @return true if the SQL where clause element should be generated 142 */ 143 boolean generateMyBatis3UpdateByExampleWhereClause(); 144 145 /** 146 * Implements the rule for generating the SQL base column list element. 147 * Generate the element if any of the select methods are enabled. 148 * 149 * @return true if the SQL base column list element should be generated 150 */ 151 boolean generateBaseColumnList(); 152 153 /** 154 * Implements the rule for generating the SQL blob column list element. 155 * Generate the element if any of the select methods are enabled, and the 156 * table contains BLOB columns. 157 * 158 * @return true if the SQL blob column list element should be generated 159 */ 160 boolean generateBlobColumnList(); 161 162 /** 163 * Implements the rule for generating the select by primary key SQL Map 164 * element and DAO method. If the table has a primary key as well as other 165 * fields, and the selectByPrimaryKey statement is allowed, then generate 166 * the element and method. 167 * 168 * @return true if the element and method should be generated 169 */ 170 boolean generateSelectByPrimaryKey(); 171 172 /** 173 * Implements the rule for generating the select by example without BLOBs 174 * SQL Map element and DAO method. If the selectByExample statement is 175 * allowed, then generate the element and method. 176 * 177 * @return true if the element and method should be generated 178 */ 179 boolean generateSelectByExampleWithoutBLOBs(); 180 181 /** 182 * Implements the rule for generating the select by example with BLOBs SQL 183 * Map element and DAO method. If the table has BLOB fields and the 184 * selectByExample statement is allowed, then generate the element and 185 * method. 186 * 187 * @return true if the element and method should be generated 188 */ 189 boolean generateSelectByExampleWithBLOBs(); 190 191 /** 192 * Implements the rule for generating an example class. The class should be 193 * generated if the selectByExample or deleteByExample or countByExample 194 * methods are allowed. 195 * 196 * @return true if the example class should be generated 197 */ 198 boolean generateExampleClass(); 199 200 boolean generateCountByExample(); 201 202 boolean generateUpdateByExampleSelective(); 203 204 boolean generateUpdateByExampleWithoutBLOBs(); 205 206 boolean generateUpdateByExampleWithBLOBs(); 207 208 /** 209 * Implements the rule for determining whether to generate a primary key 210 * class. If you return false from this method, and the table has primary 211 * key columns, then the primary key columns will be added to the base 212 * class. 213 * 214 * @return true if a separate primary key class should be generated 215 */ 216 boolean generatePrimaryKeyClass(); 217 218 /** 219 * Implements the rule for generating a base record. 220 * 221 * @return true if the class should be generated 222 */ 223 boolean generateBaseRecordClass(); 224 225 /** 226 * Implements the rule for generating a record with BLOBs. If you return 227 * false from this method, and the table had BLOB columns, then the BLOB 228 * columns will be added to the base class. 229 * 230 * @return true if the record with BLOBs class should be generated 231 */ 232 boolean generateRecordWithBLOBsClass(); 233 234 /** 235 * Implements the rule for generating a Java client. This rule is 236 * only active when a javaClientGenerator configuration has been 237 * specified, but the table is designated as "modelOnly". Do not 238 * generate the client if the table is designated as modelOnly. 239 * 240 * @return true if the Java client should be generated 241 */ 242 boolean generateJavaClient(); 243 244 IntrospectedTable getIntrospectedTable(); 245 }