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.config;
17  
18  import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19  import static org.mybatis.generator.internal.util.messages.Messages.getString;
20  
21  import java.util.List;
22  
23  /**
24   * This class is used to specify a renaming rule for table's domain object name.
25   * If domainObjectName is not configured, we'll build the domain object named
26   * based on the tableName or runtimeTableName. And then we use the domain object
27   * renaming rule to generate the final domain object name.
28   *
29   * <p>For example, if some tables are named:
30   *
31   * <ul>
32   * <li>SYS_USER</li>
33   * <li>SYS_ROLE</li>
34   * <li>SYS_FUNCTIONS</li>
35   * </ul>
36   *
37   * <p>it might be annoying to have the generated domain name all containing the SYS
38   * prefix. This class can be used to remove the prefix by specifying
39   *
40   * <ul>
41   * <li>searchString="^Sys"</li>
42   * <li>replaceString=""</li>
43   * </ul>
44   *
45   * <p>Note that internally, the generator uses the
46   * <code>java.util.regex.Matcher.replaceAll</code> method for this function. See
47   * the documentation of that method for example of the regular expression
48   * language used in Java.
49   *
50   * @author liuzh
51   *
52   */
53  public class DomainObjectRenamingRule {
54      private String searchString;
55      private String replaceString;
56  
57      public String getReplaceString() {
58          return replaceString;
59      }
60  
61      public void setReplaceString(String replaceString) {
62          this.replaceString = replaceString;
63      }
64  
65      public String getSearchString() {
66          return searchString;
67      }
68  
69      public void setSearchString(String searchString) {
70          this.searchString = searchString;
71      }
72  
73      public void validate(List<String> errors, String tableName) {
74          if (!stringHasValue(searchString)) {
75              errors.add(getString("ValidationError.28", tableName)); //$NON-NLS-1$
76          }
77      }
78  }