[jbpm-commits] JBoss JBPM SVN: r3017 - in jbpm4/trunk: modules/api/src/main/java/org/jbpm and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 20 15:44:23 EST 2008


Author: tom.baeyens at jboss.com
Date: 2008-11-20 15:44:23 -0500 (Thu, 20 Nov 2008)
New Revision: 3017

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessInstanceStoppedSynchronization.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/ProcessTest.java
Modified:
   jbpm4/trunk/build.xml
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/Deployment.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeployCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/DeploymentImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/resources/org/jbpm/pvm/hibernate.execution.hbm.xml
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/StateTest.java
Log:
added db test infrastructure

Modified: jbpm4/trunk/build.xml
===================================================================
--- jbpm4/trunk/build.xml	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/build.xml	2008-11-20 20:44:23 UTC (rev 3017)
@@ -31,11 +31,11 @@
 	</target>
 	
   <target name="javadoc">
-    <exec executable="cmd" os="Windows Vista, Windows XP,Windows 2000,Windows 98">
+    <exec executable="cmd" dir="modules/api" os="Windows Vista, Windows XP,Windows 2000,Windows 98">
       <arg line="/C mvn javadoc:javadoc" />
     </exec>
     <antcall target="show.html">
-      <param name="page" value="modules/pvm/target/site/apidocs/index.html"/>
+      <param name="page" value="modules/api/target/site/apidocs/index.html"/>
     </antcall>
   </target>
 
@@ -57,12 +57,12 @@
     </antcall>
   </target>
 
-  <target name="wirexsddoc">
-    <exec executable="cmd">
-      <arg line="/C mvn ?" />
+  <target name="jpdlxsddoc">
+    <exec executable="cmd" dir="modules/jpdl">
+      <arg line="/C mvn package" />
     </exec>
     <antcall target="show.html">
-      <param name="page" value="modules/core/target/site/apidocs/index.html"/>
+      <param name="page" value="modules/jpdl/target/doc/jpdlxsd/index.html"/>
     </antcall>
   </target>
     

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/Deployment.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/Deployment.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/Deployment.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.io.Serializable;
 import java.net.URL;
+import java.util.List;
 import java.util.zip.ZipInputStream;
 
 
@@ -54,5 +55,5 @@
   Deployment addDirectory(File directory);
   Deployment addDirectoryCanonical(File directory);
   
-  void deploy();
+  List<ProcessDefinition> deploy();
 }

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -123,4 +123,7 @@
   
   /** retrieves a map of variables */ 
   Map<String, Object> getVariables(String executionId, List<String> variableNames);
+
+  /* delete a process instance */
+  void deleteProcessInstance(String processInstanceId);
 }

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessService.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -30,10 +30,11 @@
  */
 public interface ProcessService {
   
+  /** start a deployment */
   Deployment createDeployment();
 
-  /** deploy a new process definition into the process repository. */
-  ProcessDefinition deploy(Deployment deployment);
+  /** TODO REMOVE: deploy a new process definition into the process repository. */
+  List<ProcessDefinition> deploy(Deployment deployment);
 
   /** all deployed process names. */
   List<String> findProcessDefinitionNames();
@@ -47,4 +48,10 @@
   /** specific version of a named processDefinition. */
   ProcessDefinition findProcessDefinition(String processDefinitionName, int processDefinitionVersion);
 
+  /** deletes process definition if there are no existing executions. 
+   * @throws JbpmException if there are existing executions. */
+  void deleteProcessDefinition(String processDefinitionId);
+
+  /** deletes process definition and the existing executions. */
+  void deleteProcessDefinitionAndInstances(String processDefinitionId);
 }

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -67,4 +67,10 @@
   /** the jobs for which all the retries have failed and which will not be 
    * picked up any more by the jobImpl executor */
   public List<Job> findJobsWithException(int firstResult, int maxResults);
