Problems with deleting a process instance of a complex proce
jits_1998 Nov 8, 2006 1:28 AMHi,
We have a complex process with multiple sub-processes, tasks and multiple child tokens in the subprocesses.
We found that GraphSession.deleteProcessInstance() method is unable to delete the process instance.
It falls short on following points:
1) It is not deleting the taskinstances, though it creates the query but it is never executed.
2) It is not deleting the sub-process and their child tokens, which are not refered by "token.getSubProcessInstance".
Here is an updated version of deleteProcessInstance() that works for us:
public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks, boolean includeJobs) {
if (processInstance==null) throw new JbpmException("processInstance is null in JbpmSession.deleteProcessInstance()");
try {
// find the tokens
Query query = session.getNamedQuery("GraphSession.findTokensForProcessInstance");
query.setEntity("processInstance", processInstance);
List tokens = query.list();
// deleteSubProcesses
Iterator iter = tokens.iterator();
while (iter.hasNext()) {
Token token = (Token) iter.next();
deleteSubProcesses(token);
}
// jobs
if (includeJobs) {
query = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance");
query.setEntity("processInstance", processInstance);
query.executeUpdate();
}
// tasks
if (includeTasks) {
query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance");
query.setEntity("processInstance", processInstance);
List taskInstances = query.list();
if(taskInstances.size()>0){
List<Long> taskInstancesId = new ArrayList<Long>();
for(Object ti: taskInstances)
{
taskInstancesId.add(((TaskInstance)ti).getId());
}
query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
query.setParameterList("taskInstanceIds",taskInstancesId);
query.executeUpdate();
}
}
// delete the logs for all the process instance's tokens
query = session.getNamedQuery("GraphSession.selectLogsForTokens");
query.setParameterList("tokens", tokens);
List logs = query.list();
iter = logs.iterator();
while (iter.hasNext()) {
session.delete(iter.next());
}
iter = tokens.iterator();
while(iter.hasNext()){
Token token = (Token)iter.next();
if(processInstance.getRootToken().getId()!= token.getId())
session.delete(token);
}
// then delete the process instance
session.delete(processInstance);
} catch (Exception e) {
e.printStackTrace();
log.error(e);
throw new JbpmException("couldn't delete process instance '" + processInstance.getId() + "'", e);
}
}
The "ProcessSession.findSubprocessByToken" query is as follows:
select pi from org.jbpm.graph.exe.ProcessInstance as pi where pi.superProcessToken = :token
Hope it helps... I have not checked Jira for any such known issues, please let me know if I need to raise this ticket.
Regards,
Jitendra