All Downloads are FREE. Search and download functionalities are using the official Maven repository.

enhanced.mybaits.generator.GeneratorExecutor Maven / Gradle / Ivy


package enhanced.mybaits.generator;

import enhanced.mybaits.generator.codegen.AbstratEnhanceJavaGenerator;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.PropertyRegistry;

import java.util.ArrayList;
import java.util.List;

/**
 * 生成器执行者
 * @author 徐明龙 XuMingLong 
 */
public class GeneratorExecutor {
    private List javaGeneratorList;
    
    protected Context context;
    
    protected IntrospectedTable table;
    
    private List warnings;
    
    private EnhanceProgressCallback callback = new EnhanceProgressCallback(); 
    
    public GeneratorExecutor() {
        javaGeneratorList = new ArrayList<>();
    }
    
    public void setContext(Context context) {
        this.context = context;
    }

    public void setTable(IntrospectedTable table) {
        this.table = table;
    }

    public void setWarnings(List warnings) {
        this.warnings = warnings;
    }

    /**
     * 增加生成器
     * @author 徐明龙 XuMingLong 2018-11-26 
     * @param javaGenerator Java代码生成器
     */
    public void addJavaGenerator(AbstratEnhanceJavaGenerator javaGenerator ) {
        javaGeneratorList.add(javaGenerator);
    }
    
    /**
     * 生成所有文件
     * @author 徐明龙 XuMingLong 2018-11-26 
     * @return  返回生成的Java代码文件列表
     */
    public List generateAllFiles(){
        List answer = new ArrayList();
        for(AbstratEnhanceJavaGenerator generator:javaGeneratorList) {
            initializeAbstractGenerator(generator);
            List compilationUnits = generator.getCompilationUnits();
            for (CompilationUnit compilationUnit : compilationUnits) {
                GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit,
                    generator.getProject(),
                    context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
                    context.getJavaFormatter());
                answer.add(gjf);
            }
        }
        return answer;
    }
    
    /**
     * 初始化构建器
     * @author 徐明龙 XuMingLong 
     * @param abstractGenerator 待初始的构建器
     */
    protected void initializeAbstractGenerator(AbstratEnhanceJavaGenerator abstractGenerator) {
        abstractGenerator.setContext(context);
        abstractGenerator.setIntrospectedTable(table);
        abstractGenerator.setProgressCallback(callback);
        abstractGenerator.setWarnings(warnings);
    }

    /**
     *  初始化Java代码生成器
     * @author 徐明龙 XuMingLong
     * @param introspectedTable
     * @return void
     */
    public void initializeJavaGenerator(IntrospectedTable introspectedTable) {
        this.javaGeneratorList.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy