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  
20  /**
21   * This class encapsulates all the code generation rules for a table using the
22   * hierarchical model.
23   * 
24   * @author Jeff Butler
25   * 
26   */
27  public class HierarchicalModelRules extends BaseRules {
28  
29      /**
30       * Instantiates a new hierarchical model rules.
31       *
32       * @param introspectedTable
33       *            the introspected table
34       */
35      public HierarchicalModelRules(IntrospectedTable introspectedTable) {
36          super(introspectedTable);
37      }
38  
39      /**
40       * Implements the rule for determining whether to generate a primary key
41       * class. If the physical table has a primary key, then we generate the
42       * class.
43       * 
44       * @return true if the primary key should be generated
45       */
46      public boolean generatePrimaryKeyClass() {
47          return introspectedTable.hasPrimaryKeyColumns();
48      }
49  
50      /**
51       * Implements the rule for generating a base record. If the table has fields
52       * that are not in the primary key, and non-BLOB fields, then generate the
53       * class.
54       * 
55       * @return true if the class should be generated
56       */
57      public boolean generateBaseRecordClass() {
58          return introspectedTable.hasBaseColumns();
59      }
60  
61      /**
62       * Implements the rule for generating a record with BLOBs. A record with
63       * BLOBs is generated if the table contains any BLOB fields.
64       * 
65       * @return true if the record with BLOBs class should be generated
66       */
67      public boolean generateRecordWithBLOBsClass() {
68          return introspectedTable.hasBLOBColumns();
69      }
70  }