[jbpm-commits] JBoss JBPM SVN: r2562 - in jbpm3/branches/tbaeyens/modules/core/src: test/java/org/jbpm/graph/node and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 21 04:46:20 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-10-21 04:46:20 -0400 (Tue, 21 Oct 2008)
New Revision: 2562

Modified:
   jbpm3/branches/tbaeyens/modules/core/src/main/java/org/jbpm/db/GraphSession.java
   jbpm3/branches/tbaeyens/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java
Log:
final delete process instance fix

Modified: jbpm3/branches/tbaeyens/modules/core/src/main/java/org/jbpm/db/GraphSession.java
===================================================================
--- jbpm3/branches/tbaeyens/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2008-10-20 15:16:51 UTC (rev 2561)
+++ jbpm3/branches/tbaeyens/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2008-10-21 08:46:20 UTC (rev 2562)
@@ -228,12 +228,10 @@
     if (processDefinition==null) throw new JbpmException("processDefinition is null in JbpmSession.deleteProcessDefinition()");
     try {
       // delete all the process instances of this definition
-      List processInstances = findProcessInstances(processDefinition.getId());
-      if (processInstances!=null) {
-        Iterator iter = processInstances.iterator();
-        while (iter.hasNext()) {
-          deleteProcessInstance((ProcessInstance) iter.next());
-        }
+      ProcessInstance processInstance = findNextProcessInstance(processDefinition.getId());
+      while (processInstance!=null) {
+        deleteProcessInstance(processInstance);
+        processInstance = findNextProcessInstance(processDefinition.getId());
       }
       
       List referencingProcessStates = findReferencingProcessStates(processDefinition);
@@ -253,6 +251,13 @@
     } 
   }
 
+  protected ProcessInstance findNextProcessInstance(long processDefinitionId) {
+    Query query = session.getNamedQuery("GraphSession.findAllProcessInstancesForADefinition");
+    query.setLong("processDefinitionId", processDefinitionId);
+    query.setMaxResults(1);
+    return (ProcessInstance) query.uniqueResult();
+  }
+
   protected List findReferencingProcessStates(ProcessDefinition subProcessDefinition) {
     Query query = session.getNamedQuery("GraphSession.findReferencingProcessStates");
     query.setEntity("subProcessDefinition", subProcessDefinition);
@@ -382,7 +387,7 @@
   public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks, boolean includeJobs) {
     if (processInstance==null) throw new JbpmException("processInstance is null in JbpmSession.deleteProcessInstance()");
     log.debug("deleting process instance "+processInstance.getId());
-    session.flush();
+    
     try {
       // jobs
       if (includeJobs) {
@@ -390,7 +395,6 @@
         Query query = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance");
         query.setEntity("processInstance", processInstance);
         query.executeUpdate();
-        session.flush();
       }
       
       // tasks
@@ -406,19 +410,26 @@
           query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
           query.setParameterList("taskInstanceIds", taskInstanceIds);
         }
-        session.flush();
       }
 
       // delete the logs
+      log.debug("deleting logs for process instance "+processInstance.getId());
       deleteLogs(processInstance);
 
       // delete the tokens and subprocess instances
+      log.debug("deleting subprocesses for process instance "+processInstance.getId());
       deleteSubProcesses(processInstance.getRootToken());
 
+      // null out the parent process token
+      Token superProcessToken = processInstance.getSuperProcessToken();
+      if (superProcessToken!=null) {
+        log.debug("nulling property subProcessInstance in superProcessToken "+superProcessToken.getId()+" which is referencing the process instance "+processInstance.getId()+" which is being deleted");
+        superProcessToken.setSubProcessInstance(null);
+      } 
+
       // add the process instance
-      log.debug("deleting process instance "+processInstance.getId());
+      log.debug("hibernate session delete for process instance "+processInstance.getId());
       session.delete(processInstance);
-      session.flush();
 
     } catch (Exception e) {
       log.error(e);

Modified: jbpm3/branches/tbaeyens/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java
===================================================================
--- jbpm3/branches/tbaeyens/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java	2008-10-20 15:16:51 UTC (rev 2561)
+++ jbpm3/branches/tbaeyens/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java	2008-10-21 08:46:20 UTC (rev 2562)
@@ -119,8 +119,9 @@
   }
 
   public void testMultipleRecursiveProcessDefinitions() {
-    for (int i=0; i<20; i++) {
+    for (int i=0; i<30; i++) {
       testRecursiveProcessDefinition();
+      newTransaction();
     }
   }
 




More information about the jbpm-commits mailing list