技术交流28群

服务热线

135-6963-3175

微信服务号

完成特别子流程命令类源码解析 更新时间 2022-3-20 浏览1806次

特别子流程如何完成呢?

通过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);