cn.cliveyuan.robin.generator.impl.MybatisGenerator Maven / Gradle / Ivy
package cn.cliveyuan.robin.generator.impl;
import cn.cliveyuan.robin.generator.RobinGenerator;
import cn.cliveyuan.robin.generator.core.GeneratorChain;
import cn.cliveyuan.robin.generator.core.GeneratorContext;
import cn.cliveyuan.robin.generator.core.GeneratorContextResolver;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
/**
* @author Clive Yuan
* @date 2020/12/23
*/
@Slf4j
public class MybatisGenerator implements RobinGenerator {
/**
* 配置文件路径 (默认值为"/code-generator.xml")
*/
private final String configFilePath;
@Builder
public MybatisGenerator(String configFilePath) {
this.configFilePath = configFilePath;
}
@Override
public void generate() {
log.info("MybatisGenerator.generate [START] customized configFilePath is {}", configFilePath);
long start = System.currentTimeMillis();
// 初始化上下文解析器
GeneratorContextResolver generatorContextResolver = new GeneratorContextResolver();
// 解析配置上下文
GeneratorContext generatorContext = generatorContextResolver.resolve(configFilePath);
// 创建生成链路
GeneratorChain generatorChain = new GeneratorChain();
// 执行生成链路
generatorChain.generate(generatorContext, generatorChain);
log.info("MybatisGenerator.generate [SUCCESS] cost {}ms", System.currentTimeMillis() - start);
}
}