Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
李墨
/
ddl-script-creator
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
de83caf3
authored
2022-08-09 10:26:06 +0800
by
李墨
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[modify]:增加注释
1 parent
9da0217d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
61 additions
and
56 deletions
README.md
src/main/java/com/seektruth/ddl/creator/datasource/Datasource.java
src/main/java/com/seektruth/ddl/creator/ddl/Database.java
src/main/java/com/seektruth/ddl/creator/ddl/oracle/OracleSequence.java
src/main/java/com/seektruth/ddl/creator/metadata/ColumnInfo.java
src/main/java/com/seektruth/ddl/creator/metadata/DatabaseMetaDataInfo.java
src/main/java/com/seektruth/ddl/creator/metadata/IndexInfo.java
src/main/java/com/seektruth/ddl/creator/metadata/PrimaryKeyInfo.java
src/main/java/com/seektruth/ddl/creator/metadata/TableInfo.java
src/main/java/com/seektruth/ddl/creator/transfer/OracleTransfer.java
src/test/java/com/seektruth/ddl/creator/DDLScriptCreatorTest.java
README.md
View file @
de83caf
## DDL 脚本生成器
### 逻辑图
设计请看逻辑图.png
###
1.
使用步骤
### 使用步骤
1.
修改 DDLScriptCreatorTest 数据源。
2.
运行 DDLScriptCreatorTest main 方法。
3.
稍等一会就能在控制台看到 ddl 语句。
...
...
src/main/java/com/seektruth/ddl/creator/datasource/Datasource.java
View file @
de83caf
...
...
@@ -5,10 +5,15 @@ package com.seektruth.ddl.creator.datasource;
* @author black
*/
public
class
Datasource
{
// 用户名
private
String
username
;
// 密码
private
String
password
;
// url
private
String
url
;
// 驱动类
private
String
driverClass
;
// 数据库名字
private
String
databaseName
;
public
String
getUsername
()
{
return
username
;
...
...
src/main/java/com/seektruth/ddl/creator/ddl/Database.java
View file @
de83caf
package
com
.
seektruth
.
ddl
.
creator
.
ddl
;
/**
* 数据库信息
*/
public
class
Database
{
public
String
ddl
()
{
return
""
;
...
...
src/main/java/com/seektruth/ddl/creator/ddl/oracle/OracleSequence.java
View file @
de83caf
...
...
@@ -7,22 +7,22 @@ package com.seektruth.ddl.creator.ddl.oracle;
*
*/
public
class
OracleSequence
{
// 序列名
String
name
;
// 起始值
String
start
;
// 递增值
String
increment
;
// 最大值
String
maxvalue
;
// 最小值
String
minvalue
;
// 是否循环
Boolean
cycle
;
// 是否缓存
Boolean
cache
;
Integer
cache
Size
;
// 缓存数量
Integer
cache
Amt
;
public
String
getName
()
{
return
name
;
...
...
@@ -52,8 +52,8 @@ public class OracleSequence {
return
cache
;
}
public
Integer
getCache
Size
()
{
return
cache
Size
;
public
Integer
getCache
Amt
()
{
return
cache
Amt
;
}
public
void
setName
(
String
name
)
{
...
...
@@ -84,8 +84,8 @@ public class OracleSequence {
this
.
cache
=
cache
;
}
public
void
setCache
Size
(
Integer
cacheSize
)
{
this
.
cache
Size
=
cacheSize
;
public
void
setCache
Amt
(
Integer
cacheSize
)
{
this
.
cache
Amt
=
cacheSize
;
}
public
String
ddl
()
{
...
...
@@ -103,7 +103,7 @@ public class OracleSequence {
}
if
(
cache
)
{
buffer
.
append
(
"cache "
).
append
(
cache
Size
).
append
(
" "
);
buffer
.
append
(
"cache "
).
append
(
cache
Amt
).
append
(
" "
);
}
else
{
buffer
.
append
(
"nocache "
);
}
...
...
src/main/java/com/seektruth/ddl/creator/metadata/ColumnInfo.java
View file @
de83caf
...
...
@@ -6,28 +6,28 @@ package com.seektruth.ddl.creator.metadata;
*
*/
public
class
ColumnInfo
{
// 表名
private
String
tableName
;
// 列名
private
String
name
;
// java.sql.Types
private
Integer
type
;
private
String
typeName
;
// 列长度
private
Integer
size
;
// 列精度
private
Integer
decimalDigits
;
// 进制
// 进制
(10进制还是2进制)
private
Integer
radix
;
// 可为空
private
Integer
nullable
;
// 注释
private
String
comment
;
// 默认值
private
String
defaultValue
;
// 序号
// 序号
,在表中的位置
private
Integer
index
;
private
String
is_nullable
;
...
...
src/main/java/com/seektruth/ddl/creator/metadata/DatabaseMetaDataInfo.java
View file @
de83caf
...
...
@@ -9,7 +9,7 @@ import java.util.List;
*
*/
public
class
DatabaseMetaDataInfo
{
// 表
private
List
<
TableInfo
>
tables
;
public
List
<
TableInfo
>
getTables
()
{
...
...
src/main/java/com/seektruth/ddl/creator/metadata/IndexInfo.java
View file @
de83caf
...
...
@@ -11,13 +11,13 @@ import java.util.function.Predicate;
*
*/
public
class
IndexInfo
{
// 表名
private
String
tableName
;
// 索引名
private
String
name
;
// 是否唯一索引
private
Boolean
nonUnique
;
// 索引的列
private
List
<
IndexColumnInfo
>
columns
=
new
ArrayList
<
IndexColumnInfo
>();
public
String
getTableName
()
{
...
...
src/main/java/com/seektruth/ddl/creator/metadata/PrimaryKeyInfo.java
View file @
de83caf
...
...
@@ -9,11 +9,11 @@ import java.util.List;
*
*/
public
class
PrimaryKeyInfo
{
// 表名
private
String
tableName
;
// 主键名
private
String
name
;
// 主键的列信息
private
List
<
IndexColumnInfo
>
columns
=
new
ArrayList
<
IndexColumnInfo
>();
public
String
getTableName
()
{
...
...
src/main/java/com/seektruth/ddl/creator/metadata/TableInfo.java
View file @
de83caf
...
...
@@ -14,7 +14,7 @@ public class TableInfo {
private
String
schema
;
// 表名
private
String
name
;
// 表类型
private
String
type
;
// 表注释
private
String
comment
;
...
...
src/main/java/com/seektruth/ddl/creator/transfer/OracleTransfer.java
View file @
de83caf
...
...
@@ -69,11 +69,11 @@ public class OracleTransfer implements Transfer<OracleDatabase> {
if
(
c
.
getNeedSquence
())
{
if
(
isPkColumn
)
{
// 主键列的序列命名:"表名_SEQ"
sequence
=
createSequence
(
c
.
getLength
(),
table
.
getName
()
+
"_
SEQ
"
);
sequence
=
createSequence
(
c
.
getLength
(),
table
.
getName
()
+
"_
seq
"
);
}
else
{
// 非主键列的序列命名:"表名_字段名_SEQ"
sequence
=
createSequence
(
c
.
getLength
(),
table
.
getName
()
+
"_"
+
columns
.
get
(
j
).
getName
()
+
"_
SEQ
"
);
table
.
getName
()
+
"_"
+
columns
.
get
(
j
).
getName
()
+
"_
seq
"
);
}
}
if
(
sequence
!=
null
)
{
...
...
@@ -141,7 +141,7 @@ public class OracleTransfer implements Transfer<OracleDatabase> {
public
OracleSequence
createSequence
(
String
columnLength
,
String
name
)
{
OracleSequence
sequence
=
new
OracleSequence
();
sequence
.
setCache
(
true
);
sequence
.
setCache
Size
(
20
);
sequence
.
setCache
Amt
(
20
);
sequence
.
setCycle
(
false
);
sequence
.
setIncrement
(
"1"
);
sequence
.
setMinvalue
(
"1"
);
...
...
src/test/java/com/seektruth/ddl/creator/DDLScriptCreatorTest.java
View file @
de83caf
...
...
@@ -8,7 +8,7 @@ import com.seektruth.ddl.creator.transfer.OracleTransfer;
import
com.seektruth.ddl.creator.transfer.Transfer
;
public
class
DDLScriptCreatorTest
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
{
Datasource
datasource
=
mysql
();
DatabaseMetaDataCollector
collector
=
new
MySQLDatabaseMetaDataCollector
(
datasource
);
...
...
@@ -18,35 +18,32 @@ public class DDLScriptCreatorTest {
}
public
static
Datasource
oracle
()
{
String
devUrl
=
"jdbc:oracle:thin:@localhost:1521:orcl?useInformationSchema=true"
;
String
userName
=
"dev_poc_rec"
;
String
password
=
"black"
;
String
devUrl
=
"jdbc:oracle:thin:@localhost:1521:orcl?useInformationSchema=true"
;
String
userName
=
"dev_poc_rec"
;
String
password
=
"black"
;
Datasource
datasource
=
new
Datasource
();
datasource
.
setDriverClass
(
"oracle.jdbc.driver.OracleDriver"
);
datasource
.
setUrl
(
devUrl
);
datasource
.
setUsername
(
userName
);
datasource
.
setPassword
(
password
);
datasource
.
setDatabaseName
(
"orcl"
);
return
datasource
;
return
datasource
;
}
public
static
Datasource
mysql
()
{
//pedantic=true&
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"
;
String
userName
=
"dev_poc_rec"
;
String
password
=
"HMTWBekcV116aZfoy18Au4"
;
// 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";
// String userName="standard_bank_ts";
// String password="cnX%Dio16YIKEWvt&UOdH";
// 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";
// String userName="poc_rec_bank";
// String password="f$FwIdm16Lp192qt014UT6o";
String
databaseName
=
"database"
;
String
driverClass
=
"com.mysql.cj.jdbc.Driver"
;
// url 必须拼接 “useInformationSchema=true&nullDatabaseMeansCurrent=true” 参数
String
databaseUrl
=
"jdbc:mysql://localhost:3306/dev_poc_rec?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useInformationSchema=true&nullDatabaseMeansCurrent=true"
;
String
userName
=
"username"
;
String
password
=
"password"
;
Datasource
datasource
=
new
Datasource
();
datasource
.
setDriverClass
(
"com.mysql.cj.jdbc.Driver"
);
datasource
.
setUrl
(
d
ev
Url
);
datasource
.
setDriverClass
(
driverClass
);
datasource
.
setUrl
(
d
atabase
Url
);
datasource
.
setUsername
(
userName
);
datasource
.
setPassword
(
password
);
datasource
.
setDatabaseName
(
"dev_poc_rec"
);
return
datasource
;
datasource
.
setDatabaseName
(
databaseName
);
return
datasource
;
}
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment