[modify]:增加注释
Showing
11 changed files
with
57 additions
and
52 deletions
| 1 | ## DDL 脚本生成器 | 1 | ## DDL 脚本生成器 |
| 2 | ### 逻辑图 | 2 | ### 逻辑图 |
| 3 | 设计请看逻辑图.png | 3 | 设计请看逻辑图.png |
| 4 | ### 1. 使用步骤 | 4 | ### 使用步骤 |
| 5 | 1. 修改 DDLScriptCreatorTest 数据源。 | 5 | 1. 修改 DDLScriptCreatorTest 数据源。 |
| 6 | 2. 运行 DDLScriptCreatorTest main 方法。 | 6 | 2. 运行 DDLScriptCreatorTest main 方法。 |
| 7 | 3. 稍等一会就能在控制台看到 ddl 语句。 | 7 | 3. 稍等一会就能在控制台看到 ddl 语句。 | ... | ... |
| ... | @@ -5,10 +5,15 @@ package com.seektruth.ddl.creator.datasource; | ... | @@ -5,10 +5,15 @@ package com.seektruth.ddl.creator.datasource; |
| 5 | * @author black | 5 | * @author black |
| 6 | */ | 6 | */ |
| 7 | public class Datasource { | 7 | public class Datasource { |
| 8 | // 用户名 | ||
| 8 | private String username; | 9 | private String username; |
| 10 | // 密码 | ||
| 9 | private String password; | 11 | private String password; |
| 12 | // url | ||
| 10 | private String url; | 13 | private String url; |
| 14 | // 驱动类 | ||
| 11 | private String driverClass; | 15 | private String driverClass; |
| 16 | // 数据库名字 | ||
| 12 | private String databaseName; | 17 | private String databaseName; |
| 13 | public String getUsername() { | 18 | public String getUsername() { |
| 14 | return username; | 19 | return username; | ... | ... |
| ... | @@ -7,22 +7,22 @@ package com.seektruth.ddl.creator.ddl.oracle; | ... | @@ -7,22 +7,22 @@ package com.seektruth.ddl.creator.ddl.oracle; |
| 7 | * | 7 | * |
| 8 | */ | 8 | */ |
| 9 | public class OracleSequence { | 9 | public class OracleSequence { |
| 10 | 10 | // 序列名 | |
| 11 | String name; | 11 | String name; |
| 12 | 12 | // 起始值 | |
| 13 | String start; | 13 | String start; |
| 14 | 14 | // 递增值 | |
| 15 | String increment; | 15 | String increment; |
| 16 | 16 | // 最大值 | |
| 17 | String maxvalue; | 17 | String maxvalue; |
| 18 | 18 | // 最小值 | |
| 19 | String minvalue; | 19 | String minvalue; |
| 20 | 20 | // 是否循环 | |
| 21 | Boolean cycle; | 21 | Boolean cycle; |
| 22 | 22 | // 是否缓存 | |
| 23 | Boolean cache; | 23 | Boolean cache; |
| 24 | 24 | // 缓存数量 | |
| 25 | Integer cacheSize; | 25 | Integer cacheAmt; |
| 26 | 26 | ||
| 27 | public String getName() { | 27 | public String getName() { |
| 28 | return name; | 28 | return name; |
| ... | @@ -52,8 +52,8 @@ public class OracleSequence { | ... | @@ -52,8 +52,8 @@ public class OracleSequence { |
| 52 | return cache; | 52 | return cache; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | public Integer getCacheSize() { | 55 | public Integer getCacheAmt() { |
| 56 | return cacheSize; | 56 | return cacheAmt; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public void setName(String name) { | 59 | public void setName(String name) { |
| ... | @@ -84,8 +84,8 @@ public class OracleSequence { | ... | @@ -84,8 +84,8 @@ public class OracleSequence { |
| 84 | this.cache = cache; | 84 | this.cache = cache; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | public void setCacheSize(Integer cacheSize) { | 87 | public void setCacheAmt(Integer cacheSize) { |
| 88 | this.cacheSize = cacheSize; | 88 | this.cacheAmt = cacheSize; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | public String ddl() { | 91 | public String ddl() { |
| ... | @@ -103,7 +103,7 @@ public class OracleSequence { | ... | @@ -103,7 +103,7 @@ public class OracleSequence { |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | if (cache) { | 105 | if (cache) { |
| 106 | buffer.append("cache ").append(cacheSize).append(" "); | 106 | buffer.append("cache ").append(cacheAmt).append(" "); |
| 107 | } else { | 107 | } else { |
| 108 | buffer.append("nocache "); | 108 | buffer.append("nocache "); |
| 109 | } | 109 | } | ... | ... |
| ... | @@ -6,28 +6,28 @@ package com.seektruth.ddl.creator.metadata; | ... | @@ -6,28 +6,28 @@ package com.seektruth.ddl.creator.metadata; |
| 6 | * | 6 | * |
| 7 | */ | 7 | */ |
| 8 | public class ColumnInfo { | 8 | public class ColumnInfo { |
| 9 | 9 | // 表名 | |
| 10 | private String tableName; | 10 | private String tableName; |
| 11 | 11 | // 列名 | |
| 12 | private String name; | 12 | private String name; |
| 13 | // java.sql.Types | 13 | // java.sql.Types |
| 14 | private Integer type; | 14 | private Integer type; |
| 15 | 15 | ||
| 16 | private String typeName; | 16 | private String typeName; |
| 17 | 17 | // 列长度 | |
| 18 | private Integer size; | 18 | private Integer size; |
| 19 | 19 | // 列精度 | |
| 20 | private Integer decimalDigits; | 20 | private Integer decimalDigits; |
| 21 | 21 | ||
| 22 | // 进制 | 22 | // 进制(10进制还是2进制) |
| 23 | private Integer radix; | 23 | private Integer radix; |
| 24 | 24 | // 可为空 | |
| 25 | private Integer nullable; | 25 | private Integer nullable; |
| 26 | 26 | // 注释 | |
| 27 | private String comment; | 27 | private String comment; |
| 28 | 28 | // 默认值 | |
| 29 | private String defaultValue; | 29 | private String defaultValue; |
| 30 | // 序号 | 30 | // 序号,在表中的位置 |
| 31 | private Integer index; | 31 | private Integer index; |
| 32 | 32 | ||
| 33 | private String is_nullable; | 33 | private String is_nullable; | ... | ... |
| ... | @@ -9,7 +9,7 @@ import java.util.List; | ... | @@ -9,7 +9,7 @@ import java.util.List; |
| 9 | * | 9 | * |
| 10 | */ | 10 | */ |
| 11 | public class DatabaseMetaDataInfo { | 11 | public class DatabaseMetaDataInfo { |
| 12 | 12 | // 表 | |
| 13 | private List<TableInfo> tables; | 13 | private List<TableInfo> tables; |
| 14 | 14 | ||
| 15 | public List<TableInfo> getTables() { | 15 | public List<TableInfo> getTables() { | ... | ... |
| ... | @@ -11,13 +11,13 @@ import java.util.function.Predicate; | ... | @@ -11,13 +11,13 @@ import java.util.function.Predicate; |
| 11 | * | 11 | * |
| 12 | */ | 12 | */ |
| 13 | public class IndexInfo { | 13 | public class IndexInfo { |
| 14 | 14 | // 表名 | |
| 15 | private String tableName; | 15 | private String tableName; |
| 16 | 16 | // 索引名 | |
| 17 | private String name; | 17 | private String name; |
| 18 | 18 | // 是否唯一索引 | |
| 19 | private Boolean nonUnique; | 19 | private Boolean nonUnique; |
| 20 | 20 | // 索引的列 | |
| 21 | private List<IndexColumnInfo> columns = new ArrayList<IndexColumnInfo>(); | 21 | private List<IndexColumnInfo> columns = new ArrayList<IndexColumnInfo>(); |
| 22 | 22 | ||
| 23 | public String getTableName() { | 23 | public String getTableName() { | ... | ... |
| ... | @@ -9,11 +9,11 @@ import java.util.List; | ... | @@ -9,11 +9,11 @@ import java.util.List; |
| 9 | * | 9 | * |
| 10 | */ | 10 | */ |
| 11 | public class PrimaryKeyInfo { | 11 | public class PrimaryKeyInfo { |
| 12 | 12 | // 表名 | |
| 13 | private String tableName; | 13 | private String tableName; |
| 14 | 14 | // 主键名 | |
| 15 | private String name; | 15 | private String name; |
| 16 | 16 | // 主键的列信息 | |
| 17 | private List<IndexColumnInfo> columns = new ArrayList<IndexColumnInfo>(); | 17 | private List<IndexColumnInfo> columns = new ArrayList<IndexColumnInfo>(); |
| 18 | 18 | ||
| 19 | public String getTableName() { | 19 | public String getTableName() { | ... | ... |
| ... | @@ -14,7 +14,7 @@ public class TableInfo { | ... | @@ -14,7 +14,7 @@ public class TableInfo { |
| 14 | private String schema ; | 14 | private String schema ; |
| 15 | // 表名 | 15 | // 表名 |
| 16 | private String name ; | 16 | private String name ; |
| 17 | 17 | // 表类型 | |
| 18 | private String type ; | 18 | private String type ; |
| 19 | // 表注释 | 19 | // 表注释 |
| 20 | private String comment ; | 20 | private String comment ; | ... | ... |
| ... | @@ -69,11 +69,11 @@ public class OracleTransfer implements Transfer<OracleDatabase> { | ... | @@ -69,11 +69,11 @@ public class OracleTransfer implements Transfer<OracleDatabase> { |
| 69 | if (c.getNeedSquence()) { | 69 | if (c.getNeedSquence()) { |
| 70 | if (isPkColumn) { | 70 | if (isPkColumn) { |
| 71 | // 主键列的序列命名:"表名_SEQ" | 71 | // 主键列的序列命名:"表名_SEQ" |
| 72 | sequence = createSequence(c.getLength(), table.getName() + "_SEQ"); | 72 | sequence = createSequence(c.getLength(), table.getName() + "_seq"); |
| 73 | } else { | 73 | } else { |
| 74 | // 非主键列的序列命名:"表名_字段名_SEQ" | 74 | // 非主键列的序列命名:"表名_字段名_SEQ" |
| 75 | sequence = createSequence(c.getLength(), | 75 | sequence = createSequence(c.getLength(), |
| 76 | table.getName() + "_" + columns.get(j).getName() + "_SEQ"); | 76 | table.getName() + "_" + columns.get(j).getName() + "_seq"); |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | if(sequence != null) { | 79 | if(sequence != null) { |
| ... | @@ -141,7 +141,7 @@ public class OracleTransfer implements Transfer<OracleDatabase> { | ... | @@ -141,7 +141,7 @@ public class OracleTransfer implements Transfer<OracleDatabase> { |
| 141 | public OracleSequence createSequence(String columnLength, String name) { | 141 | public OracleSequence createSequence(String columnLength, String name) { |
| 142 | OracleSequence sequence = new OracleSequence(); | 142 | OracleSequence sequence = new OracleSequence(); |
| 143 | sequence.setCache(true); | 143 | sequence.setCache(true); |
| 144 | sequence.setCacheSize(20); | 144 | sequence.setCacheAmt(20); |
| 145 | sequence.setCycle(false); | 145 | sequence.setCycle(false); |
| 146 | sequence.setIncrement("1"); | 146 | sequence.setIncrement("1"); |
| 147 | sequence.setMinvalue("1"); | 147 | sequence.setMinvalue("1"); | ... | ... |
| ... | @@ -18,9 +18,9 @@ public class DDLScriptCreatorTest { | ... | @@ -18,9 +18,9 @@ public class DDLScriptCreatorTest { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | public static Datasource oracle() { | 20 | public static Datasource oracle() { |
| 21 | String devUrl="jdbc:oracle:thin:@localhost:1521:orcl?useInformationSchema=true"; | 21 | String devUrl = "jdbc:oracle:thin:@localhost:1521:orcl?useInformationSchema=true"; |
| 22 | String userName="dev_poc_rec"; | 22 | String userName = "dev_poc_rec"; |
| 23 | String password="black"; | 23 | String password = "black"; |
| 24 | Datasource datasource = new Datasource(); | 24 | Datasource datasource = new Datasource(); |
| 25 | datasource.setDriverClass("oracle.jdbc.driver.OracleDriver"); | 25 | datasource.setDriverClass("oracle.jdbc.driver.OracleDriver"); |
| 26 | datasource.setUrl(devUrl); | 26 | datasource.setUrl(devUrl); |
| ... | @@ -29,24 +29,21 @@ public class DDLScriptCreatorTest { | ... | @@ -29,24 +29,21 @@ public class DDLScriptCreatorTest { |
| 29 | datasource.setDatabaseName("orcl"); | 29 | datasource.setDatabaseName("orcl"); |
| 30 | return datasource; | 30 | return datasource; |
| 31 | } | 31 | } |
| 32 | |||
| 32 | public static Datasource mysql() { | 33 | public static Datasource mysql() { |
| 33 | //pedantic=true& | 34 | String databaseName = "database"; |
| 34 | String devUrl="jdbc:mysql://rm-2zen60zh797n662w4lo.mysql.rds.aliyuncs.com:3306/dev_poc_rec?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useInformationSchema=true&nullDatabaseMeansCurrent=true"; | 35 | String driverClass = "com.mysql.cj.jdbc.Driver"; |
| 35 | String userName="dev_poc_rec"; | 36 | // url 必须拼接 “useInformationSchema=true&nullDatabaseMeansCurrent=true” 参数 |
| 36 | String password="HMTWBekcV116aZfoy18Au4"; | 37 | String databaseUrl = "jdbc:mysql://localhost:3306/dev_poc_rec?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useInformationSchema=true&nullDatabaseMeansCurrent=true"; |
| 38 | String userName = "username"; | ||
| 39 | String password = "password"; | ||
| 37 | 40 | ||
| 38 | // String devUrl="jdbc:mysql://rm-2zen60zh797n662w4lo.mysql.rds.aliyuncs.com:3306/standard_bank_test?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useInformationSchema=true&nullDatabaseMeansCurrent=true"; | ||
| 39 | // String userName="standard_bank_ts"; | ||
| 40 | // String password="cnX%Dio16YIKEWvt&UOdH"; | ||
| 41 | // String devUrl="jdbc:mysql://rm-2zen60zh797n662w4lo.mysql.rds.aliyuncs.com:3306/poc-rec-bank?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useInformationSchema=true&nullDatabaseMeansCurrent=true"; | ||
| 42 | // String userName="poc_rec_bank"; | ||
| 43 | // String password="f$FwIdm16Lp192qt014UT6o"; | ||
| 44 | Datasource datasource = new Datasource(); | 41 | Datasource datasource = new Datasource(); |
| 45 | datasource.setDriverClass("com.mysql.cj.jdbc.Driver"); | 42 | datasource.setDriverClass(driverClass); |
| 46 | datasource.setUrl(devUrl); | 43 | datasource.setUrl(databaseUrl); |
| 47 | datasource.setUsername(userName); | 44 | datasource.setUsername(userName); |
| 48 | datasource.setPassword(password); | 45 | datasource.setPassword(password); |
| 49 | datasource.setDatabaseName("dev_poc_rec"); | 46 | datasource.setDatabaseName(databaseName); |
| 50 | return datasource; | 47 | return datasource; |
| 51 | } | 48 | } |
| 52 | } | 49 | } | ... | ... |
-
Please register or sign in to post a comment