View Javadoc
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  
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  public class HierarchicalModelRules extends BaseRules {
27  
28      /**
29       * Instantiates a new hierarchical model rules.
30       *
31       * @param introspectedTable
32       *            the introspected table
33       */
34      public HierarchicalModelRules(IntrospectedTable introspectedTable) {
35          super(introspectedTable);
36      }
37  
38      /**
39       * Implements the rule for determining whether to generate a primary key
40       * class. If the physical table has a primary key, then we generate the
41       * class.
42       *
43       * @return true if the primary key should be generated
44       */
45      @Override
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      @Override
58      public boolean generateBaseRecordClass() {
59          return introspectedTable.hasBaseColumns();
60      }
61  
62      /**
63       * Implements the rule for generating a record with BLOBs. A record with
64       * BLOBs is generated if the table contains any BLOB fields.
65       *
66       * @return true if the record with BLOBs class should be generated
67       */
68      @Override
69      public boolean generateRecordWithBLOBsClass() {
70          return introspectedTable.hasBLOBColumns();
71      }
72  }