diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/CompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/CompositePlugin.java index 23a6c1d450..76a5a665f5 100644 --- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/CompositePlugin.java +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/CompositePlugin.java @@ -1201,9 +1201,9 @@ public boolean mapperExtensionsGenerated(KotlinFile extensionsFile, Introspected } @Override - public boolean mapperGenerated(KotlinFile mapperFile, IntrospectedTable introspectedTable) { + public boolean mapperGenerated(KotlinFile mapperFile, KotlinType mapper, IntrospectedTable introspectedTable) { for (Plugin plugin : plugins) { - if (!plugin.mapperGenerated(mapperFile, introspectedTable)) { + if (!plugin.mapperGenerated(mapperFile, mapper, introspectedTable)) { return false; } } diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/Plugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/Plugin.java index 66d8cca754..5789563832 100644 --- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/Plugin.java +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/Plugin.java @@ -1978,7 +1978,7 @@ default boolean mapperExtensionsGenerated(KotlinFile extensionsFile, Introspecte return true; } - default boolean mapperGenerated(KotlinFile mapperFile, IntrospectedTable introspectedTable) { + default boolean mapperGenerated(KotlinFile mapperFile, KotlinType mapper, IntrospectedTable introspectedTable) { return true; } diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CacheNamespacePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CacheNamespacePlugin.java new file mode 100644 index 0000000000..a661ce24bf --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CacheNamespacePlugin.java @@ -0,0 +1,142 @@ +/* + * Copyright 2006-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.generator.plugins; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.api.dom.java.Interface; +import org.mybatis.generator.api.dom.kotlin.KotlinFile; +import org.mybatis.generator.api.dom.kotlin.KotlinType; +import org.mybatis.generator.internal.util.StringUtility; + +/** + * This plugin adds a CacheNamespace annotation to generated Java or Kotlin mapper interfaces. + * The plugin accepts the following properties (all are optional): + * + *
All properties (except cache_skip) correspond to properties of the MyBatis CacheNamespace annotation and + * are passed "as is" to the corresponding properties of the generated + * annotation. All properties can be specified at the table level, or on the + * plugin element. The property on the table element will override any + * property on the plugin element. + * + *
If the "cache_skip" property is set to "true" - either on the plugin or on a specific table,
+ * the annotation will not be applied to the generated interface.
+ *
+ * @author Jeff Butler
+ */
+public class CacheNamespacePlugin extends PluginAdapter {
+
+ public enum CacheProperty {
+ BLOCKING("cache_blocking", "blocking"), //$NON-NLS-1$ //$NON-NLS-2$
+ FLUSH_INTERVAL("cache_flushInterval", "flushInterval"), //$NON-NLS-1$ //$NON-NLS-2$
+ READ_WRITE("cache_readWrite", "readWrite"), //$NON-NLS-1$ //$NON-NLS-2$
+ SIZE("cache_size", "size"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private final String propertyName;
+ private final String attributeName;
+
+ CacheProperty(String propertyName, String attributeName) {
+ this.propertyName = propertyName;
+ this.attributeName = attributeName;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+ }
+
+ @Override
+ public boolean validate(List