Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
1eeae3cc
提交
1eeae3cc
authored
4月 02, 2021
作者:
ww1xhqc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 新增聚合对象增加接口(xml工具)。
上级
ea256d2b
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
367 行增加
和
112 行删除
+367
-112
WorkFlowCoreNoScan.java
...kflowcore/model_layer/annotations/WorkFlowCoreNoScan.java
+1
-1
AggregationController.java
...lowcore/model_layer/controller/AggregationController.java
+28
-0
AggregationRelationshipDao.java
...kflowcore/model_layer/dao/AggregationRelationshipDao.java
+17
-0
TableInfoExDao.java
...com/tykj/workflowcore/model_layer/dao/TableInfoExDao.java
+2
-2
AggregationRelationship.java
...kflowcore/model_layer/entity/AggregationRelationship.java
+45
-0
TableInfoEx.java
...com/tykj/workflowcore/model_layer/entity/TableInfoEx.java
+5
-9
AggregationVO.java
...ykj/workflowcore/model_layer/entity/vo/AggregationVO.java
+40
-0
AggregationType.java
...tykj/workflowcore/model_layer/myEnum/AggregationType.java
+11
-3
ModelType.java
...a/com/tykj/workflowcore/model_layer/myEnum/ModelType.java
+9
-0
AggregationService.java
.../workflowcore/model_layer/service/AggregationService.java
+7
-2
AggregationImpl.java
...orkflowcore/model_layer/service/impl/AggregationImpl.java
+62
-6
AggregationUtil.java
.../tykj/workflowcore/model_layer/utils/AggregationUtil.java
+117
-66
WorkflowCoreApplicationTests.java
...a/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
+23
-23
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/annotations/WorkFlowCoreNoScan.java
浏览文件 @
1eeae3cc
...
@@ -7,7 +7,7 @@ import java.lang.annotation.Target;
...
@@ -7,7 +7,7 @@ import java.lang.annotation.Target;
/**
/**
* @ClassName WorkFlowCoreNoScan
* @ClassName WorkFlowCoreNoScan
* @Description TODO
* @Description TODO
工作流模块不扫描
* @Author WWW
* @Author WWW
* @Date 2021/3/1 14:19
* @Date 2021/3/1 14:19
* @Version 1.0
* @Version 1.0
...
...
src/main/java/com/tykj/workflowcore/model_layer/controller/AggregationController.java
0 → 100644
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
controller
;
import
com.tykj.workflowcore.model_layer.entity.vo.AggregationVO
;
import
com.tykj.workflowcore.model_layer.service.AggregationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @ClassName AggregationController
* @Description TODO
* @Author WWW
* @Date 2021/4/2 11:19
* @Version 1.0
*/
@RestController
public
class
AggregationController
{
@Autowired
AggregationService
aggregationService
;
@PostMapping
(
"aggregation/add"
)
public
void
add
(
@RequestBody
AggregationVO
aggregationVO
)
{
aggregationService
.
addAggregation
(
aggregationVO
);
}
}
src/main/java/com/tykj/workflowcore/model_layer/dao/AggregationRelationshipDao.java
0 → 100644
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
dao
;
import
com.tykj.workflowcore.model_layer.entity.AggregationRelationship
;
import
com.tykj.workflowcore.model_layer.entity.ColumnInfo
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @ClassName AggregationRelationshipDao
* @Description TODO
* @Author WWW
* @Date 2021/4/2 10:34
* @Version 1.0
*/
public
interface
AggregationRelationshipDao
extends
JpaRepository
<
AggregationRelationship
,
Integer
>,
JpaSpecificationExecutor
<
AggregationRelationship
>
{
}
src/main/java/com/tykj/workflowcore/model_layer/dao/TableInfoExDao.java
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
dao
;
package
com
.
tykj
.
workflowcore
.
model_layer
.
dao
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoE
X
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoE
x
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
...
@@ -12,5 +12,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
...
@@ -12,5 +12,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @Date 2021/4/1 17:00
* @Date 2021/4/1 17:00
* @Version 1.0
* @Version 1.0
*/
*/
public
interface
TableInfoExDao
extends
JpaRepository
<
TableInfoE
X
,
Integer
>,
JpaSpecificationExecutor
<
TableInfoEX
>
{
public
interface
TableInfoExDao
extends
JpaRepository
<
TableInfoE
x
,
Integer
>,
JpaSpecificationExecutor
<
TableInfoEx
>
{
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/AggregationRelationship.java
0 → 100644
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
entity
;
import
com.tykj.workflowcore.base.entity.BaseEntity
;
import
com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Entity
;
/**
* @ClassName AggregationRelationship
* @Description TODO
* @Author WWW
* @Date 2021/4/2 9:49
* @Version 1.0
*/
@WorkFlowCoreNoScan
@Data
@NoArgsConstructor
@Entity
@SQLDelete
(
sql
=
"update column_info set deleted = 1 where id = ?"
)
@Where
(
clause
=
"deleted = 0"
)
public
class
AggregationRelationship
extends
BaseEntity
{
@ApiModelProperty
(
"聚合对象ID"
)
private
Integer
tableInfoExId
;
@ApiModelProperty
(
"附表id"
)
private
Integer
sideTableId
;
@ApiModelProperty
(
"聚合对象关系"
)
private
Integer
relationship
;
@ApiModelProperty
(
"主表连接属性"
)
private
String
mainTableConnectionKey
;
@ApiModelProperty
(
"副表连接属性"
)
private
String
sideTableConnectionKey
;
@ApiModelProperty
(
"中间表名称"
)
private
String
connectionTableName
;
}
src/main/java/com/tykj/workflowcore/model_layer/entity/TableInfoE
X
.java
→
src/main/java/com/tykj/workflowcore/model_layer/entity/TableInfoE
x
.java
浏览文件 @
1eeae3cc
...
@@ -24,26 +24,22 @@ import javax.persistence.Lob;
...
@@ -24,26 +24,22 @@ import javax.persistence.Lob;
@Entity
@Entity
@SQLDelete
(
sql
=
"update column_info set deleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"update column_info set deleted = 1 where id = ?"
)
@Where
(
clause
=
"deleted = 0"
)
@Where
(
clause
=
"deleted = 0"
)
public
class
TableInfoE
X
extends
BaseEntity
{
public
class
TableInfoE
x
extends
BaseEntity
{
@ApiModelProperty
(
"名称"
)
@ApiModelProperty
(
"名称"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"描述"
)
private
String
description
;
@ApiModelProperty
(
"主表id"
)
@ApiModelProperty
(
"主表id"
)
private
Integer
mainTableId
;
private
Integer
mainTableId
;
@ApiModelProperty
(
"附表id"
)
private
Integer
sideTableId
;
@Lob
@Lob
@ApiModelProperty
(
"聚合对象xml"
)
@ApiModelProperty
(
"聚合对象xml"
)
private
String
xml
;
private
String
xml
;
@ApiModelProperty
(
"聚合对象关系"
)
private
Integer
relationship
;
@ApiModelProperty
(
"连接属性"
)
private
String
connectionProperty
;
@ApiModelProperty
(
"连接key"
)
private
String
connectionKey
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/vo/AggregationVO.java
0 → 100644
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
entity
.
vo
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.tykj.workflowcore.model_layer.entity.AggregationRelationship
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEx
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
/**
* @ClassName AggregationVO
* @Description TODO
* @Author WWW
* @Date 2021/4/2 9:51
* @Version 1.0
*/
@ApiModel
(
"聚合信息"
)
@Data
public
class
AggregationVO
{
@ApiModelProperty
(
"名称"
)
private
String
name
;
@ApiModelProperty
(
"描述"
)
private
String
description
;
@ApiModelProperty
(
"主表id"
)
private
Integer
mainTableId
;
@ApiModelProperty
(
"关系集合"
)
private
List
<
AggregationRelationship
>
lists
;
public
TableInfoEx
getTableInfoEx
(){
TableInfoEx
tableInfoEx
=
new
TableInfoEx
();
BeanUtil
.
copyProperties
(
this
,
tableInfoEx
);
return
tableInfoEx
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/myEnum/AggregationType.java
浏览文件 @
1eeae3cc
...
@@ -2,15 +2,23 @@ package com.tykj.workflowcore.model_layer.myEnum;
...
@@ -2,15 +2,23 @@ package com.tykj.workflowcore.model_layer.myEnum;
/**
/**
* @ClassName AggregationType
* @ClassName AggregationType
* @Description TODO
* @Description TODO
聚合对象的关系
* @Author WWW
* @Author WWW
* @Date 2021/4/1 16:56
* @Date 2021/4/1 16:56
* @Version 1.0
* @Version 1.0
*/
*/
public
class
AggregationType
{
public
class
AggregationType
{
/**
* 一对一关系
*/
public
static
final
Integer
ONE_TO_ONE
=
0
;
public
static
final
Integer
ONE_TO_ONE
=
0
;
/**
* 一对多关系
*/
public
static
final
Integer
ONE_TO_MANY
=
1
;
public
static
final
Integer
ONE_TO_MANY
=
1
;
/**
public
static
final
Integer
MANY_TO_MANY
=
0
;
* 多对多关系
*/
public
static
final
Integer
MANY_TO_MANY
=
2
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/myEnum/ModelType.java
浏览文件 @
1eeae3cc
...
@@ -9,8 +9,17 @@ package com.tykj.workflowcore.model_layer.myEnum;
...
@@ -9,8 +9,17 @@ package com.tykj.workflowcore.model_layer.myEnum;
*/
*/
public
class
ModelType
{
public
class
ModelType
{
/**
* 基础扫描对象
*/
public
static
final
Integer
BASICS
=
0
;
public
static
final
Integer
BASICS
=
0
;
/**
* 业务对象
*/
public
static
final
Integer
BUSINESS
=
1
;
public
static
final
Integer
BUSINESS
=
1
;
/**
* 基础对象延伸
*/
public
static
final
Integer
BASICS_EXTENSION
=
2
;
public
static
final
Integer
BASICS_EXTENSION
=
2
;
...
...
src/main/java/com/tykj/workflowcore/model_layer/service/AggregationService.java
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
service
;
package
com
.
tykj
.
workflowcore
.
model_layer
.
service
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEX
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEx
;
import
com.tykj.workflowcore.model_layer.entity.vo.AggregationVO
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
...
@@ -13,5 +14,9 @@ import org.springframework.stereotype.Service;
...
@@ -13,5 +14,9 @@ import org.springframework.stereotype.Service;
@Service
@Service
public
interface
AggregationService
{
public
interface
AggregationService
{
void
addAggregationOneToOne
(
TableInfoEX
tableInfoEX
);
/**
* 保存聚合对象
* @param aggregationVO
*/
void
addAggregation
(
AggregationVO
aggregationVO
);
}
}
src/main/java/com/tykj/workflowcore/model_layer/service/impl/AggregationImpl.java
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
service
.
impl
;
package
com
.
tykj
.
workflowcore
.
model_layer
.
service
.
impl
;
import
com.tykj.workflowcore.base.result.ApiException
;
import
com.tykj.workflowcore.model_layer.dao.AggregationRelationshipDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoExDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoExDao
;
import
com.tykj.workflowcore.model_layer.entity.AggregationRelationship
;
import
com.tykj.workflowcore.model_layer.entity.TableInfo
;
import
com.tykj.workflowcore.model_layer.entity.TableInfo
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEX
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEx
;
import
com.tykj.workflowcore.model_layer.entity.vo.AggregationVO
;
import
com.tykj.workflowcore.model_layer.myEnum.AggregationType
;
import
com.tykj.workflowcore.model_layer.service.AggregationService
;
import
com.tykj.workflowcore.model_layer.service.AggregationService
;
import
com.tykj.workflowcore.model_layer.utils.AggregationUtil
;
import
org.dom4j.Document
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.UUID
;
/**
/**
* @ClassName AggregationImpl
* @ClassName AggregationImpl
...
@@ -16,19 +26,65 @@ import java.util.Optional;
...
@@ -16,19 +26,65 @@ import java.util.Optional;
* @Date 2021/4/1 17:24
* @Date 2021/4/1 17:24
* @Version 1.0
* @Version 1.0
*/
*/
@Service
public
class
AggregationImpl
implements
AggregationService
{
public
class
AggregationImpl
implements
AggregationService
{
@Autowired
@Autowired
TableInfoDao
tableInfoDao
;
TableInfoDao
tableInfoDao
;
@Autowired
@Autowired
TableInfoExDao
tableInfoExDao
;
TableInfoExDao
tableInfoExDao
;
@Autowired
AggregationRelationshipDao
aggregationRelationshipDao
;
@Override
public
void
addAggregation
(
AggregationVO
aggregationVO
)
{
Document
mainTableDocument
;
//获取主表XML
Integer
mainTableId
=
aggregationVO
.
getMainTableId
();
Optional
<
TableInfo
>
mainTableById
=
tableInfoDao
.
findById
(
mainTableId
);
if
(
mainTableById
.
isPresent
()){
mainTableDocument
=
AggregationUtil
.
getDocument
(
mainTableById
.
get
().
getXml
());
}
else
{
throw
new
ApiException
(
"主表不存在"
);
}
//改CLASS名字
AggregationUtil
.
changeClassName
(
aggregationVO
.
getName
(),
mainTableDocument
);
// save TableInfoEx (name des mainTableId)
TableInfoEx
tableInfoEx
=
tableInfoExDao
.
save
(
aggregationVO
.
getTableInfoEx
());
// 遍历VO 根据聚合类型 生成对应的 XML 节点 并添加到DOCUMENT中
for
(
AggregationRelationship
aggregationRelationship
:
aggregationVO
.
getLists
())
{
//取出副表的tableinfo
Optional
<
TableInfo
>
sideTableById
=
tableInfoDao
.
findById
(
aggregationRelationship
.
getSideTableId
());
aggregationRelationship
.
setTableInfoExId
(
tableInfoEx
.
getId
());
if
(!
sideTableById
.
isPresent
()){
throw
new
ApiException
(
"id为:"
+
aggregationRelationship
.
getSideTableId
()+
"的副表不存在"
);
}
if
(
aggregationRelationship
.
getRelationship
().
equals
(
AggregationType
.
ONE_TO_ONE
)){
AggregationUtil
.
addOneToOne
(
aggregationRelationship
.
getSideTableConnectionKey
(),
sideTableById
.
get
().
getModelName
(),
mainTableDocument
);
}
if
(
aggregationRelationship
.
getRelationship
().
equals
(
AggregationType
.
ONE_TO_MANY
)){
//如果是一对多需要 为 aggregationRelationship 生成连接的KEY
String
mainTableConnectionKey
=
sideTableById
.
get
().
getModelName
()+
"List"
;
AggregationUtil
.
addOneToMany
(
sideTableById
.
get
().
getModelName
(),
mainTableConnectionKey
,
aggregationRelationship
.
getSideTableConnectionKey
(),
mainTableDocument
);
}
if
(
aggregationRelationship
.
getRelationship
().
equals
(
AggregationType
.
MANY_TO_MANY
)){
//如果是多对多需要 为 aggregationRelationship 生成连接的KEY
String
mainTableConnectionKey
=
mainTableById
.
get
().
getModelName
()+
"_Id"
;
String
sideTableConnectionKey
=
sideTableById
.
get
().
getModelName
()+
"_Id"
;
aggregationRelationship
.
setMainTableConnectionKey
(
mainTableConnectionKey
);
aggregationRelationship
.
setSideTableConnectionKey
(
sideTableConnectionKey
);
//如果是多对多需要 为 aggregationRelationship 生成连接的中间表名
String
ConnectionTableName
=
mainTableById
.
get
().
getModelName
()+
"_"
+
sideTableById
.
get
().
getModelName
()+
"_"
+
(
UUID
.
randomUUID
().
toString
().
substring
(
0
,
8
));
aggregationRelationship
.
setConnectionTableName
(
ConnectionTableName
);
//Util.addManyToMany
AggregationUtil
.
addManyToMany
(
sideTableById
.
get
().
getModelName
(),
ConnectionTableName
,
mainTableConnectionKey
,
sideTableConnectionKey
,
mainTableDocument
);
}
aggregationRelationshipDao
.
save
(
aggregationRelationship
);
}
@Override
public
void
addAggregationOneToOne
(
TableInfoEX
tableInfoEX
)
{
}
}
}
}
src/main/java/com/tykj/workflowcore/model_layer/utils/AggregationUtil.java
浏览文件 @
1eeae3cc
package
com
.
tykj
.
workflowcore
.
model_layer
.
utils
;
package
com
.
tykj
.
workflowcore
.
model_layer
.
utils
;
import
com.tykj.workflowcore.base.result.ApiException
;
import
com.tykj.workflowcore.model_layer.myEnum.AggregationType
;
import
liquibase.pro.packaged.E
;
import
liquibase.pro.packaged.E
;
import
org.dom4j.Document
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentException
;
import
org.dom4j.DocumentException
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.Element
;
import
org.dom4j.Element
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* @ClassName AggregationUtil
* @ClassName AggregationUtil
* @Description TODO
* @Description TODO
生成聚合对象xml
* @Author WWW
* @Author WWW
* @Date 2021/4/1 18:59
* @Date 2021/4/1 18:59
* @Version 1.0
* @Version 1.0
*/
*/
public
class
AggregationUtil
{
public
class
AggregationUtil
{
private
static
String
xmlStart
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
public
static
Document
getDocument
(
String
xml
){
"<!DOCTYPE hibernate-mapping PUBLIC\n"
+
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n"
+
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n"
+
"<hibernate-mapping>"
;
private
static
String
xmlEnd
=
"</hibernate-mapping>"
;
public
static
String
getOldProperty
(
String
xml
)
{
String
property
=
""
;
Document
document
=
null
;
try
{
try
{
document
=
DocumentHelper
.
parseText
(
xml
);
return
DocumentHelper
.
parseText
(
xml
);
}
catch
(
DocumentException
e
)
{
}
catch
(
DocumentException
e
)
{
e
.
printStackTrace
(
);
throw
new
ApiException
(
"XML格式不正确"
);
}
}
List
<
Element
>
elements
=
document
.
getRootElement
().
elements
().
get
(
0
).
elements
();
for
(
Element
element
:
elements
)
{
property
=
property
+
element
.
asXML
();
}
return
property
;
}
}
public
static
Document
changeClassName
(
String
className
,
Document
document
){
Element
aClass
=
getNode
(
document
);
aClass
.
attribute
(
"entity-name"
).
setValue
(
className
);
return
aClass
.
getDocument
();
}
public
static
String
addOneToOne
(
String
field
,
String
sideTableName
,
String
xml
)
{
public
static
Document
addOneToOne
(
String
field
,
String
sideTableName
,
Document
document
)
{
Element
element
=
DocumentHelper
.
createElement
(
"one-to-one"
);
Element
element
=
DocumentHelper
.
createElement
(
"one-to-one"
);
element
.
addAttribute
(
"name"
,
field
);
element
.
addAttribute
(
"name"
,
field
);
element
.
addAttribute
(
"class"
,
sideTableName
);
element
.
addAttribute
(
"class"
,
sideTableName
);
element
.
addAttribute
(
"cascade"
,
"save-update"
);
element
.
addAttribute
(
"cascade"
,
"save-update"
);
Element
classElement
=
getNode
(
document
);
Document
document
=
null
;
try
{
document
=
DocumentHelper
.
parseText
(
xml
);
}
catch
(
DocumentException
e
)
{
e
.
printStackTrace
();
}
Element
classElement
=
getNode
(
xml
);
classElement
.
add
(
element
);
classElement
.
add
(
element
);
return
document
;
return
document
.
asXML
();
}
}
public
static
Document
addOneToMany
(
String
sideTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
,
Document
document
)
{
public
static
String
addOneToMany
(
String
mainTable
,
String
sideTable
,
String
mainField
,
String
xml
)
{
//创建ELEMTN
Element
setElement
=
createSetElement
(
mainTableConnectionKey
,
sideTableName
,
""
,
mainTableConnectionKey
,
sideTableConnectionKey
,
AggregationType
.
ONE_TO_MANY
);
//创建结束
String
addStr
=
Element
classElement
=
getNode
(
document
);
"<class entity-name= \""
+
mainTable
+
"_"
+
sideTable
+
"\""
+
" table=\""
+
mainTable
+
"\""
+
">\n"
+
classElement
.
add
(
setElement
);
getOldProperty
(
xml
)
+
return
document
;
" <set name=\""
+
sideTable
+
"_list"
+
"\""
+
" inverse=\"true\" lazy=\"true\">\n"
+
" <key column=\""
+
mainField
+
"\""
+
"/>\n"
+
" <one-to-many class=\""
+
sideTable
+
"\""
+
"/>\n"
+
"</set>\n"
+
" </class>"
;
return
xmlStart
+
addStr
+
xmlEnd
;
}
}
public
static
String
addManyToMany
(
String
mainTable
,
String
sideTable
,
String
xml
)
{
String
entityName
=
mainTable
+
"_"
+
sideTable
+
"_ref"
;
public
static
Document
addManyToMany
(
String
sideTableName
,
String
connectionTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
,
Document
document
)
{
Element
setElement
=
createSetElement
(
sideTableName
,
sideTableName
,
connectionTableName
,
mainTableConnectionKey
,
sideTableConnectionKey
,
AggregationType
.
MANY_TO_MANY
);
//创建结束
Element
classElement
=
getNode
(
document
);
classElement
.
add
(
setElement
);
return
document
;
}
String
addStr
=
"<class entity-name=\""
+
entityName
+
"\""
+
" table=\""
+
mainTable
+
"\""
+
">\n"
+
public
static
Element
getNode
(
Document
document
)
{
" \n"
return
document
.
getRootElement
().
element
(
"class"
);
+
getOldProperty
(
xml
)
+
" <set name=\""
+
sideTable
+
"\""
+
" table=\""
+
entityName
+
"\""
+
">\n"
+
" \t<key column=\""
+
mainTable
+
"_id"
+
"\""
+
"/>\n"
+
" \t<many-to-many class=\""
+
sideTable
+
"\""
+
" column=\""
+
sideTable
+
"\""
+
"_id"
+
"/>\n"
+
" </set>"
+
"</class>"
;
return
xmlStart
+
addStr
+
xmlEnd
;
}
}
public
static
Element
getNode
(
String
xml
)
{
public
static
Element
createSetElement
(
String
setName
,
String
sideTableName
,
String
connectionTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
,
Integer
type
){
Document
document
=
null
;
//创建ELEMTN
try
{
Element
elementSet
=
DocumentHelper
.
createElement
(
"set"
);
document
=
DocumentHelper
.
parseText
(
xml
);
elementSet
.
addAttribute
(
"name"
,
setName
);
}
catch
(
DocumentException
e
)
{
elementSet
.
addAttribute
(
"cascade"
,
"save-update"
);
e
.
printStackTrace
();
Element
elementKey
=
DocumentHelper
.
createElement
(
"key"
);
if
(
type
.
equals
(
AggregationType
.
MANY_TO_MANY
)){
elementSet
.
addAttribute
(
"table"
,
connectionTableName
);
elementKey
.
addAttribute
(
"column"
,
mainTableConnectionKey
);
elementSet
.
add
(
elementKey
);
Element
elementManyToMany
=
DocumentHelper
.
createElement
(
"many-to-many"
);
elementManyToMany
.
addAttribute
(
"class"
,
sideTableName
);
elementManyToMany
.
addAttribute
(
"column"
,
sideTableConnectionKey
);
elementSet
.
add
(
elementManyToMany
);
}
else
if
(
type
.
equals
(
AggregationType
.
ONE_TO_MANY
)){
elementKey
.
addAttribute
(
"column"
,
sideTableConnectionKey
);
elementSet
.
add
(
elementKey
);
Element
elementOneToMany
=
DocumentHelper
.
createElement
(
"one-to-many"
);
elementOneToMany
.
addAttribute
(
"class"
,
sideTableName
);
elementSet
.
add
(
elementOneToMany
);
}
}
return
document
.
getRootElement
().
elements
().
get
(
0
);
return
elementSet
;
}
}
// private static String xmlStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
// "<!DOCTYPE hibernate-mapping PUBLIC\n" +
// " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
// " \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
// "<hibernate-mapping>";
//
// private static String xmlEnd = "</hibernate-mapping>";
//
//
// public static String getOldProperty(String xml) {
// String property = "";
// Document document = null;
// try {
// document = DocumentHelper.parseText(xml);
// } catch (DocumentException e) {
// e.printStackTrace();
// }
// List<Element> elements = document.getRootElement().elements().get(0).elements();
// for (Element element : elements) {
// property = property + element.asXML();
// }
// return property;
// }
//
//
//
//
// public static String addOneToMany(String mainTable, String sideTable, String mainField, String xml) {
//
//
// String addStr =
// "<class entity-name= \"" +mainTable + "_" + sideTable + "\""+" table=\"" + mainTable +"\""+ ">\n" +
// getOldProperty(xml) +
// " <set name=\"" + sideTable + "_list" + "\""+" inverse=\"true\" lazy=\"true\">\n" +
// " <key column=\"" + mainField + "\""+"/>\n" +
// " <one-to-many class=\"" + sideTable +"\""+ "/>\n" +
// "</set>\n" +
// " </class>";
//
//
// return xmlStart+ addStr+xmlEnd;
// }
//
//
// public static String addManyToMany(String mainTable, String sideTable, String xml) {
//
// String entityName = mainTable + "_" + sideTable + "_ref";
//
// String addStr = "<class entity-name=\"" + entityName +"\""+ " table=\"" + mainTable +"\""+ ">\n" +
// " \n"
// +
// getOldProperty(xml)
// +
// " <set name=\"" + sideTable+"\"" + " table=\"" + entityName+"\"" + ">\n" +
// " \t<key column=\"" + mainTable + "_id" +"\""+ "/>\n" +
// " \t<many-to-many class=\"" + sideTable +"\""+ " column=\"" + sideTable +"\""+ "_id" + "/>\n" +
// " </set>" +
// "</class>";
// return xmlStart+ addStr+xmlEnd;
// }
//
}
}
src/main/test/java/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
浏览文件 @
1eeae3cc
...
@@ -442,28 +442,28 @@ class WorkflowCoreApplicationTests {
...
@@ -442,28 +442,28 @@ class WorkflowCoreApplicationTests {
}
}
}
}
@Test
//
@Test
public
void
tsetCreateXml1
(){
//
public void tsetCreateXml1(){
TableInfo
wife
=
tableInfoDao
.
findByModelName
(
"car"
);
//
TableInfo wife = tableInfoDao.findByModelName("car");
// System.out.println(wife);
//
//
System.out.println(wife);
String
s
=
AggregationUtil
.
addOneToOne
(
"wife_id"
,
"husband"
,
wife
.
getXml
());
//
String s = AggregationUtil.addOneToOne("wife_id", "husband", wife.getXml());
System
.
out
.
println
(
s
);
//
System.out.println(s);
}
//
}
@Test
//
@Test
public
void
tsetCreateXml2
(){
//
public void tsetCreateXml2(){
TableInfo
people
=
tableInfoDao
.
findByModelName
(
"people"
);
//
TableInfo people = tableInfoDao.findByModelName("people");
String
xml
=
people
.
getXml
();
//
String xml = people.getXml();
//
String
s
=
AggregationUtil
.
addOneToMany
(
"people"
,
"car"
,
"p_id"
,
xml
);
//
String s = AggregationUtil.addOneToMany("people", "car", "p_id", xml);
System
.
out
.
println
(
s
);
//
System.out.println(s);
}
//
}
@Test
//
@Test
public
void
tsetCreateXml3
(){
//
public void tsetCreateXml3(){
TableInfo
teacher
=
tableInfoDao
.
findByModelName
(
"teacher"
);
//
TableInfo teacher = tableInfoDao.findByModelName("teacher");
//
String
xml
=
teacher
.
getXml
();
//
String xml = teacher.getXml();
String
s
=
AggregationUtil
.
addManyToMany
(
"teacher"
,
"stus"
,
xml
);
//
String s = AggregationUtil.addManyToMany("teacher", "stus", xml);
System
.
out
.
println
(
s
);
//
System.out.println(s);
}
//
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论