新增: 获取生成文件路径
parent
53a1bf0556
commit
7553b636cb
@ -1,9 +1,9 @@
|
||||
package space.caoshd.otone.extension;
|
||||
package space.caoshd.otone.aware;
|
||||
|
||||
import space.caoshd.otone.entity.ColumnInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ColumnAddonAble {
|
||||
public interface ColumnCreateAware {
|
||||
void addon(ColumnInfo tableInfo, Map<String,Object> addInfo);
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package space.caoshd.otone.extension;
|
||||
package space.caoshd.otone.aware;
|
||||
|
||||
import space.caoshd.otone.entity.TableInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface TableAddonAble {
|
||||
public interface TableCreateAware {
|
||||
void addon(TableInfo tableInfo, Map<String, Object> addInfo);
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package space.caoshd.otone.builder;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import space.caoshd.otone.entity.TableInfo;
|
||||
import space.caoshd.otone.tool.PropTools;
|
||||
import space.caoshd.otone.util.CfgConsts;
|
||||
import space.caoshd.otone.util.PathConsts;
|
||||
import space.caoshd.otone.util.VelocityUtils;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class PoBuilder {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TableBuilder.class);
|
||||
|
||||
private static final PropTools propTools = new PropTools(PathConsts.CONFIG_PROPERTIES_PATH);
|
||||
|
||||
private final List<TableInfo> tableInfoList;
|
||||
|
||||
private String templatePath = PathConsts.PO_TEMPLATE_PATH;
|
||||
private String outputBase = propTools.getString(CfgConsts.OUTPUT_BASE);
|
||||
private String outputPo = propTools.getString(CfgConsts.OUTPUT_PO);
|
||||
|
||||
public PoBuilder(List<TableInfo> tableInfoList) {
|
||||
this.tableInfoList = tableInfoList;
|
||||
}
|
||||
|
||||
public PoBuilder setTemplatePath(String templatePath) {
|
||||
this.templatePath = templatePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PoBuilder setOutputBase(String outputBase) {
|
||||
this.outputBase = outputBase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PoBuilder setOutputPo(String outputPo) {
|
||||
this.outputPo = outputPo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
for (TableInfo tableInfo : tableInfoList) {
|
||||
String beanName = tableInfo.getBeanName();
|
||||
String outputPath = Paths.get(outputBase, outputPo, beanName + ".java").toString();
|
||||
VelocityUtils.render(CfgConsts.VALUE_TABLE, tableInfo, templatePath, outputPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
public class CfgConsts {
|
||||
|
||||
private CfgConsts() {}
|
||||
|
||||
public static final String SCHEMA_NAMES = "database.schemas";
|
||||
|
||||
public static final String TABLE_NAMES = "table.names";
|
||||
|
||||
public static final String TABLE_PREFIXIES = "table.prefixes";
|
||||
|
||||
public static final String BEAN_SUFFIX = "bean.suffix";
|
||||
|
||||
public static final String OUTPUT_BASE = "output.base";
|
||||
|
||||
public static final String OUTPUT_PO = "output.po";
|
||||
|
||||
public static final String PROJECT_PATH_BASE = "project.path.base";
|
||||
|
||||
public static final String PROJECT_PATH_JAVA = "project.path.java";
|
||||
|
||||
public static final String PROJECT_PATH_RESOURCES = "project.path.resources";
|
||||
|
||||
public static final String PACKAGE_BASE = "package.base";
|
||||
|
||||
public static final String PACKAGE_PO = "package.po";
|
||||
|
||||
public static final String PACKAGE_MAPPER = "package.mapper";
|
||||
|
||||
public static final String PACKAGE_SERVICE = "package.service";
|
||||
|
||||
public static final String PACKAGE_CONTROLLER = "package.controller";
|
||||
|
||||
public static final String PACKAGE_QUERY = "package.query";
|
||||
|
||||
public static final String PACKAGE_FORM = "package.form";
|
||||
|
||||
public static final String PACKAGE_VIEW = "package.view";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_PO = "classname.suffix.po";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_MAPPER = "classname.suffix.mapper";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_SERVICE = "classname.suffix.service";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_QUERY = "classname.suffix.query";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_FORM = "classname.suffix.form";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_VIEW = "classname.suffix.view";
|
||||
|
||||
public static final String CLASS_NAME_SUFFIX_CONTROLLER = "classname.suffix.controller";
|
||||
|
||||
public static final String VALUE_TABLE = "table";
|
||||
|
||||
public static final String DEFAULT_PROJECT_PATH_JAVA = "src/main/java";
|
||||
|
||||
public static final String DEFAULT_PROJECT_PATH_RESOURCES = "src/main/resources";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_PO = "repository.po";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_MAPPER = "repository.mapper";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_SERVICE = "service";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_QUERY = "controller.query";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_FORM = "controller.form";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_VIEW = "controller.view";
|
||||
|
||||
public static final String DEFAULT_PACKAGE_CONTROLLER = "controller";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_PO = "";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_MAPPER = "Mapper";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_SERVICE = "Service";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_QUERY = "Query";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_FORM = "Form";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_VIEW = "View";
|
||||
|
||||
public static final String DEFAULT_CLASS_NAME_SUFFIX_CONTROLLER = "Controller";
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
public class ConfigConsts {
|
||||
|
||||
private ConfigConsts() {}
|
||||
|
||||
public static final String SCHEMA_NAMES = "database.schemas";
|
||||
|
||||
public static final String TABLE_NAMES = "table.names";
|
||||
|
||||
public static final String TABLE_PREFIXIES = "table.prefixes";
|
||||
|
||||
public static final String BEAN_SUFFIX = "bean.suffix";
|
||||
|
||||
public static final String VALUE_BEAN_SUFFIX = "Query";
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
public class PathConsts {
|
||||
|
||||
public PathConsts() {}
|
||||
|
||||
public static final String DATASOURCE_PROPERTIES_PATH = "config/datasource.properties";
|
||||
|
||||
public static final String CONFIG_PROPERTIES_PATH = "config/config.properties";
|
||||
|
||||
public static final String MYSQL_PROPERTIES_PATH = "config/mysql.properties";
|
||||
|
||||
public static final String VELOCITY_PROPERTIES_PATH = "config/velocity.properties";
|
||||
|
||||
public static final String RESOURCES_PATH = "config/velocity.properties";
|
||||
|
||||
public static final String PO_TEMPLATE_PATH = "template/po.vm";
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
import space.caoshd.otone.tool.PropTools;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class PathUtils {
|
||||
|
||||
private static final PropTools CONFIG = new PropTools(PathConsts.CONFIG_PROPERTIES_PATH);
|
||||
|
||||
private static final String JAVA_FILE_SUFFIX = ".java";
|
||||
|
||||
public static String getProjectPath() {
|
||||
return CONFIG.getString(CfgConsts.PROJECT_PATH_BASE);
|
||||
}
|
||||
|
||||
public static String getJavaSrcPath() {
|
||||
String basePath = getProjectPath();
|
||||
String configPath = CONFIG.getString(CfgConsts.PROJECT_PATH_JAVA);
|
||||
String defaultPath = CfgConsts.DEFAULT_PROJECT_PATH_JAVA;
|
||||
String path = StrUtils.defaultIfBlank(configPath, defaultPath);
|
||||
return Paths.get(basePath, path).toString();
|
||||
}
|
||||
|
||||
public static String getPackagePath() {
|
||||
String basePath = getJavaSrcPath();
|
||||
String name = CONFIG.getString(CfgConsts.PACKAGE_BASE);
|
||||
String path = name.replaceAll("\\.", "/");
|
||||
return Paths.get(basePath, path).toString();
|
||||
}
|
||||
|
||||
public static String getPathBasedPackage(String configPath, String defaultPath) {
|
||||
String basePath = getPackagePath();
|
||||
String path = StrUtils.defaultIfBlank(configPath, defaultPath);
|
||||
return Paths.get(basePath, path).toString();
|
||||
}
|
||||
|
||||
public static String getServicePath(String className) {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_SERVICE);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_MAPPER;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getControllerPath(String className) {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_CONTROLLER);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_CONTROLLER;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getViewPath(String className) {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_VIEW);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_VIEW;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getFormPath(String className) {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_FORM);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_FORM;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getQueryPath(String className) {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_QUERY);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_QUERY;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getPoPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_PO);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_PO;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getMapperPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_MAPPER);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_MAPPER;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getServicePath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_SERVICE);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_MAPPER;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getControllerPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_CONTROLLER);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_CONTROLLER;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getViewPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_VIEW);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_VIEW;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getFormPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_FORM);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_FORM;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
public static String getQueryPath() {
|
||||
String configPath = CONFIG.getString(CfgConsts.PACKAGE_QUERY);
|
||||
String defaultPath = CfgConsts.DEFAULT_PACKAGE_QUERY;
|
||||
return getPathBasedPackage(configPath, defaultPath);
|
||||
}
|
||||
|
||||
private static String getFilename(String className, String suffix) {
|
||||
return className + suffix + JAVA_FILE_SUFFIX;
|
||||
}
|
||||
|
||||
public static String getPoJavaPath(String className) {
|
||||
String basePath = getPoPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_PO);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_PO;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, defaultSuffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
public static String getMapperJavaPath(String className) {
|
||||
String basePath = getMapperPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_MAPPER);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_MAPPER;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
public static String getServiceJavaPath(String className) {
|
||||
String basePath = getServicePath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_SERVICE);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_SERVICE;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getControllerJavaPath(String className) {
|
||||
String basePath = getControllerPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_CONTROLLER);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_CONTROLLER;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getFormJavaPath(String className) {
|
||||
String basePath = getFormPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_CONTROLLER);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_CONTROLLER;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getQueryJavaPath(String className) {
|
||||
String basePath = getQueryPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_QUERY);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_QUERY;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
public static String getViewJavaPath(String className) {
|
||||
String basePath = getViewPath();
|
||||
String configSuffix = CONFIG.getString(CfgConsts.CLASS_NAME_SUFFIX_VIEW);
|
||||
String defaultSuffix = CfgConsts.DEFAULT_CLASS_NAME_SUFFIX_VIEW;
|
||||
String suffix = StrUtils.defaultIfBlank(configSuffix, defaultSuffix);
|
||||
String filename = getFilename(className, suffix);
|
||||
return Paths.get(basePath, filename).toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
public class PropertiesConsts {
|
||||
|
||||
public PropertiesConsts() {}
|
||||
|
||||
public static final String DATASOURCE_PROPERTIES_PATH = "datasource.properties";
|
||||
|
||||
public static final String CONFIG_PROPERTIES_PATH = "config.properties";
|
||||
|
||||
public static final String MYSQL_PROPERTIES_PATH = "mysql.properties";
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
public class StringUtils {
|
||||
public class StrUtils {
|
||||
|
||||
private StringUtils() {}
|
||||
private StrUtils() {}
|
||||
|
||||
public static String last(String str, String regex) {
|
||||
String[] split = str.split(regex);
|
@ -0,0 +1,32 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import space.caoshd.otone.tool.PropTools;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Properties;
|
||||
|
||||
public class VelocityUtils {
|
||||
|
||||
public static void render(
|
||||
String beanName, Object bean, String templatePath, String outputPath
|
||||
) {
|
||||
PropTools propTools = new PropTools(PathConsts.VELOCITY_PROPERTIES_PATH);
|
||||
Properties properties = propTools.getProperties();
|
||||
Velocity.init(properties);
|
||||
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put(beanName, bean);
|
||||
|
||||
Template template = Velocity.getTemplate(templatePath, StandardCharsets.UTF_8.name());
|
||||
try (FileWriter fw = new FileWriter(outputPath)) {
|
||||
template.merge(context, fw);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
#database.schemas=otone
|
||||
#table.names=t_file_export_instance,t_file_export_path,t_file_export_type_text,t_file_export_workspace
|
||||
table.prefixes=t_,m_
|
||||
bean.suffix=Query
|
@ -1,13 +0,0 @@
|
||||
table.sql=select * from information_schema.tables where TABLE_SCHEMA not in ('mysql', 'information_schema', 'performance_schema', 'sys')
|
||||
table.sql.schema=select * from information_schema.tables where table_schema = ?
|
||||
table.sql.schema.table=select * from information_schema.tables where table_schema = ? and table_name = ?
|
||||
|
||||
column.sql.schema.table=select * from information_schema.columns where TABLE_SCHEMA = ? and table_name = ?
|
||||
|
||||
|
||||
label.table_schema=TABLE_SCHEMA
|
||||
label.table_name=TABLE_NAME
|
||||
label.table_comment=TABLE_COMMENT
|
||||
label.column_name=COLUMN_NAME
|
||||
label.column_comment=COLUMN_COMMENT
|
||||
label.data_type=DATA_TYPE
|
@ -0,0 +1,17 @@
|
||||
package space.caoshd.otone.builder;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import space.caoshd.otone.entity.TableInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class PoBuilderTest {
|
||||
|
||||
@Test
|
||||
void build() {
|
||||
TableBuilder tableBuilder = new TableBuilder();
|
||||
List<TableInfo> tableInfoList = tableBuilder.build();
|
||||
PoBuilder poBuilder = new PoBuilder(tableInfoList);
|
||||
poBuilder.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package space.caoshd.otone.tool;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import space.caoshd.otone.util.CfgConsts;
|
||||
import space.caoshd.otone.util.PathConsts;
|
||||
import space.caoshd.otone.util.ResUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
class PropToolsTest {
|
||||
|
||||
@Test
|
||||
void loadProperties() {
|
||||
InputStream fileStream = ResUtils.getClassPathFileStream(PathConsts.DATASOURCE_PROPERTIES_PATH);
|
||||
PropTools propTools = new PropTools(fileStream);
|
||||
Assertions.assertNotNull(propTools);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getStrings() {
|
||||
InputStream fileStream = ResUtils.getClassPathFileStream(PathConsts.CONFIG_PROPERTIES_PATH);
|
||||
PropTools configProperties = new PropTools(fileStream);
|
||||
List<String> strings = configProperties.getStrings(CfgConsts.TABLE_PREFIXIES);
|
||||
System.out.println(strings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInt() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLong() {
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package space.caoshd.otone.tool;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import space.caoshd.otone.util.ConfigConsts;
|
||||
import space.caoshd.otone.util.PropertiesConsts;
|
||||
import space.caoshd.otone.util.ResourceUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
class PropertyToolsTest {
|
||||
|
||||
@Test
|
||||
void loadProperties() {
|
||||
InputStream fileStream = ResourceUtils.getClassPathFileStream(PropertiesConsts.DATASOURCE_PROPERTIES_PATH);
|
||||
PropertyTools propertyTools = new PropertyTools(fileStream);
|
||||
Assertions.assertNotNull(propertyTools);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getStrings() {
|
||||
InputStream fileStream = ResourceUtils.getClassPathFileStream(PropertiesConsts.CONFIG_PROPERTIES_PATH);
|
||||
PropertyTools configProperties = new PropertyTools(fileStream);
|
||||
List<String> strings = configProperties.getStrings(ConfigConsts.TABLE_PREFIXIES);
|
||||
System.out.println(strings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInt() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLong() {
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import space.caoshd.otone.tool.PropTools;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class DBUtilsTest {
|
||||
|
||||
@Test
|
||||
void executeQuery() {
|
||||
PropTools sqlProperties = new PropTools(PathConsts.MYSQL_PROPERTIES_PATH);
|
||||
String sql = sqlProperties.getString(SqlConsts.TABLE_SQL_SCHEMA_TABLE);
|
||||
PropTools configProperties =
|
||||
new PropTools(PathConsts.CONFIG_PROPERTIES_PATH);
|
||||
List<String> schemas = configProperties.getStrings(CfgConsts.SCHEMA_NAMES);
|
||||
List<String> tables = configProperties.getStrings(CfgConsts.TABLE_NAMES);
|
||||
List<Object> params = Arrays.asList(schemas.get(0), tables.get(0));
|
||||
List<Map<String, String>> maps = DBUtils.list(sql, params);
|
||||
Assertions.assertFalse(maps.isEmpty());
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import space.caoshd.otone.tool.PropertyTools;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class DatabaseUtilsTest {
|
||||
|
||||
@Test
|
||||
void executeQuery() {
|
||||
PropertyTools sqlProperties = new PropertyTools(PropertiesConsts.MYSQL_PROPERTIES_PATH);
|
||||
String sql = sqlProperties.getString(SqlConsts.TABLE_SQL_SCHEMA_TABLE);
|
||||
PropertyTools configProperties =
|
||||
new PropertyTools(PropertiesConsts.CONFIG_PROPERTIES_PATH);
|
||||
List<String> schemas = configProperties.getStrings(ConfigConsts.SCHEMA_NAMES);
|
||||
List<String> tables = configProperties.getStrings(ConfigConsts.TABLE_NAMES);
|
||||
List<Object> params = Arrays.asList(schemas.get(0), tables.get(0));
|
||||
List<Map<String, String>> maps = DatabaseUtils.list(sql, params);
|
||||
Assertions.assertFalse(maps.isEmpty());
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package space.caoshd.otone.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PathUtilsTest {
|
||||
|
||||
@Test
|
||||
void getProjectPath() {
|
||||
String projectPath = PathUtils.getProjectPath();
|
||||
System.out.println(projectPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackagePath() {
|
||||
String packagePath = PathUtils.getPackagePath();
|
||||
System.out.println(packagePath);
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
#database.schemas=otone
|
||||
#table.names=t_file_export_instance,t_file_export_path,t_file_export_type_text,t_file_export_workspace
|
||||
#bean.suffix=Query
|
||||
table.prefixes=t_,m_
|
@ -0,0 +1,23 @@
|
||||
project.path.base=D:/workspace/otono-debug/
|
||||
package.base=space.caoshd.navigator
|
||||
|
||||
#database.schemas=otone
|
||||
#table.names=
|
||||
#table.prefixes=
|
||||
#project.path.java=src/main/java
|
||||
#project.path.resources=src/main/resources
|
||||
#project.path.mapper=
|
||||
#package.po=repository.po
|
||||
#package.mapper=repository.mapper
|
||||
#package.service=service
|
||||
#package.query=controller.query
|
||||
#package.form=controller.form
|
||||
#package.view=controller.view
|
||||
#package.controller=controller
|
||||
#classname.suffix.service=Service
|
||||
#classname.suffix.Controller=Controller
|
||||
#classname.suffix.view=View
|
||||
#classname.suffix.form=Form
|
||||
#classname.suffix.query=Query
|
||||
#classname.suffix.mapper=Mapper
|
||||
#classname.suffix.po=
|
@ -0,0 +1 @@
|
||||
file.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
|
@ -1,4 +0,0 @@
|
||||
username=root
|
||||
password=123456
|
||||
url=jdbc:mysql://192.168.0.100:3306/otone?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
driver-class-name=com.mysql.cj.jdbc.Driver
|
@ -0,0 +1 @@
|
||||
${table.beanName}
|
Loading…
Reference in New Issue