一 代码
/**
* Copyright (C), 2020-2020, 软件公司
* FileName: DeleteProcessInstance.java
* Author: cakin
* Date: 2020/4/25
* Description: 删除流程实例
*/
package com.syc.activiti.chapter9;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
/**
* @className: DeleteProcessInstance
* @description: 删除流程实例
* @date: 2020/4/25
* @author: cakin
*/
@Slf4j
public class DeleteProcessInstance {
public static void main( String[] args ) {
// 创建流程引擎
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 得到流程存储服务实例
RepositoryService repositoryService = engine.getRepositoryService();
// 得到运行时服务组件
RuntimeService runtimeService = engine.getRuntimeService();
// 部署流程描述文件
repositoryService.createDeployment()
.addClasspathResource("bpmn/chapter9/DeleteProcess.bpmn").deploy();
// 开始流流程
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
long count = runtimeService.createProcessInstanceQuery().count();
log.info("启动时流程实例数量:" + count);
/******************************************************************************************
mysql> select ID_, REV_,PROC_INST_ID_ ,BUSINESS_KEY_ ,PARENT_ID_ ,PROC_DEF_ID_ ,SUPER_EXEC_,ROOT_PROC_INST_ID_ ,ACT_ID_ from act_ru_execution;
+--------+------+---------------+---------------+------------+----------------------+-------------+--------------------+-----------+
| ID_ | REV_ | PROC_INST_ID_ | BUSINESS_KEY_ | PARENT_ID_ | PROC_DEF_ID_ | SUPER_EXEC_ | ROOT_PROC_INST_ID_ | ACT_ID_ |
+--------+------+---------------+---------------+------------+----------------------+-------------+--------------------+-----------+
| 217505 | 1 | 217505 | NULL | NULL | testProcess:1:217504 | NULL | 217505 | NULL |
| 217506 | 1 | 217505 | NULL | 217505 | testProcess:1:217504 | NULL | 217505 | usertask1 |
| 217509 | 1 | 217505 | NULL | 217505 | testProcess:1:217504 | NULL | 217505 | usertask3 |
+--------+------+---------------+---------------+------------+----------------------+-------------+--------------------+-----------+
3 rows in set (0.00 sec)
mysql> select ID_ ,REV_, EXECUTION_ID_, PROC_INST_ID_ , PROC_DEF_ID_, NAME_ , PARENT_TASK_ID_ , DESCRIPTION_ , TASK_DEF_KEY_ , OWNER_, ASSIGNEE_ from act_ru_task;
+--------+------+---------------+---------------+----------------------+-------------+-----------------+--------------+---------------+--------+-----------+
| ID_ | REV_ | EXECUTION_ID_ | PROC_INST_ID_ | PROC_DEF_ID_ | NAME_ | PARENT_TASK_ID_ | DESCRIPTION_ | TASK_DEF_KEY_ | OWNER_ | ASSIGNEE_ |
+--------+------+---------------+---------------+----------------------+-------------+-----------------+--------------+---------------+--------+-----------+
| 217511 | 1 | 217506 | 217505 | testProcess:1:217504 | First Task | NULL | NULL | usertask1 | NULL | NULL |
| 217513 | 1 | 217509 | 217505 | testProcess:1:217504 | Second Task | NULL | NULL | usertask3 | NULL | NULL |
+--------+------+---------------+---------------+----------------------+-------------+-----------------+--------------+---------------+--------+-----------+
2 rows in set (0.00 sec)
mysql> select * from act_re_deployment;
+--------+-------+-----------+------+------------+-------------------------+-----------------+
| ID_ | NAME_ | CATEGORY_ | KEY_ | TENANT_ID_ | DEPLOY_TIME_ | ENGINE_VERSION_ |
+--------+-------+-----------+------+------------+-------------------------+-----------------+
| 217501 | NULL | NULL | NULL | | 2020-04-25 20:01:49.383 | NULL |
+--------+-------+-----------+------+------------+-------------------------+-----------------+
1 row in set (0.00 sec)
mysql> select ID_,NAME_, KEY_, DEPLOYMENT_ID_,RESOURCE_NAME_,DGRM_RESOURCE_NAME_,SUSPENSION_STATE_ from act_re_procdef;
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
| ID_ | NAME_ | KEY_ | DEPLOYMENT_ID_ | RESOURCE_NAME_ | DGRM_RESOURCE_NAME_ | SUSPENSION_STATE_ |
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
| testProcess:1:217504 | testProcess | testProcess | 217501 | bpmn/chapter9/DeleteProcess.bpmn | bpmn/chapter9/DeleteProcess.testProcess.png | 1 |
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
******************************************************************************************/
// 删除流程
runtimeService.deleteProcessInstance(pi.getId(), "abc");
count = runtimeService.createProcessInstanceQuery().count();
log.info("删除后流程实例数量:" + count);
/******************************************************************************************
mysql> select ID_,NAME_, KEY_, DEPLOYMENT_ID_,RESOURCE_NAME_,DGRM_RESOURCE_NAME_,SUSPENSION_STATE_ from act_re_procdef;
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
| ID_ | NAME_ | KEY_ | DEPLOYMENT_ID_ | RESOURCE_NAME_ | DGRM_RESOURCE_NAME_ | SUSPENSION_STATE_ |
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
| testProcess:1:217504 | testProcess | testProcess | 217501 | bpmn/chapter9/DeleteProcess.bpmn | bpmn/chapter9/DeleteProcess.testProcess.png | 1 |
+----------------------+-------------+-------------+----------------+----------------------------------+---------------------------------------------+-------------------+
1 row in set (0.00 sec)
mysql> select ID_ ,REV_, EXECUTION_ID_, PROC_INST_ID_ , PROC_DEF_ID_, NAME_ , PARENT_TASK_ID_ , DESCRIPTION_ , TASK_DEF_KEY_ , OWNER_, ASSIGNEE_ from act_ru_task;
Empty set (0.00 sec)
mysql> select * from act_re_deployment;
+--------+-------+-----------+------+------------+-------------------------+-----------------+
| ID_ | NAME_ | CATEGORY_ | KEY_ | TENANT_ID_ | DEPLOY_TIME_ | ENGINE_VERSION_ |
+--------+-------+-----------+------+------------+-------------------------+-----------------+
| 217501 | NULL | NULL | NULL | | 2020-04-25 20:01:49.383 | NULL |
+--------+-------+-----------+------+------------+-------------------------+-----------------+
1 row in set (0.00 sec)
mysql> select ID_, REV_,PROC_INST_ID_ ,BUSINESS_KEY_ ,PARENT_ID_ ,PROC_DEF_ID_ ,SUPER_EXEC_,ROOT_PROC_INST_ID_ ,ACT_ID_,SUSPENSION_STATE_ from act_ru_execution;
Empty set (0.00 sec)
******************************************************************************************/
}
}
二 测试
启动时流程实例数量:1
删除后流程实例数量:0
来源:oschina
链接:https://my.oschina.net/u/4357969/blog/4253837