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

View File

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

View File

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

View File

@@ -93,4 +93,14 @@ public class ColumnModel implements Serializable {
* 说明 * 说明
*/ */
private String remarks; 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 List<ColumnModel> columns;
/**
* 是否弃用
*/
private Boolean deprecated;
} }

View File

@@ -78,7 +78,7 @@ public abstract class AbstractProcess implements Process {
* *
* @param configuration {@link Configuration} * @param configuration {@link Configuration}
*/ */
AbstractProcess(Configuration configuration) { protected AbstractProcess(Configuration configuration) {
Assert.notNull(configuration, "Configuration can not be empty!"); Assert.notNull(configuration, "Configuration can not be empty!");
this.config = configuration; 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.CollectionUtils;
import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.ExceptionUtils;
import cn.smallbun.screw.core.util.JdbcUtils; import cn.smallbun.screw.core.util.JdbcUtils;
import dm.jdbc.driver.DmdbConnection;
/** /**
* 达梦数据库查询 * 达梦数据库查询
@@ -136,14 +135,7 @@ public class DmDataBaseQuery extends AbstractDatabaseQuery {
*/ */
@Override @Override
public String getSchema() throws QueryException { public String getSchema() throws QueryException {
try { return null;
String schema;
DmdbConnection conn = (DmdbConnection) getMetaData().getConnection();
schema = conn.getUserName();
return schema;
} catch (SQLException e) {
throw ExceptionUtils.mpe(e);
}
} }
/** /**

View File

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

View File

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