use of org.activiti.engine.impl.ProcessInstanceQueryImpl in project Activiti by Activiti.
the class ExecutionEntityManager method deleteProcessInstanceCascade.
private void deleteProcessInstanceCascade(ExecutionEntity execution, String deleteReason, boolean deleteHistory) {
CommandContext commandContext = Context.getCommandContext();
ProcessInstanceQueryImpl processInstanceQuery = new ProcessInstanceQueryImpl(commandContext);
List<ProcessInstance> subProcesses = processInstanceQuery.superProcessInstanceId(execution.getProcessInstanceId()).list();
for (ProcessInstance subProcess : subProcesses) {
deleteProcessInstanceCascade((ExecutionEntity) subProcess, deleteReason, deleteHistory);
}
commandContext.getTaskEntityManager().deleteTasksByProcessInstanceId(execution.getId(), deleteReason, deleteHistory);
// fill default reason if none provided
if (deleteReason == null) {
deleteReason = "ACTIVITY_DELETED";
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && execution.isProcessInstanceType()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createCancelledEvent(execution.getProcessInstanceId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), deleteReason));
}
// delete the execution BEFORE we delete the history, otherwise we will produce orphan HistoricVariableInstance instances
execution.deleteCascade(deleteReason);
if (deleteHistory) {
commandContext.getHistoricProcessInstanceEntityManager().deleteHistoricProcessInstanceById(execution.getId());
}
}
Aggregations