Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzlite
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzlite
提交
4e76eab8
提交
4e76eab8
编写于
12月 08, 2020
作者:
Tyl666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Liquibase逆向工程】第三版 补充字段内容
上级
d85166d0
变更
1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
91 行增加
和
24 行删除
+91
-24
DstLiquibaseService.java
...ava/cn/ibizlab/core/lite/service/DstLiquibaseService.java
+91
-24
未找到文件。
ibzlite-core/src/main/java/cn/ibizlab/core/lite/service/DstLiquibaseService.java
浏览文件 @
4e76eab8
...
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
...
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.XML
;
import
cn.hutool.json.XML
;
import
cn.ibizlab.core.lite.domain.MetaField
;
import
cn.ibizlab.core.lite.domain.MetaField
;
import
cn.ibizlab.core.lite.domain.MetaRelationship
;
import
cn.ibizlab.core.lite.extensions.domain.MetaEntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.MetaEntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.SysModel
;
import
cn.ibizlab.core.lite.extensions.domain.SysModel
;
import
cn.ibizlab.core.util.config.LiquibaseConfiguration
;
import
cn.ibizlab.core.util.config.LiquibaseConfiguration
;
...
@@ -37,6 +38,7 @@ import java.io.InputStream;
...
@@ -37,6 +38,7 @@ import java.io.InputStream;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CopyOnWriteArrayList
;
@Slf4j
@Slf4j
...
@@ -106,14 +108,21 @@ public class DstLiquibaseService{
...
@@ -106,14 +108,21 @@ public class DstLiquibaseService{
SysModel
sysModel
=
generateSysModel
(
liquibaseChangeLogPath
);
SysModel
sysModel
=
generateSysModel
(
liquibaseChangeLogPath
);
return
sysModel
;
return
sysModel
;
}
}
/**
/**
* 构建一个SysModel对象
* 构建一个SysModel对象
* @param path 生成liquibaseChangeLog路径
* @param path 生成liquibaseChangeLog路径
*/
*/
public
SysModel
generateSysModel
(
String
path
)
{
public
static
SysModel
generateSysModel
(
String
path
)
{
List
<
MetaEntityModel
>
metaEntityModels
=
new
CopyOnWriteArrayList
<>();
List
<
MetaEntityModel
>
metaEntityModels
=
new
CopyOnWriteArrayList
<>();
SysModel
sysModel
=
new
SysModel
();
SysModel
sysModel
=
new
SysModel
();
Map
<
String
,
MetaRelationship
>
parentMap
=
null
;
Map
<
String
,
MetaRelationship
>
subMap
=
null
;
List
<
Map
<
String
,
MetaRelationship
>>
parentEntities
=
null
;
List
<
Map
<
String
,
MetaRelationship
>>
subEntities
=
null
;
MetaRelationship
parent
=
null
;
MetaRelationship
sub
=
null
;
MetaEntityModel
metaEntityModel
=
null
;
MetaEntityModel
metaEntityModel
=
null
;
List
<
Map
>
commonMessage
=
null
;
List
<
Map
>
commonMessage
=
null
;
MetaField
metaField
=
null
;
MetaField
metaField
=
null
;
...
@@ -124,50 +133,108 @@ public class DstLiquibaseService{
...
@@ -124,50 +133,108 @@ public class DstLiquibaseService{
com
.
alibaba
.
fastjson
.
JSONObject
jsonObject
=
JSON
.
parseObject
(
ConvertXMLtoJSON
(
path
));
com
.
alibaba
.
fastjson
.
JSONObject
jsonObject
=
JSON
.
parseObject
(
ConvertXMLtoJSON
(
path
));
head
=
(
Map
)
jsonObject
.
get
(
"databaseChangeLog"
);
head
=
(
Map
)
jsonObject
.
get
(
"databaseChangeLog"
);
commonMessage
=
(
List
<
Map
>)
head
.
get
(
"changeSet"
);
commonMessage
=
(
List
<
Map
>)
head
.
get
(
"changeSet"
);
parentEntities
=
new
CopyOnWriteArrayList
<>();
subEntities
=
new
CopyOnWriteArrayList
<>();
// 维护父子键实体
for
(
int
i
=
0
;
i
<
commonMessage
.
size
();
i
++)
{
temp
=
(
Map
)
commonMessage
.
get
(
i
).
get
(
"addForeignKeyConstraint"
);
if
(!
ObjectUtil
.
isEmpty
(
temp
)){
// 存入父键map
parent
=
new
MetaRelationship
();
parentMap
=
new
ConcurrentHashMap
();
parent
.
setName
(
"DER1N_"
+
temp
.
get
(
"referencedTableName"
).
toString
().
toUpperCase
());
parent
.
setCodeName
(
temp
.
get
(
"referencedColumnNames"
).
toString
());
parent
.
setEntityName
(
temp
.
get
(
"referencedTableName"
).
toString
().
toUpperCase
());
parent
.
setRelationType
(
"DER1N"
);
parent
.
setSystemId
(
commonMessage
.
get
(
0
).
get
(
"author"
).
toString
());
parent
.
setRefEntityName
(
temp
.
get
(
"baseTableName"
).
toString
().
toUpperCase
());
parentMap
.
put
(
temp
.
get
(
"baseColumnNames"
).
toString
(),
parent
);
parentEntities
.
add
(
parentMap
);
// 存入子键map
sub
=
new
MetaRelationship
();
subMap
=
new
ConcurrentHashMap
();
sub
.
setName
(
"DER1N_"
+
temp
.
get
(
"baseTableName"
).
toString
().
toUpperCase
());
sub
.
setCodeName
(
temp
.
get
(
"baseColumnNames"
).
toString
());
sub
.
setEntityName
(
temp
.
get
(
"baseTableName"
).
toString
().
toUpperCase
());
sub
.
setRelationType
(
"DER1N"
);
sub
.
setSystemId
(
commonMessage
.
get
(
0
).
get
(
"author"
).
toString
());
sub
.
setRefEntityName
(
temp
.
get
(
"referencedTableName"
).
toString
().
toUpperCase
());
subMap
.
put
(
temp
.
get
(
"referencedColumnNames"
).
toString
(),
sub
);
subEntities
.
add
(
subMap
);
}
}
// 第一、二层 获取第一个作者以及id
// 第一、二层 获取第一个作者以及id
if
(!
ObjectUtil
.
isEmpty
(
commonMessage
)){
if
(!
ObjectUtil
.
isEmpty
(
commonMessage
)){
sysModel
.
setSystemid
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
sysModel
.
setSystemid
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
sysModel
.
setSystemname
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
sysModel
.
setSystemname
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
}
}
// 第三层 获取实体对象List 在这层
还
可以放入subEntitys、parentEntitys等关系字段
// 第三层 获取实体对象List 在这层可以放入subEntitys、parentEntitys等关系字段
for
(
int
i
=
0
;
i
<
commonMessage
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
commonMessage
.
size
();
i
++)
{
// createTable主要存储了表明以及字段属性,只要crateTable属性,其余剔除
temp
=
(
Map
)
commonMessage
.
get
(
i
).
get
(
"createTable"
);
temp
=
(
Map
)
commonMessage
.
get
(
i
).
get
(
"createTable"
);
if
(
ObjectUtil
.
isEmpty
(
temp
)){
if
(
ObjectUtil
.
isEmpty
(
temp
)){
continue
;
continue
;
}
}
metaEntityModel
=
new
MetaEntityModel
();
metaEntityModel
=
new
MetaEntityModel
();
// 为了获取MetaEntityModel下那些基本类型字段(此处可补充MetaEntityModel等描述字段)
// 为了获取MetaEntityModel下那些基本类型字段(此处可补充MetaEntityModel等描述字段)
metaEntityModel
.
setEntityName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
());
metaEntityModel
.
setEntityName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
());
metaEntityModel
.
setCodeName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
());
metaEntityModel
.
setCodeName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
());
metaEntityModel
.
setTableName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
());
metaEntityModel
.
setTableName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
());
metaEntityModel
.
setLogicName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
());
metaEntityModel
.
setLogicName
(
temp
.
get
(
"tableName"
)
==
null
?
""
:
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
());
// 统一关联sysId
metaEntityModel
.
setSystemId
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
metaEntityModel
.
setSystemId
((
String
)
commonMessage
.
get
(
0
).
get
(
"author"
));
// 属性List
column
=
(
List
<
Map
>)
temp
.
get
(
"column"
);
column
=
(
List
<
Map
>)
temp
.
get
(
"column"
);
// 属性List
List
<
MetaField
>
metaFields
=
new
CopyOnWriteArrayList
<>();
List
<
MetaField
>
metaFields
=
new
CopyOnWriteArrayList
<>();
List
<
MetaRelationship
>
parentRelationships
=
new
CopyOnWriteArrayList
<>();
List
<
MetaRelationship
>
subRelationships
=
new
CopyOnWriteArrayList
<>();
for
(
int
j
=
0
;
j
<
column
.
size
();
j
++){
for
(
int
j
=
0
;
j
<
column
.
size
();
j
++){
// (此处可补充MetaField描述字段,以及父子外键关系等)
// (此处可补充MetaField描述字段,以及父子外键关系等)
metaField
=
new
MetaField
();
metaField
=
new
MetaField
();
metaField
.
setFieldName
(
column
.
get
(
j
).
get
(
"name"
)
==
null
?
""
:
column
.
get
(
j
).
get
(
"name"
).
toString
());
metaField
.
setFieldName
(
column
.
get
(
j
).
get
(
"name"
)
==
null
?
""
:
column
.
get
(
j
).
get
(
"name"
).
toString
());
metaField
.
setDataType
(
column
.
get
(
j
).
get
(
"type"
)
==
null
?
""
:
fieldToName
(
column
.
get
(
j
).
get
(
"type"
).
toString
()));
metaField
.
setDataType
(
column
.
get
(
j
).
get
(
"type"
)
==
null
?
""
:
fieldToName
(
column
.
get
(
j
).
get
(
"type"
).
toString
()));
metaField
.
setDataLength
(
column
.
get
(
j
).
get
(
"type"
)
==
null
?
0
:
fieldToLenth
(
column
.
get
(
j
).
get
(
"type"
).
toString
()));
metaField
.
setDataLength
(
column
.
get
(
j
).
get
(
"type"
)
==
null
?
0
:
fieldToLength
(
column
.
get
(
j
).
get
(
"type"
).
toString
()));
metaField
.
setNullable
(
column
.
get
(
j
).
get
(
"constraints"
)
!=
null
?
1
:
0
);
Map
<
String
,
List
<
Map
>>
map
=
(
Map
<
String
,
List
<
Map
>>)
column
.
get
(
j
).
get
(
"constraints"
);
metaField
.
setKeyField
(
column
.
get
(
j
).
get
(
"primaryKey"
)
!=
null
?
1
:
0
);
if
(!
ObjectUtil
.
isEmpty
(
map
)){
metaField
.
setNullable
(
map
.
get
(
"nullable"
)==
null
?
0
:
1
);
metaField
.
setKeyField
(
map
.
get
(
"primaryKey"
)==
null
?
0
:
1
);
}
else
{
metaField
.
setNullable
(
0
);
metaField
.
setKeyField
(
0
);
}
String
name
=
column
.
get
(
j
).
get
(
"name"
)
==
null
?
""
:
column
.
get
(
j
).
get
(
"name"
).
toString
();
// 若在父键表查有该数据且属于同一实体则记录一条
for
(
int
l
=
0
;
l
<
parentEntities
.
size
();
l
++){
if
(
name
.
equals
(
parentEntities
.
get
(
l
).
keySet
().
toString
().
replaceAll
(
"[\\[\\]]"
,
""
))){
if
(
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
().
equals
(
parentEntities
.
get
(
l
).
get
(
name
).
getRefEntityName
()))
{
parentEntities
.
get
(
l
).
get
(
name
).
setEntityId
(
metaField
.
getEntityId
());
parentRelationships
.
add
(
parentEntities
.
get
(
l
).
get
(
name
));
}
}
}
metaEntityModel
.
setParentEntitys
(
parentRelationships
);
// 若在子键表查有该数据且属于同一实体则记录一条
for
(
int
l
=
0
;
l
<
subEntities
.
size
();
l
++){
if
(
name
.
equals
(
subEntities
.
get
(
l
).
keySet
().
toString
().
replaceAll
(
"[\\[\\]]"
,
""
))){
if
(
temp
.
get
(
"tableName"
).
toString
().
toUpperCase
().
equals
(
subEntities
.
get
(
l
).
get
(
name
).
getRefEntityName
())){
subRelationships
.
add
(
subEntities
.
get
(
l
).
get
(
name
));
}
}
}
metaEntityModel
.
setSubEntitys
(
subRelationships
);
metaField
.
setPhysicalField
(
1
);
metaField
.
setPhysicalField
(
1
);
metaFields
.
add
(
metaField
);
metaFields
.
add
(
metaField
);
}
}
metaEntityModel
.
setFields
(
metaFields
);
metaEntityModel
.
setFields
(
metaFields
);
metaEntityModels
.
add
(
metaEntityModel
);
metaEntityModels
.
add
(
metaEntityModel
);
sysModel
.
setEntities
(
metaEntityModels
);
sysModel
.
setEntities
(
metaEntityModels
);
}
}
return
sysModel
;
return
sysModel
;
}
}
private
static
Integer
fieldToLenth
(
String
s
)
{
private
static
Integer
fieldToLen
g
th
(
String
s
)
{
if
(
s
.
contains
(
"("
))
{
if
(
s
.
contains
(
"("
))
{
String
newStr
=
s
.
substring
(
s
.
indexOf
(
"("
)
+
1
,
s
.
indexOf
(
")"
));
String
newStr
=
s
.
substring
(
s
.
indexOf
(
"("
)
+
1
,
s
.
indexOf
(
")"
));
return
Integer
.
valueOf
(
newStr
);
return
Integer
.
valueOf
(
newStr
);
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录