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

mybatis / generator / 1945

14 Jan 2026 02:23PM UTC coverage: 88.838% (+0.04%) from 88.799%
1945

Pull #1414

github

web-flow
Merge 5eec5583d into 5d3363986
Pull Request #1414: Major Refactoring - Context is now configuration only, Plugins Potentially Impacted

2347 of 3184 branches covered (73.71%)

490 of 582 new or added lines in 133 files covered. (84.19%)

2 existing lines in 1 file now uncovered.

11517 of 12964 relevant lines covered (88.84%)

0.89 hits per line

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

0.0
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CachePlugin.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.plugins;
17

18
import java.util.List;
19

20
import org.mybatis.generator.api.IntrospectedTable;
21
import org.mybatis.generator.api.PluginAdapter;
22
import org.mybatis.generator.api.dom.xml.Attribute;
23
import org.mybatis.generator.api.dom.xml.Document;
24
import org.mybatis.generator.api.dom.xml.XmlElement;
25
import org.mybatis.generator.internal.util.StringUtility;
26

27
/**
28
 * This plugin adds a cache element to generated sqlMaps.  This plugin
29
 * is for MyBatis3 targeted runtimes only.  The plugin accepts the
30
 * following properties (all are optional):
31
 *
32
 * <ul>
33
 *   <li>cache_eviction</li>
34
 *   <li>cache_flushInterval</li>
35
 *   <li>cache_size</li>
36
 *   <li>cache_readOnly</li>
37
 *   <li>cache_type</li>
38
 * </ul>
39
 *
40
 * <p>All properties correspond to properties of the MyBatis cache element and
41
 * are passed "as is" to the corresponding properties of the generated cache
42
 * element.  All properties can be specified at the table level, or on the
43
 * plugin element.  The property on the table element will override any
44
 * property on the plugin element.
45
 *
46
 * @author Jason Bennett
47
 * @author Jeff Butler
48
 */
49
public class CachePlugin extends PluginAdapter {
50
    public enum CacheProperty {
×
51
        EVICTION("cache_eviction", "eviction"), //$NON-NLS-1$ //$NON-NLS-2$
×
52
        FLUSH_INTERVAL("cache_flushInterval", "flushInterval"), //$NON-NLS-1$ //$NON-NLS-2$
×
53
        READ_ONLY("cache_readOnly", "readOnly"), //$NON-NLS-1$ //$NON-NLS-2$
×
54
        SIZE("cache_size", "size"), //$NON-NLS-1$ //$NON-NLS-2$
×
55
        TYPE("cache_type", "type"); //$NON-NLS-1$ //$NON-NLS-2$
×
56

57
        private final String propertyName;
58
        private final String attributeName;
59

60
        CacheProperty(String propertyName, String attributeName) {
×
61
            this.propertyName = propertyName;
×
62
            this.attributeName = attributeName;
×
63
        }
×
64

65
        public String getPropertyName() {
66
            return propertyName;
×
67
        }
68

69
        public String getAttributeName() {
70
            return attributeName;
×
71
        }
72
    }
73

74
    public CachePlugin() {
75
        super();
×
76
    }
×
77

78
    @Override
79
    public boolean validate(List<String> warnings) {
80
        return true;
×
81
    }
82

83
    @Override
84
    public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
85

86
        XmlElement element = new XmlElement("cache"); //$NON-NLS-1$
×
NEW
87
        commentGenerator.addComment(element);
×
88

89
        for (CacheProperty cacheProperty : CacheProperty.values()) {
×
90
            addAttributeIfExists(element, introspectedTable, cacheProperty);
×
91
        }
92

93
        document.getRootElement().addElement(element);
×
94

95
        return true;
×
96
    }
97

98
    private void addAttributeIfExists(XmlElement element, IntrospectedTable introspectedTable,
99
            CacheProperty cacheProperty) {
100
        String property = introspectedTable.getTableConfigurationProperty(cacheProperty.getPropertyName());
×
101
        if (property == null) {
×
102
            property = properties.getProperty(cacheProperty.getPropertyName());
×
103
        }
104

105
        if (StringUtility.stringHasValue(property)) {
×
106
            element.addAttribute(new Attribute(cacheProperty.getAttributeName(), property));
×
107
        }
108
    }
×
109
}
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