扩展Execute类,新增execute(DatabaseQuery query)方法;用户通过继承AbstractDatabaseQuery类,可自定义数据来源,实现自动生成数据库模板

This commit is contained in:
lvchao@yunlizhihui.com
2021-11-10 14:24:44 +08:00
parent 70bc83a4be
commit 29004d1178
5 changed files with 65 additions and 13 deletions

View File

@@ -23,13 +23,13 @@ import cn.smallbun.screw.core.engine.TemplateEngine;
import cn.smallbun.screw.core.exception.BuilderException; import cn.smallbun.screw.core.exception.BuilderException;
import cn.smallbun.screw.core.metadata.model.DataModel; import cn.smallbun.screw.core.metadata.model.DataModel;
import cn.smallbun.screw.core.process.DataModelProcess; import cn.smallbun.screw.core.process.DataModelProcess;
import cn.smallbun.screw.core.query.DatabaseQuery;
import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.ExceptionUtils;
/** /**
* 文档生成 * 文档生成
* *
* @author SanLi * @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:51
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:51
*/ */
public class DocumentationExecute extends AbstractExecute { public class DocumentationExecute extends AbstractExecute {
@@ -42,6 +42,22 @@ public class DocumentationExecute extends AbstractExecute {
* *
* @throws BuilderException BuilderException * @throws BuilderException BuilderException
*/ */
@Override
public void execute(DatabaseQuery query) throws BuilderException {
try {
long start = System.currentTimeMillis();
//处理数据
DataModel dataModel = new DataModelProcess(config).process(query);
//产生文档
TemplateEngine produce = new EngineFactory(config.getEngineConfig()).newInstance();
produce.produce(dataModel, getDocName(dataModel.getDatabase()));
logger.debug("database document generation complete time consuming:{}ms",
System.currentTimeMillis() - start);
} catch (Exception e) {
throw ExceptionUtils.mpe(e);
}
}
@Override @Override
public void execute() throws BuilderException { public void execute() throws BuilderException {
try { try {

View File

@@ -17,15 +17,22 @@
*/ */
package cn.smallbun.screw.core.execute; package cn.smallbun.screw.core.execute;
import cn.smallbun.screw.core.query.DatabaseQuery;
/** /**
* 执行文档生成 * 执行文档生成
* *
* @author SanLi * @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:38
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:38
*/ */
public interface Execute { public interface Execute {
/** /**
* 执行生成 * 执行生成
*/ */
void execute(); void execute();
/**
* 执行生成
* @param query 自定义查询器
*/
void execute(DatabaseQuery query);
} }

View File

@@ -17,6 +17,10 @@
*/ */
package cn.smallbun.screw.core.process; package cn.smallbun.screw.core.process;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import cn.smallbun.screw.core.Configuration; import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Column;
import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.Database;
@@ -29,11 +33,10 @@ import cn.smallbun.screw.core.query.DatabaseQuery;
import cn.smallbun.screw.core.query.DatabaseQueryFactory; import cn.smallbun.screw.core.query.DatabaseQueryFactory;
import cn.smallbun.screw.core.util.StringUtils; import cn.smallbun.screw.core.util.StringUtils;
import java.util.ArrayList; import static cn.smallbun.screw.core.constant.DefaultConstants.N;
import java.util.List; import static cn.smallbun.screw.core.constant.DefaultConstants.Y;
import java.util.stream.Collectors; import static cn.smallbun.screw.core.constant.DefaultConstants.ZERO;
import static cn.smallbun.screw.core.constant.DefaultConstants.ZERO_DECIMAL_DIGITS;
import static cn.smallbun.screw.core.constant.DefaultConstants.*;
/** /**
* 数据模型处理 * 数据模型处理
@@ -61,6 +64,18 @@ public class DataModelProcess extends AbstractProcess {
public DataModel process() { public DataModel process() {
//获取query对象 //获取query对象
DatabaseQuery query = new DatabaseQueryFactory(config.getDataSource()).newInstance(); DatabaseQuery query = new DatabaseQueryFactory(config.getDataSource()).newInstance();
return this.process(query);
}
/**
* 处理
*
* @return {@link DataModel}
*/
@Override
public DataModel process(DatabaseQuery query) {
//获取query对象
DataModel model = new DataModel(); DataModel model = new DataModel();
//Title //Title
model.setTitle(config.getTitle()); model.setTitle(config.getTitle());

View File

@@ -17,15 +17,15 @@
*/ */
package cn.smallbun.screw.core.process; package cn.smallbun.screw.core.process;
import cn.smallbun.screw.core.metadata.model.DataModel;
import java.io.Serializable; import java.io.Serializable;
import cn.smallbun.screw.core.metadata.model.DataModel;
import cn.smallbun.screw.core.query.DatabaseQuery;
/** /**
* 构建 * 构建
* *
* @author SanLi * @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/3/22 21:08
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/3/22 21:08
*/ */
public interface Process extends Serializable { public interface Process extends Serializable {
/** /**
@@ -35,4 +35,12 @@ public interface Process extends Serializable {
* @throws Exception Exception * @throws Exception Exception
*/ */
DataModel process() throws Exception; DataModel process() throws Exception;
/**
* 自定义处理
* @param query 自定义查询器
* @return {@link DataModel}
* @throws Exception Exception
*/
DataModel process(DatabaseQuery query) throws Exception;
} }

View File

@@ -19,6 +19,7 @@ package cn.smallbun.screw.extension.pojo.execute;
import cn.smallbun.screw.core.exception.ScrewException; import cn.smallbun.screw.core.exception.ScrewException;
import cn.smallbun.screw.core.execute.Execute; import cn.smallbun.screw.core.execute.Execute;
import cn.smallbun.screw.core.query.DatabaseQuery;
import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.ExceptionUtils;
import cn.smallbun.screw.core.util.StringUtils; import cn.smallbun.screw.core.util.StringUtils;
import cn.smallbun.screw.extension.pojo.PojoConfiguration; import cn.smallbun.screw.extension.pojo.PojoConfiguration;
@@ -89,6 +90,11 @@ public class PojoExecute implements Execute {
} }
} }
@Override
public void execute(DatabaseQuery query) {
}
private String validate(PojoConfiguration config) { private String validate(PojoConfiguration config) {
StringBuilder error = new StringBuilder(); StringBuilder error = new StringBuilder();
String separator = System.lineSeparator(); String separator = System.lineSeparator();