ExecutionEntityManagerImpl extends AbstractEntityManager<ExecutionEntity> implements ExecutionEntityManager { @Override public ExecutionEntity createChildExecution(ExecutionEntity parentExecutionEntity) { ExecutionEntity childExecution = executionDataManager.create(); inheritCommonProperties(parentExecutionEntity, childExecution); childExecution.setParent(parentExecutionEntity); childExecution.setProcessDefinitionId(parentExecutionEntity.getProcessDefinitionId()); childExecution.setProcessDefinitionKey(parentExecutionEntity.getProcessDefinitionKey()); childExecution.setProcessInstanceId(parentExecutionEntity.getProcessInstanceId() != null ? parentExecutionEntity.getProcessInstanceId() : parentExecutionEntity.getId()); childExecution.setParentProcessInstanceId(parentExecutionEntity.getParentProcessInstanceId()); childExecution.setAppVersion(parentExecutionEntity.getAppVersion()); childExecution.setScope(false); parentExecutionEntity.addChildExecution(childExecution); insert(childExecution, false); if (logger.isDebugEnabled()) { logger.debug("Child execution {} created with parent {}", childExecution, parentExecutionEntity.getId()); } if (getEventDispatcher().isEnabled()) { getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, childExecution)); getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, childExecution)); } return childExecution; } ExecutionEntityManagerImpl(ProcessEngineConfigurationImpl processEngineConfiguration, ExecutionDataManager executionDataManager); @Override void delete(ExecutionEntity entity); @Override void delete(ExecutionEntity entity, boolean fireDeleteEvent); @Override ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId); @Override List<ExecutionEntity> findChildExecutionsByParentExecutionId(String parentExecutionId); @Override List<ExecutionEntity> findChildExecutionsByProcessInstanceId(String processInstanceId); @Override List<ExecutionEntity> findExecutionsByParentExecutionAndActivityIds(final String parentExecutionId, final Collection<String> activityIds); @Override long findExecutionCountByQueryCriteria(ExecutionQueryImpl executionQuery); @Override List<ExecutionEntity> findExecutionsByQueryCriteria(ExecutionQueryImpl executionQuery, Page page); @Override long findProcessInstanceCountByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override List<ProcessInstance> findProcessInstanceByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override ExecutionEntity findByRootProcessInstanceId(String rootProcessInstanceId); @Override List<ProcessInstance> findProcessInstanceAndVariablesByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override Collection<ExecutionEntity> findInactiveExecutionsByProcessInstanceId(final String processInstanceId); @Override Collection<ExecutionEntity> findInactiveExecutionsByActivityIdAndProcessInstanceId(final String activityId, final String processInstanceId); @Override List<Execution> findExecutionsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override List<ProcessInstance> findProcessInstanceByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override long findExecutionCountByNativeQuery(Map<String, Object> parameterMap); @Override ExecutionEntity createProcessInstanceExecution(ProcessDefinition processDefinition, String businessKey, String tenantId, String initiatorVariableName); ExecutionEntity updateProcessInstanceStartDate(ExecutionEntity processInstanceExecution); @Override ExecutionEntity createChildExecution(ExecutionEntity parentExecutionEntity); @Override ExecutionEntity createSubprocessInstance(ProcessDefinition processDefinition, ExecutionEntity superExecutionEntity, String businessKey); @Override void updateExecutionTenantIdForDeployment(String deploymentId, String newTenantId); @Override void deleteProcessInstancesByProcessDefinition(String processDefinitionId, String deleteReason, boolean cascade); @Override void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade); @Override void deleteExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void cancelExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void deleteProcessInstanceExecutionEntity(String processInstanceId,
      String currentFlowElementId, String deleteReason, boolean cascade, boolean cancel); @Override void deleteChildExecutions(ExecutionEntity executionEntity, String deleteReason); @Override void cancelChildExecutions(ExecutionEntity executionEntity, String deleteReason); List<ExecutionEntity> collectChildren(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstScope(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstMultiInstanceRoot(ExecutionEntity executionEntity); @Override void updateProcessInstanceLockTime(String processInstanceId); @Override void clearProcessInstanceLockTime(String processInstanceId); @Override String updateProcessInstanceBusinessKey(ExecutionEntity executionEntity, String businessKey); ExecutionDataManager getExecutionDataManager(); void setExecutionDataManager(ExecutionDataManager executionDataManager);  }
@Test public void should_createChildExecution() { ExecutionEntityImpl parentExecution = new ExecutionEntityImpl(); parentExecution.executions = new ArrayList<>(); parentExecution.setRootProcessInstanceId("rootProcessInstanceId"); parentExecution.setTenantId("tenantId"); parentExecution.setProcessDefinitionId("processDefinitionId"); parentExecution.setProcessDefinitionKey("processDefinitionKey"); parentExecution.setProcessInstanceId("processInstanceId"); parentExecution.setParentProcessInstanceId("parentProcessInstanceId"); parentExecution.setAppVersion(4); ExecutionEntityImpl childExecution = new ExecutionEntityImpl(); given(executionDataManager.create()).willReturn(childExecution); Date startTime = new Date(); given(clock.getCurrentTime()).willReturn(startTime); ExecutionEntity childResult = executionEntityManager.createChildExecution(parentExecution); assertThat(childResult.getRootProcessInstanceId()).isEqualTo("rootProcessInstanceId"); assertThat(childResult.isActive()).isTrue(); assertThat(childResult.getStartTime()).isEqualTo(startTime); assertThat(childResult.getTenantId()).isEqualTo("tenantId"); assertThat(childResult.getParent()).isEqualTo(parentExecution); assertThat(childResult.getProcessDefinitionId()).isEqualTo("processDefinitionId"); assertThat(childResult.getProcessDefinitionKey()).isEqualTo("processDefinitionKey"); assertThat(childResult.getProcessInstanceId()).isEqualTo("processInstanceId"); assertThat(childResult.getParentProcessInstanceId()).isEqualTo("parentProcessInstanceId"); assertThat(childResult.getAppVersion()).isEqualTo(4); assertThat(childResult.isScope()).isFalse(); verify(executionDataManager).insert(childExecution); verify(eventDispatcher).isEnabled(); }