• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / generator / 2036

11 Feb 2026 03:40PM UTC coverage: 89.976% (+0.04%) from 89.941%
2036

Pull #1447

github

web-flow
Merge fcb778c1b into cb3727515
Pull Request #1447: Support Injecting Generated Model into Generic Mapper Root Interfaces

2300 of 3075 branches covered (74.8%)

31 of 33 new or added lines in 5 files covered. (93.94%)

11651 of 12949 relevant lines covered (89.98%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/RootInterfaceUtility.java
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.runtime;
17

18
import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19

20
import java.util.stream.Collectors;
21

22
import org.jspecify.annotations.Nullable;
23
import org.mybatis.generator.api.IntrospectedTable;
24
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
25
import org.mybatis.generator.api.dom.java.Interface;
26
import org.mybatis.generator.config.Context;
27
import org.mybatis.generator.config.PropertyRegistry;
28

NEW
29
public class RootInterfaceUtility {
×
30
    public static void addRootInterfaceIsNecessary(Interface mapper,
31
                                                   IntrospectedTable introspectedTable, Context context) {
32
        String rootInterface = findProperty(PropertyRegistry.ANY_ROOT_INTERFACE, introspectedTable, context);
1✔
33

34
        if (stringHasValue(rootInterface)) {
1✔
35
            FullyQualifiedJavaType baseInterface = new FullyQualifiedJavaType(rootInterface);
1✔
36
            String inject =
1✔
37
                    findProperty(PropertyRegistry.ANY_INJECT_MODEL_INTO_ROOT_INTERFACE, introspectedTable, context);
1✔
38

39
            FullyQualifiedJavaType rootInterfaceType;
40
            if (Boolean.parseBoolean(inject)) {
1✔
41
                rootInterfaceType = injectRootModel(baseInterface, calculateRootModel(introspectedTable));
1✔
42
            } else {
43
                rootInterfaceType = baseInterface;
1✔
44
            }
45

46
            mapper.addSuperInterface(rootInterfaceType);
1✔
47
            mapper.addImportedTypes(rootInterfaceType.getImportList().stream()
1✔
48
                    .map(FullyQualifiedJavaType::new).collect(Collectors.toSet()));
1✔
49
        }
50
    }
1✔
51

52
    private static FullyQualifiedJavaType injectRootModel(FullyQualifiedJavaType baseInterface,
53
                                                          FullyQualifiedJavaType injectedType) {
54
        if (baseInterface.getTypeArguments().size() == 1) {
1!
55
            FullyQualifiedJavaType answer =
1✔
56
                    new FullyQualifiedJavaType(baseInterface.getFullyQualifiedNameWithoutTypeParameters());
1✔
57
            answer.addTypeArgument(new FullyQualifiedJavaType(injectedType.getShortName()));
1✔
58
            return answer;
1✔
59
        } else {
NEW
60
            return baseInterface;
×
61
        }
62
    }
63

64
    private static FullyQualifiedJavaType calculateRootModel(IntrospectedTable introspectedTable) {
65
        if (introspectedTable.getRules().generatePrimaryKeyClass()) {
1✔
66
            return new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
1✔
67
        } else {
68
            return new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
1✔
69
        }
70
    }
71

72
    private static @Nullable String findProperty(String property, IntrospectedTable introspectedTable,
73
                                                 Context context) {
74
        String value = introspectedTable.getTableConfigurationProperty(property);
1✔
75
        if (!stringHasValue(value)) {
1!
76
            value = context.getJavaClientGeneratorConfiguration()
1✔
77
                    .map(c -> c.getProperty(property))
1✔
78
                    .orElse(null);
1✔
79
        }
80

81
        return value;
1✔
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc