Merge pull request #39 from lkqm/master

支持文档数据库结构
优化从类路径加载velocity模板.
增加元数据deprecated标记字段.
This commit is contained in:
平凡故事
2021-06-06 17:13:19 +08:00
committed by GitHub
11 changed files with 60 additions and 30 deletions

View File

@@ -7,7 +7,7 @@
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw</artifactId>
<packaging>pom</packaging>
<version>1.0.5</version>
<version>1.0.6-SNAPSHOT</version>
<inceptionYear>2020</inceptionYear>
<name>screw</name>
<description>简洁好用的数据库表结构文档生成工具</description>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw</artifactId>
<version>1.0.5</version>
<version>1.0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>jar</packaging>

View File

@@ -55,4 +55,8 @@ public class EngineConfig implements Serializable {
* 文件名称
*/
private String fileName;
/**
* 模板内容
*/
private String templateContent;
}

View File

@@ -24,6 +24,7 @@ import cn.smallbun.screw.core.metadata.model.DataModel;
import cn.smallbun.screw.core.util.Assert;
import cn.smallbun.screw.core.util.ExceptionUtils;
import cn.smallbun.screw.core.util.StringUtils;
import java.util.HashMap;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
@@ -33,6 +34,7 @@ import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import org.apache.velocity.runtime.log.NullLogChute;
import static cn.smallbun.screw.core.constant.DefaultConstants.DEFAULT_ENCODING;
import static cn.smallbun.screw.core.engine.EngineTemplateType.velocity;
@@ -74,6 +76,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
velocityEngine.setProperty("file.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
}
velocityEngine.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName());
velocityEngine.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "");
velocityEngine.setProperty(Velocity.ENCODING_DEFAULT, DEFAULT_ENCODING);
velocityEngine.setProperty(Velocity.INPUT_ENCODING, DEFAULT_ENCODING);
@@ -89,21 +92,24 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
@Override
public void produce(DataModel info, String docName) throws ProduceException {
Assert.notNull(info, "DataModel can not be empty!");
Template template;
Template template = null;
try {
// get template path
String path = getEngineConfig().getCustomTemplate();
//如果自定义了模板
if (StringUtils.isNotBlank(path)) {
template = velocityEngine.getTemplate(path, DEFAULT_ENCODING);
}
//没有自定义模板,使用核心包自带
else {
template = velocityEngine
.getTemplate(velocity.getTemplateDir()
+ getEngineConfig().getFileType().getTemplateNamePrefix()
+ velocity.getSuffix(),
DEFAULT_ENCODING);
String templateContent = getEngineConfig().getTemplateContent();
if (templateContent != null) {
// get template path
String path = getEngineConfig().getCustomTemplate();
//如果自定义了模板
if (StringUtils.isNotBlank(path)) {
template = velocityEngine.getTemplate(path, DEFAULT_ENCODING);
}
//没有自定义模板,使用核心包自带
else {
template = velocityEngine
.getTemplate(velocity.getTemplateDir()
+ getEngineConfig().getFileType().getTemplateNamePrefix()
+ velocity.getSuffix(),
DEFAULT_ENCODING);
}
}
// output
try (FileOutputStream outStream = new FileOutputStream(getFile(docName));
@@ -112,8 +118,21 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
//put data
VelocityContext context = new VelocityContext();
context.put(DATA, info);
context.put("markdown", new HashMap<String, String>() {
{
put("h1", "#");
put("h2", "##");
put("h3", "###");
put("h4", "####");
put("h5", "#####");
}
});
//generate
template.merge(context, sw);
if (template != null) {
template.merge(context, sw);
} else {
velocityEngine.evaluate(context, sw, "test", templateContent);
}
// open the output directory
openOutputDir();
}

View File

@@ -93,4 +93,14 @@ public class ColumnModel implements Serializable {
* 说明
*/
private String remarks;
/**
* 嵌套数据信息(用于文档数据库)
*/
private TableModel nestedTable;
/**
* 是否弃用
*/
private Boolean deprecated;
}

View File

@@ -44,4 +44,9 @@ public class TableModel implements Serializable {
* 表列
*/
private List<ColumnModel> columns;
/**
* 是否弃用
*/
private Boolean deprecated;
}

View File

@@ -78,7 +78,7 @@ public abstract class AbstractProcess implements Process {
*
* @param configuration {@link Configuration}
*/
AbstractProcess(Configuration configuration) {
protected AbstractProcess(Configuration configuration) {
Assert.notNull(configuration, "Configuration can not be empty!");
this.config = configuration;
}

View File

@@ -44,7 +44,6 @@ import cn.smallbun.screw.core.util.Assert;
import cn.smallbun.screw.core.util.CollectionUtils;
import cn.smallbun.screw.core.util.ExceptionUtils;
import cn.smallbun.screw.core.util.JdbcUtils;
import dm.jdbc.driver.DmdbConnection;
/**
* 达梦数据库查询
@@ -136,14 +135,7 @@ public class DmDataBaseQuery extends AbstractDatabaseQuery {
*/
@Override
public String getSchema() throws QueryException {
try {
String schema;
DmdbConnection conn = (DmdbConnection) getMetaData().getConnection();
schema = conn.getUserName();
return schema;
} catch (SQLException e) {
throw ExceptionUtils.mpe(e);
}
return null;
}
/**

View File

@@ -47,4 +47,4 @@
#foreach($c in $t.columns)
| $!{velocityCount} | $!{c.columnName} | $!{c.columnType} | #if($!{c.decimalDigits})$!{c.decimalDigits}#else 0#end | $!{c.nullable}| $!{c.primaryKey} | $!{c.columnDef} | $!{c.remarks} |
#end
#end
#end

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>screw</artifactId>
<groupId>cn.smallbun.screw</groupId>
<version>1.0.5</version>
<version>1.0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw</artifactId>
<version>1.0.5</version>
<version>1.0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>