activiti源码解析系列9 - 完成特别子流程命令类

特别子流程如何完成呢?

通过runtimeService.completeAdhocSubProcess(String executionId) 

主要看命令类CompleteAdhocSubProcessCmd:

看代码:

public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity execution = executionEntityManager.findById(executionId);
    if (execution == null) {
      throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
    }
    if (execution.getCurrentFlowElement() instanceof AdhocSubProcess == false) {
      throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
    }
    List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
    if (childExecutions.size() > 0) {
      throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first");
    }
    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
    outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());
    executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);
    return null;
}

分析代码:

主要进行了:

1、检查特别子流程元素类型(元素非特别子流程则异常)

2、检查子执行实例大于0则异常(需要首先完成的子执行)

3、创建子执行实例

        创建一个新的执行.并初始化属性定义信息、实例信息,并入库ACT_RU_EXECUTION

4、删除执行实例和相关数据

        4.1更新结束信息(结束时间、花费时间、删除原因);调度历史活动实例结束事件;

        4.2删除相关数据

            executionEntity.setEnded(true);

            executionEntity.setActive(false);

            删除ACT_RU_IDENTITYLINK

            删除ACT_RU_VARIABLE

            删除ACT_GE_BYTEARRAY

            删除任务运行表数据

            删除ACT_RU_TIMER_JOB

            删除ACT_RU_JOB

            删除ACT_RU_SUSPENDED_JOB

            删除ACT_RU_DEADLETTER_JOB

            删除ACT_RU_EVENT_SUBSCR(消息、事件、信号)

       4.3删除ACT_RU_EXECUTION

5、执行出线计划

Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

Activiti社区交流群:839915498

更多activiti系列教程:activiti教程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值