文章目录
- 一、流程部署涉及表及其结构
- 1. 部署流程代码示例:
- 2. 流程部署所涉及表:
- 3. 流程部署涉及表的结构、字段解析
- 二、流程部署中数据的存储的过程
一、流程部署涉及表及其结构
1. 部署流程代码示例:
- 设计俩个流程,并压缩成zip包。
- 代码:
package com.hx; import org.flowable.engine.*; import org.flowable.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration; import org.flowable.engine.repository.Deployment; import org.junit.Before; import org.junit.Test; import java.io.InputStream; import java.util.zip.ZipInputStream; /** * @author Huathy * @date 2023-01-08 21:57 * @description */ public class Test4_ProcessDeploy { ProcessEngineConfiguration configuration = null; ProcessEngine processEngine = null; @Before public void before() { // 通过 ProcessEngineConfiguration 构建我们需要的 ProcessEngine configuration = new StandaloneInMemProcessEngineConfiguration(); // 配置相关数据库连接 configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver"); configuration.setJdbcUsername("root"); configuration.setJdbcPassword("admin"); configuration.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/flowable_learn?useSSL=false&serverTimezone=UTC"); // 如果数据库中的表结构不存在则新建 configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); processEngine = configuration.buildProcessEngine(); } /** * 流程部署:涉及到三张表 * 流程部署表:ACT_RE_DEPLOYMENT一次流程部署操作就会产生一条记录 * 流程定义表:ACT_RE_PROCDEF 一次流程部署操作中包含几个流程定义文件就会产生几条记录 * 流程定义资源表:ACT_GE_BYTEARRAY 有多少资源就会产生几条记录 */ @Test public void test1_deploy(){ RepositoryService repositoryService = processEngine.getRepositoryService(); InputStream ins = this.getClass().getClassLoader().getResourceAsStream("holidayAndProcess.zip"); ZipInputStream zipIns = new ZipInputStream(ins); // 流程部署操作,关联zip或者bar文件 Deployment deploy = repositoryService.createDeployment() // .addClasspathResource("MyProcess.bpmn20.xml") .addZipInputStream(zipIns) .name("请假流程") .category("请假") // 分类 .tenantId("whx") // 租户ID .deploy(); System.out.println("deploy.getId() = " + deploy.getId()); System.out.println("deploy.getName() = " + deploy.getName()); System.out.println("deploy.getCategory() = " + deploy.getCategory()); } }
- 测试运行结果
2. 流程部署所涉及表:
查看表结构与数据变动(其中ACT_RE_DEPLOYMENT的一条记录可以对应ACT_RE_PROCDEF的多条记录)
- 流程部署表:ACT_RE_DEPLOYMENT(一次流程部署操作就会产生一条记录)
- 流程定义表:ACT_RE_PROCDEF(一次流程部署操作中包含几个流程定义文件就会产生几条记录)
ID_ |REV_|CATEGORY_ |NAME_ |KEY_ |VERSION_|DEPLOYMENT_ID_|RESOURCE_NAME_ |DGRM_RESOURCE_NAME_ |DESCRIPTION_ |HAS_START_FORM_KEY_|HAS_GRAPHICAL_NOTATION_|SUSPENSION_STATE_|TENANT_ID_|ENGINE_VERSION_|DERIVED_FROM_|DERIVED_FROM_ROOT_|DERIVED_VERSION_| ---------------+----+----------------------------------+-----------+-----------+--------+--------------+----------------------+---------------------------+---------------+-------------------+-----------------------+-----------------+----------+---------------+-------------+------------------+----------------+ MyHolidayUI:1:7| 1|http://www.flowable.org/processdef|MyHolidayUI|MyHolidayUI| 1|1 |MyHolidayUI.bpmn20.xml|MyHolidayUI.MyHolidayUI.png|MyHolidayUI请假流程| 0| 1| 1|whx | | | | 0| MyProcess:1:6 | 1|http://www.flowable.org/processdef|MyProcess |MyProcess | 1|1 |MyProcess.bpmn20.xml |MyProcess.MyProcess.png |请假流程 | 0| 1| 1|whx | | | | 0|
- 流程定义资源表:ACT_GE_BYTEARRAY(有多少资源就会产生几条记录)
3. 流程部署涉及表的结构、字段解析
- 流程部署表:ACT_RE_DEPLOYMENT
字段 | 含义与注释 |
---|---|
ID_ | 主键 |
NAME_ | 名称 |
CATEGORY_ | 分类 |
KEY_ | |
TENANT_ID_ | 租户ID |
DEPLOY_TIME_ | 部署事件 |
DERIVED_FROM_ | 来源于 |
DERIVED_FROM_ROOT_ | 来源于 |
ENGINE_VERSION_ | 引擎版本号 |
2. 流程定义表:ACT_RE_PROCDEF
Name | Value |
---|---|
ID_ | 自动生成的ID |
REV_ | 1 |
CATEGORY_ | 流程定义的namespace |
NAME_ | 每个流程的名称 |
KEY_ | 自己定义的ID |
VERSION_ | 1 |
DEPLOYMENT_ID_ | 部署关联的ID |
RESOURCE_NAME_ | 资源名称 |
DGRM_RESOURCE_NAME_ | 图片 |
DESCRIPTION_ | MyHolidayUI请假流程 |
HAS_START_FORM_KEY_ | 0 |
HAS_GRAPHICAL_NOTATION_ | 1 |
SUSPENSION_STATE_ | 当前流程的状态,1正常,2挂起 |
TENANT_ID_ | 租户ID。可关联用户。 |
ENGINE_VERSION_ | |
DERIVED_FROM_ | |
DERIVED_FROM_ROOT_ | |
DERIVED_VERSION_ | 0 |
- 部署资源表:ACT_GE_BYTEARRAY
字段 | 含义及备注 |
---|---|
ID_ | 主键 |
REV_ | 版本号 |
NAME_ | 部署的文件名称(如MyProcess.bpmn20.xml) |
DEPLOYMENT_ID_ | 部署ID |
BYTES_ | 字节(二进制数据) |
GENERATED_ | 是否系统生成。 (0为用户上传,1为系统生成。比如系统会自动根据xml生成png文件) |
二、流程部署中数据的存储的过程
// 我们一路跟踪代码的方法
// org.flowable.engine.repository.DeploymentBuilder#deploy
// org.flowable.engine.common.impl.interceptor.CommandExecutor#execute(org.flowable.engine.common.impl.interceptor.Command<T>)
// 进入 org.flowable.engine.impl.cmd.DeployCmd 类
// 看到执行器方法 org.flowable.engine.impl.cmd.DeployCmd#execute
// org.flowable.engine.impl.cmd.DeployCmd#executeDeploy
protected Deployment executeDeploy(CommandContext commandContext) {
// 获取 DeploymentEntity 对象,ProcessEngineConfigurationImpl 配置文件实现类,setDeploymentTime设置部署时间
if (this.deploymentBuilder.isDuplicateFilterEnabled()) {
// 是否有开启重复的流程的判断,若有则进行判断
}
deployment.setNew(true);
// Save the data 保存数据
CommandContextUtil.getDeploymentEntityManager(commandContext).insert(deployment);
// Actually deploy 部署流程
processEngineConfiguration.getDeploymentManager().deploy(deployment, deploymentSettings);
// 省略
return deployment;
}
// 继续跟踪上面的insert方法
// org.flowable.engine.impl.persistence.entity.DeploymentEntityManagerImpl#insert
@Override
public void insert(DeploymentEntity deployment) {
// 插入部署信息
insert(deployment, false);
// 循环插入资源文件
for (EngineResource resource : deployment.getResources().values()) {
resource.setDeploymentId(deployment.getId());
getResourceEntityManager().insert((ResourceEntity) resource);
}
}
// 继续跟踪上面的deploy方法
// org.flowable.engine.impl.persistence.deploy.DeploymentManager#deploy(org.flowable.engine.impl.persistence.entity.DeploymentEntity, java.util.Map<java.lang.String,java.lang.Object>)
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
for (EngineDeployer deployer : deployers) {
deployer.deploy(deployment, deploymentSettings);
}
}
// 跟踪deployer.deploy
// org.flowable.engine.impl.bpmn.deployer.BpmnDeployer#deploy