From 50de1a840443e9e4671d1b150e4f9d2606bbddd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=81=E5=9F=B9=E5=9F=B9?= Date: Thu, 19 Oct 2023 16:17:26 +0800 Subject: [PATCH] make MBG pluggable(step 1) --- .../IntrospectedTableGenerateNothingImpl.java | 70 ++ ...ectedTableGenerateNothingMyBatis3Impl.java | 24 + .../plugins/AbstracKotlinGeneratorPlugin.java | 52 + .../plugins/AbstractGeneratorPlugin.java | 53 + .../AbstractJavaClientGeneratorPlugin.java | 43 + .../plugins/AbstractJavaGeneratorPlugin.java | 52 + .../plugins/AbstractXmlGeneratorPlugin.java | 87 ++ .../AnnotatedClientGeneratorPlugin.java | 35 + .../plugins/BaseRecordGeneratorPlugin.java | 32 + .../plugins/ClientCompositePlugin.java | 52 + .../CustomJavaClientGeneratorPlugin.java | 56 + .../DynamicSqlMapperGeneratorPlugin.java | 37 + .../DynamicSqlModelGeneratorPlugin.java | 29 + ...DynamicSqlSupportClassGeneratorPlugin.java | 30 + .../plugins/ExampleGeneratorPlugin.java | 32 + .../plugins/JavaMapperGeneratorPlugin.java | 38 + .../plugins/KotlinCompositePlugin.java | 35 + .../KotlinDataClassGeneratorPlugin.java | 30 + ...DynamicSqlSupportClassGeneratorPlugin.java | 47 + .../plugins/KotlinMapperGeneratorPlugin.java | 44 + .../plugins/MixedClientGeneratorPlugin.java | 35 + .../plugins/MixedMapperGeneratorPlugin.java | 38 + .../MyBatis3ClientCompositePlugin.java | 29 + .../plugins/MyBatis3CompositePlugin.java | 41 + .../MyBatis3DynamicSqlCompositePlugin.java | 35 + .../MyBatis3SimpleClientCompositePlugin.java | 28 + .../MyBatis3SimpleCompositePlugin.java | 38 + .../plugins/PrimaryKeyGeneratorPlugin.java | 32 + .../RecordWithBLOBsGeneratorPlugin.java | 32 + .../SimpleAnnotatedClientGeneratorPlugin.java | 33 + .../SimpleJavaClientGeneratorPlugin.java | 34 + .../plugins/SimpleModelGeneratorPlugin.java | 30 + .../SimpleXMLMapperGeneratorPlugin.java | 38 + .../plugins/XMLMapperGeneratorPlugin.java | 38 + .../sql/DynamicSqlMapperGenerator.java | 8 +- .../sql/DynamicSqlSupportClassGenerator.java | 30 +- .../generator/JavaCodeGenerationTest.java | 37 +- .../generator/KotlinCodeGenerationTest.java | 27 +- .../generator/XmlCodeGenerationTest.java | 14 +- .../scripts/generatorConfig-kotlin.xml | 16 + .../scripts/generatorConfig-kotlin2.xml | 253 ++++ .../resources/scripts/generatorConfig.xml | 72 ++ .../resources/scripts/generatorConfig2.xml | 1082 +++++++++++++++++ .../scripts/generatorConfig_Dsql.xml | 12 + .../scripts/generatorConfig_Dsql2.xml | 254 ++++ 45 files changed, 3140 insertions(+), 24 deletions(-) create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingImpl.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingMyBatis3Impl.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstracKotlinGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractXmlGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AnnotatedClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/BaseRecordGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ClientCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CustomJavaClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlModelGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlSupportClassGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ExampleGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/JavaMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDataClassGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDynamicSqlSupportClassGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3ClientCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3CompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3DynamicSqlCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleClientCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleCompositePlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/PrimaryKeyGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/RecordWithBLOBsGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleAnnotatedClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleJavaClientGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleModelGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleXMLMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/XMLMapperGeneratorPlugin.java create mode 100644 core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin2.xml create mode 100644 core/mybatis-generator-core/src/test/resources/scripts/generatorConfig2.xml create mode 100644 core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql2.xml diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingImpl.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingImpl.java new file mode 100644 index 0000000000..3472a866bd --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.codegen; + +import java.util.ArrayList; +import java.util.List; + +import org.mybatis.generator.api.GeneratedJavaFile; +import org.mybatis.generator.api.GeneratedKotlinFile; +import org.mybatis.generator.api.GeneratedXmlFile; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.ProgressCallback; + +/** + * Introspected table implementation for generating nothing. + */ +public class IntrospectedTableGenerateNothingImpl extends IntrospectedTable { + + public IntrospectedTableGenerateNothingImpl() { + this(TargetRuntime.MYBATIS3_DSQL); + } + + public IntrospectedTableGenerateNothingImpl(TargetRuntime targetRuntime) { + super(targetRuntime); + } + + @Override + public void calculateGenerators(List warnings, ProgressCallback progressCallback) { + //no generator + } + + @Override + public List getGeneratedJavaFiles() { + return new ArrayList<>(0); + } + + @Override + public List getGeneratedXmlFiles() { + return new ArrayList<>(0); + } + + @Override + public List getGeneratedKotlinFiles() { + return new ArrayList<>(0); + } + + @Override + public int getGenerationSteps() { + return 0; + } + + @Override + public boolean requiresXMLGenerator() { + return false; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingMyBatis3Impl.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingMyBatis3Impl.java new file mode 100644 index 0000000000..a3a697eee7 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectedTableGenerateNothingMyBatis3Impl.java @@ -0,0 +1,24 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.codegen; + +public class IntrospectedTableGenerateNothingMyBatis3Impl extends IntrospectedTableGenerateNothingImpl { + + public IntrospectedTableGenerateNothingMyBatis3Impl() { + super(TargetRuntime.MYBATIS3); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstracKotlinGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstracKotlinGeneratorPlugin.java new file mode 100644 index 0000000000..c419ee6e15 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstracKotlinGeneratorPlugin.java @@ -0,0 +1,52 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.ArrayList; +import java.util.List; + +import org.mybatis.generator.api.GeneratedKotlinFile; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.kotlin.KotlinFile; +import org.mybatis.generator.codegen.AbstractKotlinGenerator; +import org.mybatis.generator.config.PropertyRegistry; + +public abstract class AbstracKotlinGeneratorPlugin extends AbstractGeneratorPlugin { + + @Override + public abstract AbstractKotlinGenerator getGenerator(IntrospectedTable introspectedTable); + + @Override + public List contextGenerateAdditionalKotlinFiles(IntrospectedTable introspectedTable) { + AbstractKotlinGenerator generator = getGenerator(introspectedTable); + if (generator == null) { + return new ArrayList<>(0); + } + initGenerator(generator, introspectedTable); + + List answer = new ArrayList<>(); + List kotlinFiles = generator.getKotlinFiles(); + for (KotlinFile kotlinFile : kotlinFiles) { + GeneratedKotlinFile gjf = new GeneratedKotlinFile(kotlinFile, + getProject(), + context.getProperty(PropertyRegistry.CONTEXT_KOTLIN_FILE_ENCODING), + context.getKotlinFormatter()); + answer.add(gjf); + } + return answer; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractGeneratorPlugin.java new file mode 100644 index 0000000000..74e9bec10c --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractGeneratorPlugin.java @@ -0,0 +1,53 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.ArrayList; +import java.util.List; + +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.PluginAdapter; +import org.mybatis.generator.api.ProgressCallback; +import org.mybatis.generator.codegen.AbstractGenerator; + +public abstract class AbstractGeneratorPlugin extends PluginAdapter { + + public static final String TARGET_PROJECT_PROPERTY = "targetProject"; + + public static final ProgressCallback NULL_PROGRESS_CALLBACK = new ProgressCallback() {}; + + @Override + public boolean validate(List warnings) { + return true; + } + + public abstract AbstractGenerator getGenerator(IntrospectedTable introspectedTable); + + protected String getProject() { + return properties.getProperty(TARGET_PROJECT_PROPERTY); + } + + protected void initGenerator(AbstractGenerator generator, + IntrospectedTable introspectedTable) { + generator.setContext(context); + generator.setIntrospectedTable(introspectedTable); + generator.setProgressCallback(NULL_PROGRESS_CALLBACK); + generator.setWarnings(new ArrayList<>(0)); + } + + + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaClientGeneratorPlugin.java new file mode 100644 index 0000000000..b9758bf17e --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaClientGeneratorPlugin.java @@ -0,0 +1,43 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; + +public abstract class AbstractJavaClientGeneratorPlugin + extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaClientGenerator getGenerator( + IntrospectedTable introspectedTable) { + if (!introspectedTable.getRules().generateJavaClient() + || context.getJavaClientGeneratorConfiguration() == null) { + return null; + } + return getClientGenerator(introspectedTable); + } + + public String getType() { + if (context.getJavaClientGeneratorConfiguration() == null) { + return null; + } + return context.getJavaClientGeneratorConfiguration().getConfigurationType(); + } + + public abstract AbstractJavaClientGenerator getClientGenerator(IntrospectedTable introspectedTable); + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaGeneratorPlugin.java new file mode 100644 index 0000000000..a67582e7c4 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractJavaGeneratorPlugin.java @@ -0,0 +1,52 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.ArrayList; +import java.util.List; + +import org.mybatis.generator.api.GeneratedJavaFile; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.CompilationUnit; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.config.PropertyRegistry; + +public abstract class AbstractJavaGeneratorPlugin extends AbstractGeneratorPlugin { + + @Override + public abstract AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable); + + @Override + public List contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) { + AbstractJavaGenerator generator = getGenerator(introspectedTable); + if (generator == null) { + return new ArrayList<>(0); + } + initGenerator(generator, introspectedTable); + + List answer = new ArrayList<>(); + List compilationUnits = generator.getCompilationUnits(); + for (CompilationUnit compilationUnit : compilationUnits) { + GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit, + getProject(), + context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING), + context.getJavaFormatter()); + answer.add(gjf); + } + return answer; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractXmlGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractXmlGeneratorPlugin.java new file mode 100644 index 0000000000..b359ed6eb8 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AbstractXmlGeneratorPlugin.java @@ -0,0 +1,87 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.ArrayList; +import java.util.List; + +import org.mybatis.generator.api.GeneratedXmlFile; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.xml.Document; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.AbstractXmlGenerator; + +public abstract class AbstractXmlGeneratorPlugin extends AbstractGeneratorPlugin { + + private ClientCompositePlugin clientPlugin; + + public AbstractXmlGeneratorPlugin(ClientCompositePlugin clientPlugin) { + super(); + this.clientPlugin = clientPlugin; + } + + public ClientCompositePlugin getClientPlugin() { + return clientPlugin; + } + + public void setClientPlugin(MyBatis3ClientCompositePlugin clientPlugin) { + this.clientPlugin = clientPlugin; + } + + public abstract AbstractXmlGenerator getXmlGenerator(IntrospectedTable introspectedTable); + + @Override + public List contextGenerateAdditionalXmlFiles(IntrospectedTable introspectedTable) { + AbstractXmlGenerator generator = getGenerator(introspectedTable); + if (generator == null) { + return new ArrayList<>(0); + } + initGenerator(generator, introspectedTable); + + List answer = new ArrayList<>(); + Document document = generator.getDocument(); + GeneratedXmlFile gxf = new GeneratedXmlFile(document, + introspectedTable.getMyBatis3XmlMapperFileName(), + introspectedTable.getMyBatis3XmlMapperPackage(), + getProject(), true, context.getXmlFormatter()); + if (context.getPlugins().sqlMapGenerated(gxf, introspectedTable)) { + answer.add(gxf); + } + return answer; + } + + @Override + public AbstractXmlGenerator getGenerator( + IntrospectedTable introspectedTable) { + AbstractXmlGenerator xmlMapperGenerator; + if (getClientPlugin() != null) { + AbstractJavaClientGenerator javaClientGenerator = getClientPlugin().getClientGenerator(introspectedTable); + if (javaClientGenerator == null) { + if (context.getSqlMapGeneratorConfiguration() != null) { + xmlMapperGenerator = getXmlGenerator(introspectedTable); + } else { + xmlMapperGenerator = null; + } + } else { + xmlMapperGenerator = javaClientGenerator.getMatchedXMLGenerator(); + } + } else { + xmlMapperGenerator = getXmlGenerator(introspectedTable); + } + return xmlMapperGenerator; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AnnotatedClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AnnotatedClientGeneratorPlugin.java new file mode 100644 index 0000000000..1756f448ff --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/AnnotatedClientGeneratorPlugin.java @@ -0,0 +1,35 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.mybatis3.javamapper.AnnotatedClientGenerator; + +public class AnnotatedClientGeneratorPlugin extends AbstractJavaClientGeneratorPlugin { + + public static final String TYPE_ANNOTATEDMAPPER = "ANNOTATEDMAPPER"; + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + if (TYPE_ANNOTATEDMAPPER.equalsIgnoreCase(getType())) { + return new AnnotatedClientGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/BaseRecordGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/BaseRecordGeneratorPlugin.java new file mode 100644 index 0000000000..628e4e07ae --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/BaseRecordGeneratorPlugin.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.codegen.mybatis3.model.BaseRecordGenerator; + +public class BaseRecordGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + if (introspectedTable.getRules().generateBaseRecordClass()) { + return new BaseRecordGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ClientCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ClientCompositePlugin.java new file mode 100644 index 0000000000..e22f320261 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ClientCompositePlugin.java @@ -0,0 +1,52 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.List; + +import org.mybatis.generator.api.CompositePlugin; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; + +public class ClientCompositePlugin extends CompositePlugin { + + protected final List generatorPlugins; + + public ClientCompositePlugin(List generatorPlugins) { + for (AbstractJavaClientGeneratorPlugin plugin : generatorPlugins) { + super.addPlugin(plugin); + } + this.generatorPlugins = generatorPlugins; + } + + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + AbstractJavaClientGenerator generator = null; + for (AbstractJavaClientGeneratorPlugin plugin : generatorPlugins) { + generator = plugin.getGenerator(introspectedTable); + if (generator != null) { + break; + } + } + return generator; + } + + @Override + public boolean validate(List warnings) { + return true; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CustomJavaClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CustomJavaClientGeneratorPlugin.java new file mode 100644 index 0000000000..d54011604d --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/CustomJavaClientGeneratorPlugin.java @@ -0,0 +1,56 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.internal.ObjectFactory; +import org.mybatis.generator.internal.util.StringUtility; + +public class CustomJavaClientGeneratorPlugin + extends AbstractJavaClientGeneratorPlugin { + + public static final Set PREDEFINED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + JavaMapperGeneratorPlugin.TYPE_MAPPER, + JavaMapperGeneratorPlugin.TYPE_XMLMAPPER, + MixedClientGeneratorPlugin.TYPE_MIXEDMAPPER, + AnnotatedClientGeneratorPlugin.TYPE_ANNOTATEDMAPPER))); + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + String type = null; + if (context.getJavaClientGeneratorConfiguration() != null) { + type = context.getJavaClientGeneratorConfiguration() + .getConfigurationType(); + } else { + //get type from plugin properties config + type = properties.getProperty("type"); + } + if (StringUtility.stringHasValue(type) + && !PREDEFINED_TYPES.contains(type)) { + return (AbstractJavaClientGenerator) ObjectFactory + .createInternalObject(type); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlMapperGeneratorPlugin.java new file mode 100644 index 0000000000..5fdb9413bd --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlMapperGeneratorPlugin.java @@ -0,0 +1,37 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.runtime.dynamic.sql.DynamicSqlMapperGenerator; + +public class DynamicSqlMapperGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + return context.getJavaClientGeneratorConfiguration() != null + ? new DynamicSqlMapperGenerator(getProject()) : null; + } + + @Override + public boolean dynamicSqlSupportGenerated(TopLevelClass supportClass, IntrospectedTable introspectedTable) { + //DynamicSqlMapperGenerator will not gen dynamicSqlSupport + return false; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlModelGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlModelGeneratorPlugin.java new file mode 100644 index 0000000000..7b28e1e3eb --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlModelGeneratorPlugin.java @@ -0,0 +1,29 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.runtime.dynamic.sql.DynamicSqlModelGenerator; + +public class DynamicSqlModelGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + return new DynamicSqlModelGenerator(getProject()); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlSupportClassGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlSupportClassGeneratorPlugin.java new file mode 100644 index 0000000000..4fd47cf83c --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/DynamicSqlSupportClassGeneratorPlugin.java @@ -0,0 +1,30 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.runtime.dynamic.sql.DynamicSqlSupportClassGenerator; + +public class DynamicSqlSupportClassGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + return context.getJavaClientGeneratorConfiguration() != null + ? new DynamicSqlSupportClassGenerator(getProject()) : null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ExampleGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ExampleGeneratorPlugin.java new file mode 100644 index 0000000000..5157c626b4 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/ExampleGeneratorPlugin.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.codegen.mybatis3.model.ExampleGenerator; + +public class ExampleGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + if (introspectedTable.getRules().generateExampleClass()) { + return new ExampleGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/JavaMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/JavaMapperGeneratorPlugin.java new file mode 100644 index 0000000000..201d8b3b77 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/JavaMapperGeneratorPlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.mybatis3.javamapper.JavaMapperGenerator; + +public class JavaMapperGeneratorPlugin extends AbstractJavaClientGeneratorPlugin { + + public static final String TYPE_XMLMAPPER = "XMLMAPPER"; + + public static final String TYPE_MAPPER = "MAPPER"; + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + if (TYPE_XMLMAPPER.equalsIgnoreCase(getType()) + || TYPE_MAPPER.equalsIgnoreCase(getType())) { + return new JavaMapperGenerator(getProject(), true); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinCompositePlugin.java new file mode 100644 index 0000000000..f26c583ebb --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinCompositePlugin.java @@ -0,0 +1,35 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.List; + +import org.mybatis.generator.api.CompositePlugin; + +public class KotlinCompositePlugin extends CompositePlugin { + + public KotlinCompositePlugin() { + super.addPlugin(new KotlinDataClassGeneratorPlugin()); + super.addPlugin(new KotlinMapperGeneratorPlugin()); + super.addPlugin(new KotlinDynamicSqlSupportClassGeneratorPlugin()); + } + + @Override + public boolean validate(List warnings) { + return true; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDataClassGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDataClassGeneratorPlugin.java new file mode 100644 index 0000000000..b569af4bec --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDataClassGeneratorPlugin.java @@ -0,0 +1,30 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractKotlinGenerator; +import org.mybatis.generator.runtime.kotlin.KotlinDataClassGenerator; + +public class KotlinDataClassGeneratorPlugin extends AbstracKotlinGeneratorPlugin { + + @Override + public AbstractKotlinGenerator getGenerator( + IntrospectedTable introspectedTable) { + return new KotlinDataClassGenerator(getProject()); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDynamicSqlSupportClassGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDynamicSqlSupportClassGeneratorPlugin.java new file mode 100644 index 0000000000..6855ea7194 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinDynamicSqlSupportClassGeneratorPlugin.java @@ -0,0 +1,47 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.kotlin.KotlinFile; +import org.mybatis.generator.codegen.AbstractKotlinGenerator; +import org.mybatis.generator.runtime.kotlin.KotlinDynamicSqlSupportClassGenerator; + +public class KotlinDynamicSqlSupportClassGeneratorPlugin + extends AbstracKotlinGeneratorPlugin { + + @Override + public AbstractKotlinGenerator getGenerator( + IntrospectedTable introspectedTable) { + if (context.getJavaClientGeneratorConfiguration() != null + && introspectedTable.getRules().generateJavaClient()) { + return new AbstractKotlinGenerator(null) { + + @Override + public List getKotlinFiles() { + return Arrays.asList(new KotlinDynamicSqlSupportClassGenerator( + context, introspectedTable, warnings).getKotlinFile()); + } + + }; + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinMapperGeneratorPlugin.java new file mode 100644 index 0000000000..282b34c8c2 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/KotlinMapperGeneratorPlugin.java @@ -0,0 +1,44 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.kotlin.KotlinFile; +import org.mybatis.generator.api.dom.kotlin.KotlinType; +import org.mybatis.generator.codegen.AbstractKotlinGenerator; +import org.mybatis.generator.runtime.kotlin.KotlinMapperAndExtensionsGenerator; + +public class KotlinMapperGeneratorPlugin + extends AbstracKotlinGeneratorPlugin { + + @Override + public AbstractKotlinGenerator getGenerator( + IntrospectedTable introspectedTable) { + if (context.getJavaClientGeneratorConfiguration() != null + && introspectedTable.getRules().generateJavaClient()) { + return new KotlinMapperAndExtensionsGenerator(getProject()); + } + return null; + } + + @Override + public boolean dynamicSqlSupportGenerated(KotlinFile kotlinFile, + KotlinType outerSupportObject, KotlinType innerSupportClass, + IntrospectedTable introspectedTable) { + return false; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedClientGeneratorPlugin.java new file mode 100644 index 0000000000..0f80acffce --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedClientGeneratorPlugin.java @@ -0,0 +1,35 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.mybatis3.javamapper.MixedClientGenerator; + +public class MixedClientGeneratorPlugin extends AbstractJavaClientGeneratorPlugin { + + public static final String TYPE_MIXEDMAPPER = "MIXEDMAPPER"; + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + if (TYPE_MIXEDMAPPER.equalsIgnoreCase(getType())) { + return new MixedClientGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedMapperGeneratorPlugin.java new file mode 100644 index 0000000000..424c7b6f34 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MixedMapperGeneratorPlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractXmlGenerator; +import org.mybatis.generator.codegen.mybatis3.xmlmapper.MixedMapperGenerator; + +public class MixedMapperGeneratorPlugin extends AbstractXmlGeneratorPlugin { + + public MixedMapperGeneratorPlugin() { + this(null); + } + + public MixedMapperGeneratorPlugin(MyBatis3ClientCompositePlugin clientPlugin) { + super(clientPlugin); + } + + @Override + public AbstractXmlGenerator getXmlGenerator( + IntrospectedTable introspectedTable) { + return new MixedMapperGenerator(); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3ClientCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3ClientCompositePlugin.java new file mode 100644 index 0000000000..b94970d285 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3ClientCompositePlugin.java @@ -0,0 +1,29 @@ +/* + * Copyright 2006-2023 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 + * + * https://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; + +public class MyBatis3ClientCompositePlugin extends ClientCompositePlugin { + + public MyBatis3ClientCompositePlugin() { + super(Arrays.asList(new JavaMapperGeneratorPlugin(), + new MixedClientGeneratorPlugin(), + new AnnotatedClientGeneratorPlugin(), + new CustomJavaClientGeneratorPlugin())); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3CompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3CompositePlugin.java new file mode 100644 index 0000000000..d5129c5fa7 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3CompositePlugin.java @@ -0,0 +1,41 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.List; + +import org.mybatis.generator.api.CompositePlugin; + +public class MyBatis3CompositePlugin extends CompositePlugin { + + public MyBatis3CompositePlugin() { + super.addPlugin(new ExampleGeneratorPlugin()); + super.addPlugin(new PrimaryKeyGeneratorPlugin()); + super.addPlugin(new BaseRecordGeneratorPlugin()); + super.addPlugin(new RecordWithBLOBsGeneratorPlugin()); + + MyBatis3ClientCompositePlugin clientPlugin = new MyBatis3ClientCompositePlugin(); + super.addPlugin(clientPlugin); + + super.addPlugin(new XMLMapperGeneratorPlugin(clientPlugin)); + } + + @Override + public boolean validate(List warnings) { + return true; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3DynamicSqlCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3DynamicSqlCompositePlugin.java new file mode 100644 index 0000000000..2c15cb8372 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3DynamicSqlCompositePlugin.java @@ -0,0 +1,35 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.List; + +import org.mybatis.generator.api.CompositePlugin; + +public class MyBatis3DynamicSqlCompositePlugin extends CompositePlugin { + + public MyBatis3DynamicSqlCompositePlugin() { + super.addPlugin(new DynamicSqlModelGeneratorPlugin()); + super.addPlugin(new DynamicSqlMapperGeneratorPlugin()); + super.addPlugin(new DynamicSqlSupportClassGeneratorPlugin()); + } + + @Override + public boolean validate(List warnings) { + return true; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleClientCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleClientCompositePlugin.java new file mode 100644 index 0000000000..dbfaf54af2 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleClientCompositePlugin.java @@ -0,0 +1,28 @@ +/* + * Copyright 2006-2023 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 + * + * https://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; + +public class MyBatis3SimpleClientCompositePlugin extends ClientCompositePlugin { + + public MyBatis3SimpleClientCompositePlugin() { + super(Arrays.asList(new SimpleJavaClientGeneratorPlugin(), + new SimpleAnnotatedClientGeneratorPlugin(), + new CustomJavaClientGeneratorPlugin())); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleCompositePlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleCompositePlugin.java new file mode 100644 index 0000000000..9b638c5dae --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/MyBatis3SimpleCompositePlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006-2023 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 + * + * https://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.List; + +import org.mybatis.generator.api.CompositePlugin; + +public class MyBatis3SimpleCompositePlugin extends CompositePlugin { + + public MyBatis3SimpleCompositePlugin() { + super.addPlugin(new SimpleModelGeneratorPlugin()); + + MyBatis3SimpleClientCompositePlugin simplePlugin = new MyBatis3SimpleClientCompositePlugin(); + super.addPlugin(simplePlugin); + + super.addPlugin(new SimpleXMLMapperGeneratorPlugin(simplePlugin)); + } + + @Override + public boolean validate(List warnings) { + return true; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/PrimaryKeyGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/PrimaryKeyGeneratorPlugin.java new file mode 100644 index 0000000000..976f3007f5 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/PrimaryKeyGeneratorPlugin.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.codegen.mybatis3.model.PrimaryKeyGenerator; + +public class PrimaryKeyGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + if (introspectedTable.getRules().generatePrimaryKeyClass()) { + return new PrimaryKeyGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/RecordWithBLOBsGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/RecordWithBLOBsGeneratorPlugin.java new file mode 100644 index 0000000000..75f6a98239 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/RecordWithBLOBsGeneratorPlugin.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.codegen.mybatis3.model.RecordWithBLOBsGenerator; + +public class RecordWithBLOBsGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator(IntrospectedTable introspectedTable) { + if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { + return new RecordWithBLOBsGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleAnnotatedClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleAnnotatedClientGeneratorPlugin.java new file mode 100644 index 0000000000..20f4a16e0d --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleAnnotatedClientGeneratorPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.mybatis3.javamapper.SimpleAnnotatedClientGenerator; + +public class SimpleAnnotatedClientGeneratorPlugin extends AbstractJavaClientGeneratorPlugin { + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + if (AnnotatedClientGeneratorPlugin.TYPE_ANNOTATEDMAPPER.equalsIgnoreCase(getType())) { + return new SimpleAnnotatedClientGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleJavaClientGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleJavaClientGeneratorPlugin.java new file mode 100644 index 0000000000..f1b841bcb7 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleJavaClientGeneratorPlugin.java @@ -0,0 +1,34 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaClientGenerator; +import org.mybatis.generator.codegen.mybatis3.javamapper.SimpleJavaClientGenerator; + +public class SimpleJavaClientGeneratorPlugin extends AbstractJavaClientGeneratorPlugin { + + @Override + public AbstractJavaClientGenerator getClientGenerator( + IntrospectedTable introspectedTable) { + if (JavaMapperGeneratorPlugin.TYPE_XMLMAPPER.equalsIgnoreCase(getType()) + || JavaMapperGeneratorPlugin.TYPE_MAPPER.equalsIgnoreCase(getType())) { + return new SimpleJavaClientGenerator(getProject()); + } + return null; + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleModelGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleModelGeneratorPlugin.java new file mode 100644 index 0000000000..0d157eeb65 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleModelGeneratorPlugin.java @@ -0,0 +1,30 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractJavaGenerator; +import org.mybatis.generator.codegen.mybatis3.model.SimpleModelGenerator; + +public class SimpleModelGeneratorPlugin extends AbstractJavaGeneratorPlugin { + + @Override + public AbstractJavaGenerator getGenerator( + IntrospectedTable introspectedTable) { + return new SimpleModelGenerator(getProject()); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleXMLMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleXMLMapperGeneratorPlugin.java new file mode 100644 index 0000000000..7c7561f404 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/SimpleXMLMapperGeneratorPlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractXmlGenerator; +import org.mybatis.generator.codegen.mybatis3.xmlmapper.SimpleXMLMapperGenerator; + +public class SimpleXMLMapperGeneratorPlugin extends AbstractXmlGeneratorPlugin { + + public SimpleXMLMapperGeneratorPlugin() { + this(null); + } + + public SimpleXMLMapperGeneratorPlugin(ClientCompositePlugin clientPlugin) { + super(clientPlugin); + } + + @Override + public AbstractXmlGenerator getXmlGenerator( + IntrospectedTable introspectedTable) { + return new SimpleXMLMapperGenerator(); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/XMLMapperGeneratorPlugin.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/XMLMapperGeneratorPlugin.java new file mode 100644 index 0000000000..514fddaed8 --- /dev/null +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/XMLMapperGeneratorPlugin.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006-2023 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 + * + * https://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 org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.codegen.AbstractXmlGenerator; +import org.mybatis.generator.codegen.mybatis3.xmlmapper.XMLMapperGenerator; + +public class XMLMapperGeneratorPlugin extends AbstractXmlGeneratorPlugin { + + public XMLMapperGeneratorPlugin() { + this(null); + } + + public XMLMapperGeneratorPlugin(MyBatis3ClientCompositePlugin clientPlugin) { + super(clientPlugin); + } + + @Override + public AbstractXmlGenerator getXmlGenerator( + IntrospectedTable introspectedTable) { + return new XMLMapperGenerator(); + } + +} diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlMapperGenerator.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlMapperGenerator.java index aebb95a1a4..940652e58b 100644 --- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlMapperGenerator.java +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlMapperGenerator.java @@ -163,8 +163,12 @@ protected Interface createBasicInterface() { } protected TopLevelClass getSupportClass() { - return DynamicSqlSupportClassGenerator.of( - introspectedTable, context.getCommentGenerator(), warnings).generate(); + DynamicSqlSupportClassGenerator generator = new DynamicSqlSupportClassGenerator(getProject()); + generator.setContext(context); + generator.setIntrospectedTable(introspectedTable); + generator.setWarnings(warnings); + generator.setProgressCallback(progressCallback); + return generator.generate(); } protected void addInsertOneMethod(Interface interfaze) { diff --git a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java index 92f74c6a8a..4be5b71160 100644 --- a/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java +++ b/core/mybatis-generator-core/src/main/java/org/mybatis/generator/runtime/dynamic/sql/DynamicSqlSupportClassGenerator.java @@ -18,29 +18,27 @@ import static org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities.getEscapedColumnName; import static org.mybatis.generator.internal.util.StringUtility.escapeStringForJava; +import java.util.Arrays; import java.util.List; -import org.mybatis.generator.api.CommentGenerator; import org.mybatis.generator.api.IntrospectedColumn; -import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.CompilationUnit; import org.mybatis.generator.api.dom.java.Field; import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; import org.mybatis.generator.api.dom.java.InnerClass; import org.mybatis.generator.api.dom.java.JavaVisibility; import org.mybatis.generator.api.dom.java.Method; import org.mybatis.generator.api.dom.java.TopLevelClass; +import org.mybatis.generator.codegen.AbstractJavaGenerator; import org.mybatis.generator.config.PropertyRegistry; import org.mybatis.generator.internal.util.JavaBeansUtil; import org.mybatis.generator.internal.util.StringUtility; import org.mybatis.generator.internal.util.messages.Messages; -public class DynamicSqlSupportClassGenerator { - private IntrospectedTable introspectedTable; - private CommentGenerator commentGenerator; - private List warnings; +public class DynamicSqlSupportClassGenerator extends AbstractJavaGenerator { - private DynamicSqlSupportClassGenerator() { - super(); + public DynamicSqlSupportClassGenerator(String project) { + super(project); } public TopLevelClass generate() { @@ -90,7 +88,7 @@ private InnerClass buildInnerTableClass(TopLevelClass topLevelClass) { + ");"); //$NON-NLS-1$ innerClass.addMethod(method); - commentGenerator.addClassAnnotation(innerClass, introspectedTable, topLevelClass.getImportedTypes()); + context.getCommentGenerator().addClassAnnotation(innerClass, introspectedTable, topLevelClass.getImportedTypes()); return innerClass; } @@ -101,7 +99,7 @@ private Field calculateTableDefinition(TopLevelClass topLevelClass) { String fieldName = JavaBeansUtil.getValidPropertyName(introspectedTable.getMyBatisDynamicSQLTableObjectName()); Field field = new Field(fieldName, fqjt); - commentGenerator.addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes()); + context.getCommentGenerator().addFieldAnnotation(field, introspectedTable, topLevelClass.getImportedTypes()); field.setVisibility(JavaVisibility.PUBLIC); field.setStatic(true); field.setFinal(true); @@ -138,7 +136,7 @@ private void handleColumn(TopLevelClass topLevelClass, InnerClass innerClass, field.setStatic(true); field.setFinal(true); field.setInitializationString(tableFieldName + "." + fieldName); //$NON-NLS-1$ - commentGenerator.addFieldAnnotation(field, introspectedTable, column, topLevelClass.getImportedTypes()); + context.getCommentGenerator().addFieldAnnotation(field, introspectedTable, column, topLevelClass.getImportedTypes()); topLevelClass.addField(field); } @@ -178,12 +176,8 @@ private String calculateInnerInitializationString(IntrospectedColumn column, Ful return initializationString.toString(); } - public static DynamicSqlSupportClassGenerator of(IntrospectedTable introspectedTable, - CommentGenerator commentGenerator, List warnings) { - DynamicSqlSupportClassGenerator generator = new DynamicSqlSupportClassGenerator(); - generator.introspectedTable = introspectedTable; - generator.commentGenerator = commentGenerator; - generator.warnings = warnings; - return generator; + @Override + public List getCompilationUnits() { + return Arrays.asList(generate()); } } diff --git a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/JavaCodeGenerationTest.java b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/JavaCodeGenerationTest.java index 571f56897b..504f3ee9c7 100644 --- a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/JavaCodeGenerationTest.java +++ b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/JavaCodeGenerationTest.java @@ -51,8 +51,31 @@ void testJavaParse(GeneratedJavaFile generatedJavaFile) { static List javaFileGenerator() throws Exception { List generatedFiles = new ArrayList<>(); - generatedFiles.addAll(generateJavaFilesMybatis()); - generatedFiles.addAll(generateJavaFilesMybatisDsql()); + List mybatisFiles = generateJavaFilesMybatis(); + generatedFiles.addAll(mybatisFiles); + List mybatisFiles2 = generateJavaFilesMybatis2(); + generatedFiles.addAll(mybatisFiles2); + + assertEquals(mybatisFiles.size(), mybatisFiles2.size()); + int size = mybatisFiles.size(); + for (int i = 0; i < size; i++) { + assertEquals(mybatisFiles.get(i).getFormattedContent(), + mybatisFiles2.get(i).getFormattedContent()); + } + + + List dsqlFiles = generateJavaFilesMybatisDsql(); + generatedFiles.addAll(dsqlFiles); + List dsql2Files = generateJavaFilesMybatisDsql2(); + generatedFiles.addAll(dsql2Files); + + assertEquals(dsqlFiles.size(), dsql2Files.size()); + int dsize = dsqlFiles.size(); + for (int i = 0; i < dsize; i++) { + assertEquals(dsqlFiles.get(i).getFormattedContent(), + dsql2Files.get(i).getFormattedContent()); + } + return generatedFiles; } @@ -61,11 +84,21 @@ static List generateJavaFilesMybatis() throws Exception { return generateJavaFiles("/scripts/generatorConfig.xml"); } + static List generateJavaFilesMybatis2() throws Exception { + createDatabase(); + return generateJavaFiles("/scripts/generatorConfig2.xml"); + } + static List generateJavaFilesMybatisDsql() throws Exception { createDatabase(); return generateJavaFiles("/scripts/generatorConfig_Dsql.xml"); } + static List generateJavaFilesMybatisDsql2() throws Exception { + createDatabase(); + return generateJavaFiles("/scripts/generatorConfig_Dsql2.xml"); + } + static List generateJavaFiles(String configFile) throws Exception { List warnings = new ArrayList<>(); ConfigurationParser cp = new ConfigurationParser(warnings); diff --git a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/KotlinCodeGenerationTest.java b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/KotlinCodeGenerationTest.java index 518218f122..2edc80876e 100644 --- a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/KotlinCodeGenerationTest.java +++ b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/KotlinCodeGenerationTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import org.junit.jupiter.params.ParameterizedTest; @@ -48,10 +49,32 @@ void testKotlinParse(GeneratedKotlinFile generatedKotlinFile) { } static List kotlinFileGenerator() throws Exception { + List allFiles = new ArrayList<>(); + List files = generateKotlinFiles(); + allFiles.addAll(files); + List files2 = generateKotlinFiles2(); + allFiles.addAll(files2); + + assertEquals(files.size(), files2.size()); + int size = files.size(); + for (int i = 0; i < size; i++) { + assertEquals(files.get(i).getFormattedContent(), + files2.get(i).getFormattedContent()); + } + + return allFiles; + } + + static List generateKotlinFiles() throws Exception { JavaCodeGenerationTest.createDatabase(); return generateKotlinFiles("/scripts/generatorConfig-kotlin.xml"); } + static List generateKotlinFiles2() throws Exception { + JavaCodeGenerationTest.createDatabase(); + return generateKotlinFiles("/scripts/generatorConfig-kotlin2.xml"); + } + static List generateKotlinFiles(String configFile) throws Exception { List warnings = new ArrayList<>(); ConfigurationParser cp = new ConfigurationParser(warnings); @@ -60,7 +83,9 @@ static List generateKotlinFiles(String configFile) throws E DefaultShellCallback shellCallback = new DefaultShellCallback(true); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); - myBatisGenerator.generate(null, null, null, false); + HashSet ctxIds = new HashSet<>(); + ctxIds.add("kotlin-modelonly"); + myBatisGenerator.generate(null, ctxIds, null, false); return myBatisGenerator.getGeneratedKotlinFiles(); } } diff --git a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/XmlCodeGenerationTest.java b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/XmlCodeGenerationTest.java index f465c6f529..8327ba1b1f 100644 --- a/core/mybatis-generator-core/src/test/java/org/mybatis/generator/XmlCodeGenerationTest.java +++ b/core/mybatis-generator-core/src/test/java/org/mybatis/generator/XmlCodeGenerationTest.java @@ -62,8 +62,20 @@ static List xmlFileGenerator() throws Exception { } static List generateXmlFilesMybatis() throws Exception { + List allFiles = new ArrayList<>(); JavaCodeGenerationTest.createDatabase(); - return generateXmlFiles("/scripts/generatorConfig.xml"); + List xmlFiles = generateXmlFiles("/scripts/generatorConfig.xml"); + allFiles.addAll(xmlFiles); + List xml2Files = generateXmlFiles("/scripts/generatorConfig2.xml"); + allFiles.addAll(xml2Files); + + assertEquals(xmlFiles.size(), xml2Files.size()); + int size = xmlFiles.size(); + for (int i = 0; i < size; i++) { + assertEquals(xmlFiles.get(i).getFormattedContent(), + xml2Files.get(i).getFormattedContent()); + } + return allFiles; } static List generateXmlFiles(String configFile) throws Exception { diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin.xml index f2a8d0a666..f103b123ab 100644 --- a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin.xml +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin.xml @@ -25,6 +25,10 @@ + + + + @@ -80,6 +84,10 @@ + + + + @@ -126,6 +134,10 @@ + + + + @@ -178,6 +190,10 @@ + + + + diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin2.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin2.xml new file mode 100644 index 0000000000..617aff5100 --- /dev/null +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig-kotlin2.xml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + +
+ + +
+ +
+
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + +
+ + + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+
+ + + + + + + + + + + + + + +
+
+
diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig.xml index d96d5fd563..d785664fc1 100644 --- a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig.xml +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig.xml @@ -29,6 +29,10 @@ + + + + @@ -137,6 +141,10 @@ + + + + @@ -256,6 +264,10 @@ + + + + @@ -276,6 +288,10 @@ + + + + @@ -290,6 +306,10 @@ + + + + @@ -314,6 +334,10 @@ + + + + @@ -345,6 +369,10 @@ + + + + @@ -379,6 +407,10 @@ + + + + @@ -422,6 +454,10 @@ + + + + @@ -465,6 +501,10 @@ + + + + @@ -565,6 +605,10 @@ + + + + @@ -593,6 +637,10 @@ + + + + @@ -639,6 +687,10 @@ + + + + @@ -686,6 +738,10 @@ + + + + @@ -783,6 +839,10 @@ + + + + @@ -816,6 +876,10 @@ + + + + @@ -866,6 +930,10 @@ + + + + @@ -910,6 +978,10 @@ + + + + diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig2.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig2.xml new file mode 100644 index 0000000000..607c6c1c37 --- /dev/null +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig2.xml @@ -0,0 +1,1082 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
+
+ + + + + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + +
+ + + +
+ + +
+ + +
+ + + +
+ + + +
+ + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + +
+ + + +
+ + +
+ + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + +
+ + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + +
+ + diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql.xml index 56d6d14c4b..0e47db079f 100644 --- a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql.xml +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql.xml @@ -24,6 +24,10 @@ + + + + @@ -81,6 +85,10 @@ + + + + @@ -183,6 +191,10 @@ + + + + diff --git a/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql2.xml b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql2.xml new file mode 100644 index 0000000000..729d040558 --- /dev/null +++ b/core/mybatis-generator-core/src/test/resources/scripts/generatorConfig_Dsql2.xml @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + +
+ + +
+ +
+
+ + + + + + + + + + + + + + +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + +
+ + + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+
+ + + + + + + + + + + + + + +
+
+