org.sagacity.quickvo.MavenQuickVOPlugin Maven / Gradle / Ivy
package org.sagacity.quickvo;
import static java.lang.System.out;
import java.util.logging.Logger;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.sagacity.quickvo.config.XMLConfigLoader;
import org.sagacity.quickvo.model.ConfigModel;
import org.sagacity.quickvo.utils.FreemarkerUtil;
import org.sagacity.quickvo.utils.LoggerUtil;
/**
* sqltoy-quickvo maven插件
*/
@Mojo(name = "quickvo")
public class MavenQuickVOPlugin extends AbstractMojo {
private static Logger logger = null;
@Parameter(name = "configFile", defaultValue = "classpath:quickvo.xml")
private String configFile;
@Parameter(name = "baseDir", defaultValue = "${project.basedir}")
private String baseDir;
@Parameter(name = "loggerFileEncoding", defaultValue = "UTF-8")
private String loggerFileEncoding;
/**
* 开始生成文件
*
* @throws Exception
*/
public void doStart() {
logger = LoggerUtil.getLogger();
try {
out.println("\n\n========= welcome use sagacity-quickvo-5.2.4 ==========");
out.println("/*----友情提示: 遇到问题请关注日志提示,最常见错误有3个: -----------------------*/\n"
+ "/*-1、没有匹配到表: 检查 include 正则表达式配置是否正确 \n"
+ "/*-2、没有匹配到表: 检查 schema和catalog配置是否正确(含大小写),可尝试去除schema、catalog配置项 \n"
+ "/*-3、VO中字段出现重复字段,错误就是schema和catalog配置问题,没有隔离不同schema \n"
+ "/*---------------------------------------------------------------*/\n\n ");
Thread.sleep(1500);
// 解析配置文件
ConfigModel configModel = XMLConfigLoader.parse();
TaskController.setConfigModel(configModel);
// 创建vo和vof
TaskController.create();
FreemarkerUtil.destory();
// 发生表字段重复现象
if (Constants.hasRepeatField) {
Thread.sleep(1000);
logger.info("\n\n\n/*------------任务已结束,生成的VO对象中有重复字段致命性错误,具体原因:---------------------------*/\n"
+ "/*- 就是datasource中的schema 和 catalog 配置问题,导致在多用户多实例环境下隔离不正确!\n"
+ "/*--------------------------处理协助----------------------------------\n"
+ "/*-1、比如mysql场景下可以设置schema和catalog的值一致进行尝试!\n"
+ "/*-2、datasource中是可以配置schema和catalog属性的,如果没有可以自行调整和尝试赋值(不同数据库一般跟用户名,库名、tablespace等相关)!\n"
+ "/*-3、取表字段的内部原理:conn.getMetaData().getColumns(catalog, schema, tableName, \"%\");\n"
+ "/*-------------------------------------------------------------*/");
Thread.sleep(10000);
} else {
logger.info("成功完成vo以及vo<-->po映射类的生成!");
}
} catch (ClassNotFoundException e) {
logger.info("数据库驱动加载失败!请将数据库驱动jar文件放到当前目录libs目录下!" + e.getMessage());
} catch (Exception e) {
logger.info(e.getMessage());
}
}
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Constants.QUICK_CONFIG_FILE = configFile;
if (loggerFileEncoding != null) {
Constants.LOG_FILE_ENCODING = loggerFileEncoding;
}
if (baseDir == null || baseDir.trim().equals("")) {
Constants.BASE_LOCATE = System.getProperty("user.dir");
} else {
Constants.BASE_LOCATE = baseDir;
}
doStart();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy