Skip to content

Commit

Permalink
MySQL代码生成器完善
Browse files Browse the repository at this point in the history
MySQL代码生成器完善
  • Loading branch information
TedHacker committed Mar 10, 2017
1 parent 05a26dd commit da894ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
13 changes: 11 additions & 2 deletions JavaWebCodeGenerator/src/main/java/com/zju/ShellRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@
public class ShellRunner {

private static final String CONFIG_FILE = "-configfile"; //配置文件
private static final String OVERWRITE="-overwrite"; //是否重写文件

public static void main(String[] args) throws IOException {
boolean overwrite=false;
if (args.length == 0) {
System.out.println("args is empty");
System.exit(0);
return;
}
//命令参数
Map<String, String> arguments = parseCommandLine(args);
if (!arguments.containsKey(CONFIG_FILE)) {
System.out.println("args do not contain configfile");
return;
}
if(arguments.containsKey(OVERWRITE)){
overwrite=true;
}
String configfile = arguments.get(CONFIG_FILE);
File configurationFile = new File(configfile);
if (!configurationFile.exists()) {
System.out.println("configfile is not exist");
return;
}
Configuration configuration= ConfigurationParser.parseConfiguration(configurationFile);
CodeGenerator.generate(configuration);
Configuration configuration= ConfigurationParser.parseConfiguration(configurationFile,overwrite);
CodeGenerator.generate(configuration);//生成代码
}

private static Map<String, String> parseCommandLine(String[] args) {
Expand All @@ -42,10 +48,13 @@ private static Map<String, String> parseCommandLine(String[] args) {
if (CONFIG_FILE.equalsIgnoreCase(args[i])) {
if ((i + 1) < args.length) {
arguments.put(CONFIG_FILE, args[i + 1]);
++i;
} else {
System.out.println("args error");
System.exit(-1);
}
}else if(OVERWRITE.equalsIgnoreCase(args[i])){
arguments.put(OVERWRITE,"");
}
}
return arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public class ConfigurationParser {
private static final String TABLE_NAME = "table.name";
private static final String DOMAIN_OBJECT_NAME = "domain.object.name";

public static Configuration parseConfiguration(File inputFile) throws IOException {
/**
* 配置文件解析
* @param inputFile 配置文件
* @param overwrite 是否重写参数
* @return
* @throws IOException
*/
public static Configuration parseConfiguration(File inputFile,Boolean overwrite) throws IOException {
FileReader fr = new FileReader(inputFile);
Properties prop = new Properties();
prop.load(fr);
Expand Down Expand Up @@ -51,6 +58,7 @@ public static Configuration parseConfiguration(File inputFile) throws IOExceptio
config.setDomainObjectName(prop.get(key).toString());
}
}
config.setOverwrite(overwrite);
return config;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CodeGeneratorTest {
@Test
public void testGenerate() throws Exception {
File file=new File("src/test/resources/generatorConfig.properties");
Configuration configuration= ConfigurationParser.parseConfiguration(file);
Configuration configuration= ConfigurationParser.parseConfiguration(file,true);
System.out.println(configuration);
CodeGenerator.generate(configuration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConfigurationParserTest {
@Test
public void testParseConfiguration() throws Exception {
File file=new File("src/test/resources/generatorConfig.properties");
Configuration configuration= ConfigurationParser.parseConfiguration(file);
Configuration configuration= ConfigurationParser.parseConfiguration(file,true);
System.out.println(configuration);
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 练习场
想做的,有趣的,好玩的

1. TheGameOfLife 可视化生命游戏
2. JavaWebCodeGenerator 简单的MySQL代码生成器

0 comments on commit da894ef

Please sign in to comment.