+
+  /* find ids for all process instances for a given process definition. */
+  List<String> findProcessInstanceIds(String processDefinitionId);
+
+  /** delete the process instance */
+  void deleteProcessInstance(String processInstanceId);
 }

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import java.util.List;
+
+import org.jbpm.JbpmException;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.session.PvmDbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class DeleteProcessDefinitionCmd implements Command<Void> {
+
+  private static final long serialVersionUID = 1L;
+  
+  String processDefinitionId;
+  boolean deleteProcessInstances;
+ 
+  public DeleteProcessDefinitionCmd(String processDefinitionId) {
+    this(processDefinitionId, false);
+  }
+
+  public DeleteProcessDefinitionCmd(String processDefinitionId, boolean deleteProcessInstances) {
+    this.deleteProcessInstances = deleteProcessInstances;
+    this.processDefinitionId = processDefinitionId;
+  }
+
+  public Void execute(Environment environment) {
+    PvmDbSession pvmDbSession = Environment.getFromCurrent(PvmDbSession.class);
+    List<String> processInstanceIds = pvmDbSession.findProcessInstanceIds(processDefinitionId);
+    
+    if (deleteProcessInstances) {
+      for (String processInstanceId : processInstanceIds) {
+        pvmDbSession.deleteProcessInstance(processInstanceId);
+      }
+    } else {
+      if (processInstanceIds.size()>0) {
+        throw new JbpmException("still "+processInstanceIds.size()+" process instances for process definition "+processDefinitionId);
+      }
+    }
+    return null;
+  }
+}

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.session.PvmDbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class DeleteProcessInstance implements Command<Void> {
+
+  private static final long serialVersionUID = 1L;
+
+  String processInstanceId;
+  
+  public DeleteProcessInstance(String processInstanceId) {
+    this.processInstanceId = processInstanceId;
+  }
+
+  public Void execute(Environment environment) throws Exception {
+    Environment.getFromCurrent(PvmDbSession.class).deleteProcessInstance(processInstanceId);
+    return null;
+  }
+
+}

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeployCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeployCmd.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeployCmd.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -21,6 +21,9 @@
  */
 package org.jbpm.pvm.internal.cmd;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.jbpm.ProcessDefinition;
 import org.jbpm.JbpmException;
 import org.jbpm.cmd.Command;
@@ -31,7 +34,7 @@
 /**
  * @author Tom Baeyens
  */
