View Javadoc
1   /*
2    *    Copyright 2006-2026 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.api;
17  
18  import java.util.List;
19  import java.util.Optional;
20  import java.util.Properties;
21  
22  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
23  import org.mybatis.generator.config.Context;
24  
25  /**
26   * This interface describes methods that are required in any Java type resolver.
27   * A Java type resolver is used to make a default translation between a JDBC
28   * type as returned from the database introspection process, and a Java type.
29   *
30   * @author Jeff Butler
31   */
32  public interface JavaTypeResolver {
33      /**
34       * Adds properties for this instance from any properties configured in the
35       * JavaTypeResolverConfiguration.
36       *
37       * <p>This method will be called before any of the get methods.
38       *
39       * @param properties All properties from the configuration
40       */
41      void addConfigurationProperties(Properties properties);
42  
43      /**
44       * Sets the instance of the Context object associated with this instance.
45       *
46       * <p>This method will be called before any of the get methods.
47       *
48       * @param context The current Context
49       */
50      void setContext(Context context);
51  
52      /**
53       * The generator will supply a list to this method. The implementation class may add strings to the list that will
54       * be treated as warning messages and displayed to the user. The concept of a warning is that code generation can
55       * continue, but that the results may not be what is expected.
56       *
57       * @param warnings warnings
58       */
59      void setWarnings(List<String> warnings);
60  
61      /**
62       * Calculates and returns the type information that should be associated with
63       * this column based on the jdbc type, length, and scale of the column.
64       *
65       * @param introspectedColumn the column whose type information needs to be calculated
66       * @return the calculated type information, or empty if this is an unsupported type.
67       *     If empty, we will set the JDBC type to OTHER and the Java type to Object and issue a warning
68       *     unless the column is ignored or otherwise overridden
69       */
70      Optional<JdbcTypeInformation> calculateTypeInformation(IntrospectedColumn introspectedColumn);
71  
72      record JdbcTypeInformation(String jdbcTypeName, FullyQualifiedJavaType fullyQualifiedJavaType) {
73          public JdbcTypeInformation withJavaType(FullyQualifiedJavaType fullyQualifiedJavaType) {
74              return new JdbcTypeInformation(jdbcTypeName, fullyQualifiedJavaType);
75          }
76      }
77  }