RepositorySession repositorySession = environment.get(RepositorySession.class);
List<ProcessDefinition> processDefinitions = repositorySession.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.list();
DbSession dbSession = environment.get(DbSession.class);
for (ProcessDefinition processDefinition: processDefinitions) {
String processDefinitionId = processDefinition.getId();
List<String> processInstanceIds = dbSession.findProcessInstanceIds(processDefinitionId);
if (cascade) {
for (String processInstanceId: processInstanceIds) {
dbSession.deleteProcessInstance(processInstanceId, true);
}
dbSession.deleteProcessDefinitionHistory(processDefinitionId);
} else {
if (!processInstanceIds.isEmpty()) {
throw new JbpmException("cannot delete deployment "+deploymentId+": still executions for "+processDefinition+": "+processInstanceIds);
}