-public class DeployCmd implements Command<ProcessDefinition> {
+public class DeployCmd implements Command<List<ProcessDefinition>> {
 
   private static final long serialVersionUID = 1L;
 
@@ -41,7 +44,7 @@
     this.deployment = deployment;
   }
 
-  public ProcessDefinition execute(Environment environment) throws Exception {
+  public List<ProcessDefinition> execute(Environment environment) throws Exception {
     DeployerManager deployerManager = environment.get(DeployerManager.class);
     if (deployerManager==null) {
       throw new JbpmException("no "+DeployerManager.class.getName()+" configured");
@@ -51,13 +54,14 @@
     // and handle the deployment
     deployerManager.deploy(deployment);
     
+    List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>();
     for (String objectName: deployment.getObjectNames()) {
       Object object = deployment.getObject(objectName);
       if (object instanceof ProcessDefinition) {
-        return (ProcessDefinition) object;
+        processDefinitions.add((ProcessDefinition) object);
       }
     }
 
-    return null;
+    return processDefinitions;
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -30,13 +30,16 @@
 import org.jbpm.job.Job;
 import org.jbpm.job.Message;
 import org.jbpm.job.Timer;
+import org.jbpm.log.Log;
 import org.jbpm.session.PvmDbSession;
 
 /**
  * @author Tom Baeyens
  */
 public class HibernatePvmDbSession extends HibernateDbSession implements PvmDbSession {
-
+  
+  private static final Log log = Log.getLog(HibernatePvmDbSession.class.getName());
+  
   public HibernatePvmDbSession() {
   }
 
@@ -119,4 +122,17 @@
     query.setMaxResults(maxResults);
     return query.list();
   }
+
+  public List<String> findProcessInstanceIds(String processDefinitionId) {
+    // query definition can be found at the bottom of resource org/jbpm/pvm/hibernate.job.hbm.xml
+    Query query = session.getNamedQuery("findProcessInstanceIds");
+    query.setString("processDefinitionId", processDefinitionId);
+    return query.list();
+  }
+
+  public void deleteProcessInstance(String processInstanceId) {
+    Execution processInstance = findExecutionById(processInstanceId);
+    log.debug("deleting process instance "+processInstanceId);
+    session.delete(processInstance);
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -36,11 +36,13 @@
 import java.util.Set;
 
 import org.jbpm.Execution;
+import org.jbpm.ExecutionService;
 import org.jbpm.JbpmException;
 import org.jbpm.activity.ActivityExecution;
 import org.jbpm.client.ClientProcessDefinition;
 import org.jbpm.client.ClientProcessInstance;
 import org.jbpm.env.Environment;
+import org.jbpm.env.Transaction;
 import org.jbpm.job.Timer;
 import org.jbpm.listener.EventListener;
 import org.jbpm.listener.EventListenerExecution;
@@ -336,6 +338,17 @@
         log.trace(toString()+" signals super process execution");
         superProcessExecution.signal();
       }
+      
+      Environment environment = Environment.getCurrent();
+      if (environment!=null) {
+        Transaction transaction = environment.get(Transaction.class);
+        ExecutionService executionService = environment.get(ExecutionService.class);
+        if ( (transaction!=null)
+             && (executionService!=null)
+           ) {
+          transaction.registerSynchronization(new ProcessInstanceStoppedSynchronization(this.getId(), executionService));
+        }
+      }
     }
   }
 

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessInstanceStoppedSynchronization.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessInstanceStoppedSynchronization.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ProcessInstanceStoppedSynchronization.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.model;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.jbpm.ExecutionService;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessInstanceStoppedSynchronization implements Synchronization {
+  
+  String processInstanceId;
+  ExecutionService executionService;
+
+  public ProcessInstanceStoppedSynchronization(String processInstanceId, ExecutionService executionService) {
+    this.processInstanceId = processInstanceId;
+    this.executionService = executionService;
+  }
+
+  public void afterCompletion(int status) {
+    if (status==Status.STATUS_COMMITTED) {
+      executionService.deleteProcessInstance(processInstanceId);
+    }
+  }
+
+  public void beforeCompletion() {
+  }
+}

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/DeploymentImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/DeploymentImpl.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/DeploymentImpl.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -304,8 +304,8 @@
     return this;
   }
 
-  public void deploy() {
-    processServiceImpl.deploy(this);
+  public List<ProcessDefinition> deploy() {
+    return processServiceImpl.deploy(this);
   }
 
   // error logging

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -28,6 +28,7 @@
 import org.jbpm.Execution;
 import org.jbpm.ExecutionService;
 import org.jbpm.cmd.CommandService;
+import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
 import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
 import org.jbpm.pvm.internal.cmd.GetVariablesCmd;
 import org.jbpm.pvm.internal.cmd.SetVariablesCmd;
@@ -133,6 +134,10 @@
     return commandService.execute(new FindExecutionCmd(executionId));
   }
 
+  public void deleteProcessInstance(String processInstanceId) {
+    commandService.execute(new DeleteProcessInstance(processInstanceId));
+  }
+
   public Object getVariable(String executionId, String variableName) {
     List<String> variableNames = new ArrayList<String>();
     variableNames.add(variableName);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -28,6 +28,7 @@
 import org.jbpm.ProcessService;
 import org.jbpm.cmd.CommandService;
 import org.jbpm.model.OpenProcessDefinition;
+import org.jbpm.pvm.internal.cmd.DeleteProcessDefinitionCmd;
 import org.jbpm.pvm.internal.cmd.DeployCmd;
 import org.jbpm.pvm.internal.cmd.FindLatestProcessDefinitionCmd;
 import org.jbpm.pvm.internal.cmd.FindProcessDefinitionCmd;
@@ -43,7 +44,7 @@
 
   protected CommandService commandService;
 
-  public ProcessDefinition deploy(OpenProcessDefinition processDefinition) {
+  public List<ProcessDefinition> deploy(OpenProcessDefinition processDefinition) {
     DeploymentImpl deploymentImpl = new DeploymentImpl(processDefinition);
     return commandService.execute(new DeployCmd(deploymentImpl));
   }
@@ -52,7 +53,7 @@
     return new DeploymentImpl(this);
   }
 
-  public ProcessDefinition deploy(Deployment deployment) {
+  public List<ProcessDefinition> deploy(Deployment deployment) {
     return commandService.execute(new DeployCmd((DeploymentImpl)deployment));
   }
 
@@ -72,6 +73,14 @@
     return (List)commandService.execute(new FindProcessDefinitionsCmd(processDefinitionName));
   }
 
+  public void deleteProcessDefinition(String processDefinitionId) {
+    commandService.execute(new DeleteProcessDefinitionCmd(processDefinitionId));
+  }
+
+  public void deleteProcessDefinitionAndInstances(String processDefinitionId) {
+    commandService.execute(new DeleteProcessDefinitionCmd(processDefinitionId, true));
+  }
+
   public CommandService getCommandService() {
     return commandService;
   }

Modified: jbpm4/trunk/modules/pvm/src/main/resources/org/jbpm/pvm/hibernate.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/org/jbpm/pvm/hibernate.execution.hbm.xml	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/pvm/src/main/resources/org/jbpm/pvm/hibernate.execution.hbm.xml	2008-11-20 20:44:23 UTC (rev 3017)
@@ -132,5 +132,15 @@
        and execution.processDefinition.name = :processDefinitionName
     ]]>
   </query>
+  
+  <query name="findProcessInstanceIds">
+    <![CDATA[
+     select processInstance.id
+     from org.jbpm.pvm.internal.model.ExecutionImpl as processInstance
+     where processInstance.processDefinition.id = :processDefinitionId
+       and processInstance.parent is null
+    ]]>
+  </query>
+  
 
 </hibernate-mapping>
\ No newline at end of file

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -35,19 +35,27 @@
 import org.hibernate.mapping.Table;
 import org.jbpm.ProcessEngine;
 import org.jbpm.env.EnvironmentFactory;
+import org.jbpm.log.Log;
 
 
 /**
  * @author Tom Baeyens
  */
 public class Db {
+  
+  private static final Log log = Log.getLog(Db.class.getName());
 
+  private static final String TABLE_NAMES_KEY = "tableNames";
   private static final String CLEAN_SQL_KEY = "cleanSql";
 
   public static void clean(ProcessEngine processEngine) {
     clean((EnvironmentFactory) processEngine);
   }
 
+  public static void verifyClean(ProcessEngine processEngine) {
+    verifyClean((EnvironmentFactory) processEngine);
+  }
+
   public static void clean(EnvironmentFactory environmentFactory) {
     SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
     String[] cleanSql = (String[]) environmentFactory.get(CLEAN_SQL_KEY);
@@ -115,10 +123,56 @@
     Session session = sessionFactory.openSession();
     try {
       for (String query : cleanSql) {
+        log.trace(query);
         session.createSQLQuery(query).executeUpdate();
       }
     } finally {
       session.close();
     }
   }
+
+  public static void verifyClean(EnvironmentFactory environmentFactory) {
+    SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
+    String[] tableNames = (String[]) environmentFactory.get(TABLE_NAMES_KEY);
+
+    if (tableNames == null) {
+      Configuration configuration = environmentFactory.get(Configuration.class);
+      
+      SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+      Dialect dialect = sessionFactoryImplementor.getDialect();
+
+      // loop over all foreign key constraints
+      List<String> tableNamesList = new ArrayList<String>();
+      Iterator iter = configuration.getTableMappings();
+      while (iter.hasNext()) {
+        Table table = (Table) iter.next();
+        if (table.isPhysicalTable()) {
+          tableNamesList.add(table.getName());
+        }
+      }
+
+      tableNames = (String[]) tableNamesList.toArray(new String[tableNamesList.size()]);
+      
+      environmentFactory.set(TABLE_NAMES_KEY, tableNames);
+    }
+
+    boolean recordsLeft = false;
+    Session session = sessionFactory.openSession();
+    try {
+      for (String tableName : tableNames) {
+        String countSql = "select count(*) from "+tableName;
+        Integer recordCount = (Integer) session.createSQLQuery(countSql).uniqueResult();
+        if (recordCount>0) {
+          recordsLeft = true;
+          log.error("FIXME: "+recordCount+" records left in table "+tableName);
+        }
+      }
+    } finally {
+      session.close();
+    }
+    
+    if (recordsLeft) {
+      clean(environmentFactory);
+    }
+  }
 }

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -21,9 +21,13 @@
  */
 package org.jbpm.test;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.jbpm.Configuration;
 import org.jbpm.ExecutionService;
 import org.jbpm.ManagementService;
+import org.jbpm.ProcessDefinition;
 import org.jbpm.ProcessEngine;
 import org.jbpm.ProcessService;
 import org.jbpm.TaskService;
@@ -40,6 +44,8 @@
   protected ExecutionService executionService;
   protected ManagementService managementService;
   protected TaskService taskService;
+  
+  protected List<ProcessDefinition> processDefinitions;
 
   public void setUp() throws Exception {
     super.setUp();
@@ -67,8 +73,28 @@
   }
 
   public void tearDown() throws Exception {
-    Db.clean(processEngine);
+    if (processDefinitions!=null) {
+      for (ProcessDefinition processDefinition : processDefinitions) {
+        processService.deleteProcessDefinition(processDefinition.getId());
+      }
+    }
     
+    Db.verifyClean(processEngine);
+    
     super.tearDown();
   }
+
+  public void deployJpdlXmlString(String jpdlXmlString) {
+    List<ProcessDefinition> deployedProcessDefinitions = 
+      processService.createDeployment()
+        .setLanguage("jpdl")
+        .addString("xmlstring.jpdl.xml", jpdlXmlString)
+        .deploy();
+    
+    if (processDefinitions==null) {
+      processDefinitions = new ArrayList<ProcessDefinition>();
+    }
+    
+    processDefinitions.addAll(deployedProcessDefinitions);
+  }
 }

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/ProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/ProcessTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/ProcessTest.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.basicfeatures;
+
+import org.jbpm.Execution;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessTest extends DbTestCase {
+
+  public void testMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start>" +
+      "    <flow to='end' />" +
+      "  </start>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+    
+    Execution execution = executionService.startExecutionInLatest("minimal");
+    
+    assertEquals("end", execution.getNodeName());
+    assertTrue(execution.isEnded());
+    assertTrue(execution.isFinished());
+    assertFalse(execution.isActive());
+  }
+
+  public void testMostMinimalProcess() {
+    deployJpdlXmlString(
+      "<process name='minimal'>" +
+      "  <start />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startExecutionInLatest("minimal");
+    
+    assertTrue(execution.isEnded());
+    assertTrue(execution.isFinished());
+    assertFalse(execution.isActive());
+  }
+}

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/StateTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/StateTest.java	2008-11-20 15:46:29 UTC (rev 3016)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/basicfeatures/StateTest.java	2008-11-20 20:44:23 UTC (rev 3017)
@@ -56,13 +56,6 @@
     assertEquals("d", execution.getNodeName());
     assertTrue(execution.isEnded());
   }
-  
-  public void deployJpdlXmlString(String jpdlXmlString) {
-    processService.createDeployment()
-      .setLanguage("jpdl")
-      .addString("xmlstring.jpdl.xml", jpdlXmlString)
-      .deploy();
-  }
 
   /*
   public void testExternalDecision() {




More information about the jbpm-commits mailing list