[jbpm-commits] JBoss JBPM SVN: r4807 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/api/job and 14 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed May 13 11:15:52 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-05-13 11:15:51 -0400 (Wed, 13 May 2009)
New Revision: 4807
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeDeploymentCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendDeploymentCmd.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/SuspendDeploymentTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Deployment.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/job/Job.java
jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/EjbTimerSessionTest.java
jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/TimerTest.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/StartProcessInstanceInLatestCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateJobDbSession.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/hibernate/HibernateTaskDbSession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/AcquireJobsCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.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/query/ProcessDefinitionQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCache.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCacheImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/LifeCycle.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.task.hbm.xml
Log:
JBPM-2242 added deployment state and introduced suspend and resume
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Deployment.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Deployment.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Deployment.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -26,19 +26,19 @@
import java.net.URL;
import java.util.zip.ZipInputStream;
-import org.jbpm.api.client.ClientProcessDefinition;
-
-/**
+/**
* @author Tom Baeyens
*/
public interface Deployment {
+ long getDbid();
+
String getName();
Deployment setName(String name);
long getTimestamp();
Deployment setTimestamp(long timestamp);
-
+
Deployment addResourceFromString(String resourceName, String string);
Deployment addResourceFromInputStream(String resourceName, InputStream inputStream);
Deployment addResourceFromClasspath(String resourceName);
@@ -48,6 +48,4 @@
/** @return deploymentId */
long deploy();
-
- Deployment addProcessDefinition(ClientProcessDefinition processDefinition);
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -205,4 +205,7 @@
* Returns an empty set in case there are no activities active.
* @see #findActiveExecutionIn(String) */
Set<String> findActiveActivityNames();
+
+ /** id of the process definition used for this execution */
+ String getProcessDefinitionId();
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -39,6 +39,7 @@
ProcessDefinitionQuery nameLike(String name);
ProcessDefinitionQuery name(String name);
ProcessDefinitionQuery deploymentDbid(long deploymentDbid);
+ ProcessDefinitionQuery suspended();
ProcessDefinitionQuery orderAsc(String property);
ProcessDefinitionQuery orderDesc(String property);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -35,6 +35,8 @@
ProcessInstanceQuery processInstanceId(String processInstanceId);
+ ProcessInstanceQuery suspended();
+
ProcessInstanceQuery orderAsc(String property);
ProcessInstanceQuery orderDesc(String property);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -33,6 +33,8 @@
Deployment createDeployment();
+ void suspendDeployment(long deploymentDbid);
+ void resumeDeployment(long deploymentDbid);
void deleteDeployment(long deploymentDbid);
void deleteDeploymentCascade(long deploymentDbid);
@@ -41,5 +43,4 @@
ProcessDefinitionQuery createProcessDefinitionQuery();
ActivityCoordinates getActivityCoordinates(String processDefinitionId, String activityName);
-
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/job/Job.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/job/Job.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/job/Job.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -35,8 +35,6 @@
String getLockOwner();
- boolean isSuspended();
-
Date getDueDate();
String getException();
Modified: jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/EjbTimerSessionTest.java
===================================================================
--- jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/EjbTimerSessionTest.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/EjbTimerSessionTest.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -82,10 +82,10 @@
.endProcess();
// deploy process
- environment.get(RepositoryService.class)
- .createDeployment()
- .addProcessDefinition(processDefinition)
- .deploy();
+// environment.get(RepositoryService.class)
+// .createDeployment()
+// .addProcessDefinition(processDefinition)
+// .deploy();
processDefinitionId = processDefinition.getId();
}
Modified: jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/TimerTest.java
===================================================================
--- jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/TimerTest.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/internal/ejb/TimerTest.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -130,10 +130,10 @@
public void testHappyTimer() throws CreateException {
// deploy process
listenerDescriptor.setClassName(HappyListener.class.getName());
- environment.get(RepositoryService.class)
- .createDeployment()
- .addProcessDefinition(processDefinition)
- .deploy();
+// environment.get(RepositoryService.class)
+// .createDeployment()
+// .addProcessDefinition(processDefinition)
+// .deploy();
// start execution
Execution execution = environment.get(ExecutionService.class).startProcessInstanceById(
@@ -175,10 +175,10 @@
public void testNoisyTimer() throws CreateException {
// deploy process
listenerDescriptor.setClassName(NoisyListener.class.getName());
- environment.get(RepositoryService.class)
- .createDeployment()
- .addProcessDefinition(processDefinition)
- .deploy();
+// environment.get(RepositoryService.class)
+// .createDeployment()
+// .addProcessDefinition(processDefinition)
+// .deploy();
// start execution
ExecutionService executionService = environment.get(ExecutionService.class);
@@ -228,10 +228,10 @@
public void testCyclicTimer() throws CreateException {
// deploy process
listenerDescriptor.setClassName(HappyListener.class.getName());
- environment.get(RepositoryService.class)
- .createDeployment()
- .addProcessDefinition(processDefinition)
- .deploy();
+// environment.get(RepositoryService.class)
+// .createDeployment()
+// .addProcessDefinition(processDefinition)
+// .deploy();
// start execution
ExecutionImpl execution = (ExecutionImpl) environment.get(ExecutionService.class)
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -44,10 +44,6 @@
private static Log log = Log.getLog(JpdlDeployer.class.getName());
- public static final String KEY_ID = "id";
- public static final String KEY_KEY = "key";
- public static final String KEY_VERSION = "version";
-
static JpdlParser jpdlParser = new JpdlParser();
public void deploy(DeploymentImpl deployment) {
@@ -67,9 +63,9 @@
processDefinition.setDeploymentDbid(deployment.getDbid());
if (deployment.hasObjectProperties(processDefinitionName)) {
- String key = (String) deployment.getObjectProperty(processDefinitionName, KEY_KEY);
- String id = (String) deployment.getObjectProperty(processDefinitionName, KEY_ID);
- Long version = (Long) deployment.getObjectProperty(processDefinitionName, KEY_VERSION);
+ String key = deployment.getProcessDefinitionKey(processDefinitionName);
+ String id = deployment.getProcessDefinitionId(processDefinitionName);
+ Long version = deployment.getProcessDefinitionVersion(processDefinitionName);
processDefinition.setId(id);
processDefinition.setKey(key);
processDefinition.setVersion(version.intValue());
@@ -79,9 +75,9 @@
checkVersion(processDefinition, deployment);
checkId(processDefinition, deployment);
- deployment.addObjectProperty(processDefinitionName, KEY_KEY, processDefinition.getKey());
- deployment.addObjectProperty(processDefinitionName, KEY_VERSION, new Long(processDefinition.getVersion()));
- deployment.addObjectProperty(processDefinitionName, KEY_ID, processDefinition.getId());
+ deployment.setProcessDefinitionId(processDefinitionName, processDefinition.getId());
+ deployment.setProcessDefinitionKey(processDefinitionName, processDefinition.getKey());
+ deployment.setProcessDefinitionVersion(processDefinitionName, new Long(processDefinition.getVersion()));
}
deployment.addObject(processDefinitionName, processDefinition);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -86,6 +86,8 @@
private void deployFile(ProcessEngine processEngine, File processFile) {
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment();
+ deployment.setName(processFile.getName());
+ deployment.setTimestamp(System.currentTimeMillis());
if (processFile.getName().endsWith(".xml")) {
log("deploying process file "+processFile.getName());
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeDeploymentCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeDeploymentCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeDeploymentCmd.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -0,0 +1,49 @@
+/*
+ * 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.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ResumeDeploymentCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ long deploymentDbid;
+
+ public ResumeDeploymentCmd(long deploymentDbid) {
+ this.deploymentDbid = deploymentDbid;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ Session session = environment.get(Session.class);
+ DeploymentImpl deployment = (DeploymentImpl) session.load(DeploymentImpl.class, deploymentDbid);
+ deployment.resume();
+ return null;
+ }
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/ResumeDeploymentCmd.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/StartProcessInstanceInLatestCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/StartProcessInstanceInLatestCmd.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/StartProcessInstanceInLatestCmd.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -57,6 +57,9 @@
RepositorySession repositorySession = environment.get(RepositorySession.class);
processDefinition = (ClientProcessDefinition) repositorySession.findProcessDefinitionByKey(processDefinitionKey);
+ if (processDefinition==null) {
+ throw new JbpmException("no process definition with key "+processDefinitionKey);
+ }
ClientProcessInstance processInstance = processDefinition.createProcessInstance(executionKey);
processInstance.setVariables(variables);
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendDeploymentCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendDeploymentCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendDeploymentCmd.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -0,0 +1,50 @@
+/*
+ * 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.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SuspendDeploymentCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ long deploymentDbid;
+
+ public SuspendDeploymentCmd(long deploymentDbid) {
+ this.deploymentDbid = deploymentDbid;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ Session session = environment.get(Session.class);
+ DeploymentImpl deployment = (DeploymentImpl) session.load(DeploymentImpl.class, deploymentDbid);
+ deployment.suspend();
+ return null;
+ }
+
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SuspendDeploymentCmd.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateJobDbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateJobDbSession.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateJobDbSession.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -35,7 +35,6 @@
public class HibernateJobDbSession extends HibernateDbSession implements JobDbSession {
public JobImpl<?> findFirstAcquirableJob() {
- // query definition can be found at the bottom of resource jbpm.pvm.job.hbm.xml
Query query = session.getNamedQuery("findFirstAcquirableJob");
query.setTimestamp("now", Clock.getCurrentTime());
query.setMaxResults(1);
@@ -43,7 +42,6 @@
}
public List<JobImpl<?>> findExclusiveJobs(Execution processInstance) {
- // query definition can be found at the bottom of resource jbpm.pvm.job.hbm.xml
Query query = session.getNamedQuery("findExclusiveJobs");
query.setTimestamp("now", Clock.getCurrentTime());
query.setEntity("processInstance", processInstance);
@@ -51,7 +49,6 @@
}
public JobImpl<?> findFirstDueJob() {
- // query definition can be found at the bottom of resource jbpm.pvm.job.hbm.xml
Query query = session.getNamedQuery("findFirstDueJob");
query.setMaxResults(1);
return (JobImpl<?>) query.uniqueResult();
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 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -37,6 +37,7 @@
import org.jbpm.api.session.PvmDbSession;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
+import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
import org.jbpm.pvm.internal.svc.DefaultCommandService;
@@ -264,6 +265,62 @@
}
}
+ public void cascadeExecutionSuspend(ExecutionImpl execution) {
+ // cascade suspend to jobs
+ Query query = session.createQuery(
+ "select job " +
+ "from "+JobImpl.class.getName()+" as job " +
+ "where job.execution = :execution " +
+ " and job.state != '"+JobImpl.STATE_SUSPENDED+"' "
+ );
+ query.setEntity("execution", execution);
+ List<JobImpl> jobs = query.list();
+ for (JobImpl job: jobs) {
+ job.suspend();
+ }
+
+ // cascade suspend to tasks
+ query = session.createQuery(
+ "select task " +
+ "from "+TaskImpl.class.getName()+" as task " +
+ "where task.execution = :execution " +
+ " and task.state != '"+TaskImpl.STATE_SUSPENDED+"' "
+ );
+ query.setEntity("execution", execution);
+ List<TaskImpl> tasks = query.list();
+ for (TaskImpl task: tasks) {
+ task.suspend();
+ }
+ }
+
+ public void cascadeExecutionResume(ExecutionImpl execution) {
+ // cascade suspend to jobs
+ Query query = session.createQuery(
+ "select job " +
+ "from "+JobImpl.class.getName()+" as job " +
+ "where job.execution = :execution " +
+ " and job.state = '"+TaskImpl.STATE_SUSPENDED+"' "
+ );
+ query.setEntity("execution", execution);
+ List<JobImpl> jobs = query.list();
+ for (JobImpl job: jobs) {
+ job.resume();
+ }
+
+ // cascade suspend to tasks
+ query = session.createQuery(
+ "select task " +
+ "from "+TaskImpl.class.getName()+" as task " +
+ "where task.execution = :execution " +
+ " and task.state = '"+TaskImpl.STATE_SUSPENDED+"' "
+ );
+ query.setEntity("execution", execution);
+ List<TaskImpl> tasks = query.list();
+ for (TaskImpl task: tasks) {
+ task.resume();
+ }
+ }
+
private List<TaskImpl> findTasks(String processInstanceId) {
Query query = session.createQuery(
"select task " +
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTaskDbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTaskDbSession.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernateTaskDbSession.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -28,7 +28,6 @@
import org.jbpm.api.session.TaskDbSession;
import org.jbpm.api.task.Task;
import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.task.LifeCycle;
import org.jbpm.pvm.internal.task.SwimlaneImpl;
import org.jbpm.pvm.internal.task.TaskImpl;
import org.jbpm.pvm.internal.util.Clock;
@@ -67,7 +66,6 @@
public Task createTask() {
TaskImpl task = newTask();
task.setCreate(Clock.getCurrentTime());
- task.setState(LifeCycle.initialise(task));
return task;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -13,6 +13,11 @@
private static final long serialVersionUID = 1L;
// private static final DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS");
+ public static final String STATE_WAITING = "waiting";
+ public static final String STATE_ACQUIRED = "acquired";
+ public static final String STATE_ERROR = "error";
+ public static final String STATE_SUSPENDED = "suspended";
+
protected long dbid;
protected int dbversion;
@@ -20,8 +25,8 @@
* for async messages, this dueDate should be set to null. */
protected Date dueDate = null;
- /** suspended jobs will not execute. */
- protected boolean isSuspended;
+ /** job state. */
+ protected String state;
/** the execution (if any) for this jobImpl */
protected ExecutionImpl execution;
@@ -62,6 +67,30 @@
this.processInstance = execution.getProcessInstance();
}
+ public void acquire(String lockOwner, Date lockExpirationTime) {
+ this.state = STATE_ACQUIRED;
+ this.lockOwner = lockOwner;
+ this.lockExpirationTime = lockExpirationTime;
+ }
+ public void release() {
+ this.state = STATE_WAITING;
+ this.lockOwner = null;
+ this.lockExpirationTime = null;
+ }
+ public void setRetries(int retries) {
+ this.retries = retries;
+ if (this.retries==0) {
+ this.state = STATE_ERROR;
+ }
+ }
+ public void suspend() {
+ this.state = STATE_SUSPENDED;
+ }
+ public void resume() {
+ this.state = STATE_WAITING;
+ }
+
+
public long getDbid() {
return dbid;
}
@@ -71,9 +100,6 @@
public String getLockOwner() {
return lockOwner;
}
- public boolean isSuspended() {
- return isSuspended;
- }
public Date getDueDate() {
return dueDate;
}
@@ -92,24 +118,18 @@
public ExecutionImpl getExecution() {
return execution;
}
- public void setException(String exception) {
- this.exception = exception;
- }
public void setExclusive(boolean isExclusive) {
this.isExclusive = isExclusive;
}
public void setLockOwner(String jobExecutorName) {
this.lockOwner = jobExecutorName;
}
- public void setRetries(int retries) {
- this.retries = retries;
- }
- public void setSuspended(boolean isSuspended) {
- this.isSuspended = isSuspended;
- }
public ExecutionImpl getProcessInstance() {
return processInstance;
}
+ public void setException(String exception) {
+ this.exception = exception;
+ }
public Date getLockExpirationTime() {
return lockExpirationTime;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -136,8 +136,7 @@
if (log.isDebugEnabled()) log.debug("rescheduled "+this+" for "+formatDueDate(dueDate));
// release the lock on the timer
- setLockOwner(null);
- setLockExpirationTime(null);
+ release();
// notify the jobExecutor at the end of the transaction
JobExecutor jobExecutor = environment.get(JobExecutor.class);
@@ -153,7 +152,7 @@
return deleteThisJob;
}
-
+
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("timer[");
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/AcquireJobsCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/AcquireJobsCmd.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/AcquireJobsCmd.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -72,8 +72,7 @@
for (JobImpl<?> acquiredJob: acquiredJobs) {
long lockExpirationTime = System.currentTimeMillis()+jobExecutor.getLockMillis();
log.trace("trying to obtain a lock for '"+acquiredJob+"' with exp "+timeFormat.format(new Date(lockExpirationTime)));
- acquiredJob.setLockExpirationTime(new Date(lockExpirationTime));
- acquiredJob.setLockOwner(jobExecutor.getName());
+ acquiredJob.acquire(jobExecutor.getName(), new Date(lockExpirationTime));
acquiredJobDbids.add(acquiredJob.getDbid());
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExceptionHandler.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -26,7 +26,6 @@
import javax.transaction.Synchronization;
-import org.hibernate.Session;
import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.CommandService;
@@ -83,11 +82,9 @@
// decrement the number of retries
int decrementedRetries = job.getRetries()-1;
log.debug("decrementing retries to "+decrementedRetries+" for "+job);
+ job.release();
job.setRetries(decrementedRetries);
- job.setException(sw.toString());
- log.debug("unlocking "+job);
- job.setLockOwner(null);
- job.setLockExpirationTime(null);
+ job.setException(sw.toString());
// notify the job executor after the transaction is completed
Transaction transaction = environment.get(Transaction.class);
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 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -52,8 +52,10 @@
import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.model.Transition;
import org.jbpm.api.session.MessageSession;
+import org.jbpm.api.session.PvmDbSession;
import org.jbpm.api.session.RepositorySession;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.hibernate.HibernatePvmDbSession;
import org.jbpm.pvm.internal.history.HistoryEvent;
import org.jbpm.pvm.internal.history.HistorySession;
import org.jbpm.pvm.internal.history.events.ActivityEnd;
@@ -70,6 +72,7 @@
import org.jbpm.pvm.internal.model.op.ProceedToDestination;
import org.jbpm.pvm.internal.model.op.Signal;
import org.jbpm.pvm.internal.model.op.TakeTransition;
+import org.jbpm.pvm.internal.repository.RepositorySessionImpl;
import org.jbpm.pvm.internal.util.EqualsUtil;
import org.jbpm.pvm.internal.util.Priority;
@@ -355,6 +358,10 @@
if (isSuspended()) {
throw new JbpmException(toString()+" is suspended");
}
+ HibernatePvmDbSession hibernatePvmDbSession = Environment.getFromCurrent(HibernatePvmDbSession.class, false);
+ if (hibernatePvmDbSession!=null) {
+ hibernatePvmDbSession.cascadeExecutionSuspend(this);
+ }
lock(STATE_SUSPENDED);
}
@@ -363,6 +370,10 @@
if (! isSuspended()) {
throw new JbpmException(toString()+" is not suspended");
}
+ HibernatePvmDbSession hibernatePvmDbSession = Environment.getFromCurrent(HibernatePvmDbSession.class, false);
+ if (hibernatePvmDbSession!=null) {
+ hibernatePvmDbSession.cascadeExecutionResume(this);
+ }
unlock();
}
@@ -1202,4 +1213,7 @@
public void setHistoryActivityStart(Date historyActivityStart) {
this.historyActivityStart = historyActivityStart;
}
+ public String getProcessDefinitionId() {
+ return processDefinitionId;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -57,6 +57,7 @@
protected String key;
protected String nameLike;
protected String name;
+ protected boolean suspended;
protected Long deploymentDbid;
public ProcessDefinitionQueryImpl(CommandService commandService) {
@@ -102,15 +103,21 @@
hql.append(" as keyProperty, ");
hql.append(DeploymentProperty.class.getName());
hql.append(" as versionProperty ");
-
- appendWhereClause("idProperty.key = 'id'", hql);
+
+ if (suspended) {
+ appendWhereClause("deployment.state = '"+DeploymentImpl.STATE_SUSPENDED+"'", hql);
+ } else {
+ appendWhereClause("deployment.state != '"+DeploymentImpl.STATE_SUSPENDED+"'", hql);
+ }
+
+ appendWhereClause("idProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_ID+"'", hql);
appendWhereClause("idProperty.deployment = deployment ", hql);
- appendWhereClause("keyProperty.key = 'key' ", hql);
+ appendWhereClause("keyProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_KEY+"' ", hql);
appendWhereClause("keyProperty.objectName = idProperty.objectName ", hql);
appendWhereClause("keyProperty.deployment = deployment ", hql);
- appendWhereClause("versionProperty.key = 'version' ", hql);
+ appendWhereClause("versionProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_VERSION+"' ", hql);
appendWhereClause("versionProperty.objectName = idProperty.objectName ", hql);
appendWhereClause("versionProperty.deployment = deployment ", hql);
@@ -159,6 +166,11 @@
this.key = key;
return this;
}
+
+ public ProcessDefinitionQuery suspended() {
+ this.suspended = true;
+ return this;
+ }
public ProcessDefinitionQuery nameLike(String name) {
this.nameLike = name;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -39,6 +39,7 @@
protected String processDefinitionId;
protected String processInstanceId;
+ protected boolean suspended;
public ProcessInstanceQueryImpl(CommandService commandService) {
super(commandService);
@@ -61,6 +62,12 @@
appendWhereClause("processInstance.parent is null ", hql);
+ if (suspended) {
+ appendWhereClause("processInstance.state = '"+ExecutionImpl.STATE_SUSPENDED+"' ", hql);
+ } else {
+ appendWhereClause("processInstance.state != '"+ExecutionImpl.STATE_SUSPENDED+"' ", hql);
+ }
+
if (processInstanceId!=null) {
appendWhereClause("processInstance.processInstance.id = '"+processInstanceId+"' ", hql);
}
@@ -87,11 +94,6 @@
return this;
}
- public ProcessInstanceQuery processDefinitionId(String processDefinitionId) {
- this.processDefinitionId = processDefinitionId;
- return this;
- }
-
public ProcessInstanceQuery page(int firstResult, int maxResults) {
this.page = new Page(firstResult, maxResults);
return this;
@@ -101,4 +103,14 @@
this.processInstanceId = processInstanceId;
return this;
}
+
+ public ProcessInstanceQuery processDefinitionId(String processDefinitionId) {
+ this.processDefinitionId = processDefinitionId;
+ return this;
+ }
+
+ public ProcessInstanceQuery suspended() {
+ this.suspended = true;
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -37,8 +37,9 @@
import org.jbpm.api.Deployment;
import org.jbpm.api.JbpmException;
-import org.jbpm.api.client.ClientProcessDefinition;
import org.jbpm.api.cmd.CommandService;
+import org.jbpm.api.env.Environment;
+import org.jbpm.api.session.RepositorySession;
import org.jbpm.pvm.internal.cmd.DeployCmd;
import org.jbpm.pvm.internal.lob.Lob;
import org.jbpm.pvm.internal.stream.ByteArrayStreamInput;
@@ -57,9 +58,17 @@
*/
public class DeploymentImpl extends ProblemList implements Deployment {
+ public static final String STATE_ACTIVE = "active";
+ public static final String STATE_SUSPENDED = "suspended";
+
+ public static final String KEY_PROCESS_DEFINITION_ID = "pdid";
+ public static final String KEY_PROCESS_DEFINITION_KEY = "pdkey";
+ public static final String KEY_PROCESS_DEFINITION_VERSION = "pdversion";
+
protected long dbid;
protected String name;
protected long timestamp;
+ protected String state = STATE_ACTIVE;
protected Map<String, Lob> resources;
protected CommandService commandService;
@@ -164,8 +173,34 @@
}
objects.put(objectName, object);
}
+
+ // object properties ////////////////////////////////////////////////////////
+
+ public void setProcessDefinitionId(String processDefinitionName, String processDefinitionId) {
+ setObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_ID, processDefinitionId);
+ }
+
+ public String getProcessDefinitionId(String processDefinitionName) {
+ return (String) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_ID);
+ }
- public void addObjectProperty(String objectName, String key, Object value) {
+ public void setProcessDefinitionKey(String processDefinitionName, String processDefinitionKey) {
+ setObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_KEY, processDefinitionKey);
+ }
+
+ public String getProcessDefinitionKey(String processDefinitionName) {
+ return (String) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_KEY);
+ }
+
+ public void setProcessDefinitionVersion(String processDefinitionName, Long processDefinitionVersion) {
+ setObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_VERSION, processDefinitionVersion);
+ }
+
+ public Long getProcessDefinitionVersion(String processDefinitionName) {
+ return (Long) getObjectProperty(processDefinitionName, KEY_PROCESS_DEFINITION_VERSION);
+ }
+
+ public void setObjectProperty(String objectName, String key, Object value) {
if (objectProperties==null) {
objectProperties = new HashSet<DeploymentProperty>();
}
@@ -187,6 +222,19 @@
return null;
}
+ public Set<String> getProcessDefinitionIds() {
+ Set<String> processDefinitionIds = new HashSet<String>();
+ if (objectProperties!=null) {
+ for (DeploymentProperty deploymentProperty: objectProperties) {
+ if (KEY_PROCESS_DEFINITION_ID.equals(deploymentProperty.getKey())) {
+ String processDefinitionId = deploymentProperty.getStringValue();
+ processDefinitionIds.add(processDefinitionId);
+ }
+ }
+ }
+ return processDefinitionIds;
+ }
+
public boolean hasObjectProperties(String objectName) {
if (objectProperties!=null) {
for (DeploymentProperty deploymentProperty: objectProperties) {
@@ -197,7 +245,33 @@
}
return false;
}
+
+ public void suspend() {
+ if (isSuspended()) {
+ throw new JbpmException("deployment is already suspended");
+ }
+ RepositorySessionImpl repositorySession = Environment.getFromCurrent(RepositorySessionImpl.class, false);
+ if (repositorySession!=null) {
+ repositorySession.cascadeDeploymentSuspend(this);
+ }
+ state = STATE_SUSPENDED;
+ }
+ public void resume() {
+ if (!isSuspended()) {
+ throw new JbpmException("deployment is not suspended");
+ }
+ RepositorySessionImpl repositorySession = Environment.getFromCurrent(RepositorySessionImpl.class, false);
+ if (repositorySession!=null) {
+ repositorySession.cascadeDeploymentResume(this);
+ }
+ state = STATE_ACTIVE;
+ }
+
+ public boolean isSuspended() {
+ return STATE_SUSPENDED.equals(state);
+ }
+
protected Object writeReplace() throws ObjectStreamException {
commandService = null;
return this;
@@ -226,9 +300,4 @@
this.timestamp = timestamp;
return this;
}
-
-
- public Deployment addProcessDefinition(ClientProcessDefinition processDefinition) {
- throw new UnsupportedOperationException("implement me");
- }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCache.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCache.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCache.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -31,5 +31,6 @@
void set(long deploymentdbid, Map<String, Object> deployedObjects);
Object get(long deploymentDbid, String objectName);
+ void remove(long deploymentDbid);
void clear();
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCacheImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCacheImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryCacheImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -56,6 +56,12 @@
}
}
+ public void remove(long deploymentDbid) {
+ if (deployments!=null) {
+ deployments.remove(deploymentDbid);
+ }
+ }
+
public void clear() {
deployments = new HashMap<Long, Map<String,Object>>();
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -31,6 +31,8 @@
import org.jbpm.pvm.internal.cmd.DeleteDeploymentCmd;
import org.jbpm.pvm.internal.cmd.GetActivityCoordinates;
import org.jbpm.pvm.internal.cmd.GetResourceAsStreamCmd;
+import org.jbpm.pvm.internal.cmd.ResumeDeploymentCmd;
+import org.jbpm.pvm.internal.cmd.SuspendDeploymentCmd;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
/**
@@ -44,6 +46,14 @@
return new DeploymentImpl(commandService);
}
+ public void suspendDeployment(long deploymentDbid) {
+ commandService.execute(new SuspendDeploymentCmd(deploymentDbid));
+ }
+
+ public void resumeDeployment(long deploymentDbid) {
+ commandService.execute(new ResumeDeploymentCmd(deploymentDbid));
+ }
+
public void deleteDeployment(long deploymentDbid) {
commandService.execute(new DeleteDeploymentCmd(deploymentDbid));
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -23,7 +23,10 @@
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.hibernate.Query;
import org.hibernate.Session;
import org.jbpm.api.Deployment;
import org.jbpm.api.JbpmException;
@@ -33,6 +36,7 @@
import org.jbpm.api.client.ClientProcessDefinition;
import org.jbpm.api.session.RepositorySession;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
/**
@@ -59,13 +63,58 @@
log.info("errors during deployment of "+deployment+": "+jbpmException.getMessage());
throw jbpmException;
} else {
-
repositoryCache.set(deploymentImpl.getDbid(), deploymentImpl.getObjects());
}
return deploymentImpl.getDbid();
}
+
+ public void cascadeDeploymentSuspend(DeploymentImpl deployment) {
+ // cascade to all executions in this deployment
+ Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
+ if (!processDefinitionIds.isEmpty()) {
+ Query query = session.createQuery(
+ "select execution " +
+ "from "+ExecutionImpl.class.getName()+" as execution " +
+ "where execution.processDefinitionId in (:processDefinitionIds) " +
+ " and execution.state != '"+ExecutionImpl.STATE_SUSPENDED+"'"
+ );
+ query.setParameterList("processDefinitionIds", processDefinitionIds);
+ List<ExecutionImpl> executions = query.list();
+ for (ExecutionImpl execution: executions) {
+ execution.suspend();
+ }
+ }
+
+ // TODO cleaning this cache should actually be done as a synchronization
+ // after the transaction. If a concurrent transaction for an execution
+ // starts between clearing the cache and committing the transaction, then
+ // that transaction could potentially re-initialize the process definition
+ // in the cache.
+ repositoryCache.remove(deployment.getDbid());
+ }
+
+ public void cascadeDeploymentResume(DeploymentImpl deployment) {
+ // cascade to all executions in this deployment
+ Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
+ if (!processDefinitionIds.isEmpty()) {
+ Query query = session.createQuery(
+ "select execution " +
+ "from "+ExecutionImpl.class.getName()+" as execution " +
+ "where execution.processDefinitionId in (:processDefinitionIds) " +
+ " and execution.state = '"+ExecutionImpl.STATE_SUSPENDED+"'"
+ );
+ query.setParameterList("processDefinitionIds", processDefinitionIds);
+ List<ExecutionImpl> executions = query.list();
+ for (ExecutionImpl execution: executions) {
+ execution.resume();
+ }
+ }
+
+ deploy(deployment);
+ }
+
public DeploymentImpl getDeployment(long deploymentDbid) {
return (DeploymentImpl) session.get(DeploymentImpl.class, deploymentDbid);
}
@@ -78,10 +127,11 @@
} else {
log.trace("loading deployment "+deploymentDbid+" from db");
DeploymentImpl deployment = (DeploymentImpl) session.load(DeploymentImpl.class, deploymentDbid);
+ if (deployment.isSuspended()) {
+ throw new JbpmException("deployment "+deploymentDbid+" is suspended");
+ }
deploy(deployment);
-
object = repositoryCache.get(deploymentDbid, objectName);
-
if (object==null) {
throw new JbpmException("deployment "+deploymentDbid+" doesn't contain object "+objectName);
}
@@ -121,7 +171,7 @@
DeploymentProperty deploymentProperty = (DeploymentProperty) session.createQuery(
"select deploymentProperty " +
"from "+DeploymentProperty.class.getName()+" as deploymentProperty " +
- "where deploymentProperty.key = 'id' " +
+ "where deploymentProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_ID+"' " +
" and deploymentProperty.stringValue = '"+processDefinitionId+"' "
).setMaxResults(1).uniqueResult();
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/LifeCycle.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/LifeCycle.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/LifeCycle.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -83,7 +83,7 @@
Activity activity = lifeCycleProcess.getActivity(state);
lifeCycleExecution.setActivity((ActivityImpl) activity);
lifeCycleExecution.signal(eventName);
- task.state = lifeCycleExecution.getActivity().getName();
+ task.setState(lifeCycleExecution.getActivity().getName());
}
public IdGenerator getIdGenerator() {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -62,7 +62,10 @@
// private static Log log = Log.getLog(TaskImpl.class.getName());
- private static final TaskHandler DEFAULT_TASK_HANDLER = new TaskHandler();
+ private static final TaskHandler DEFAULT_TASK_HANDLER = new TaskHandler();
+
+ public static final String STATE_SUSPENDED = "suspended";
+ public static final String STATE_ACTIVE = "active";
protected String id;
protected String name;
@@ -82,7 +85,7 @@
protected int priority = Priority.NORMAL;
- protected String state;
+ protected String state = STATE_ACTIVE;
protected String taskDefinitionName;
protected TaskDefinitionImpl taskDefinition;
@@ -493,4 +496,9 @@
public void setForm(String form) {
this.form = form;
}
+
+ public void suspend() {
+ }
+ public void resume() {
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -144,6 +144,8 @@
}
}
+ appendWhereClause("task.state != '"+TaskImpl.STATE_SUSPENDED+"' ", hql);
+
if (assignee == UNASSIGNED) {
appendWhereClause("task.assignee is null ", hql);
} else if (assignee != null) {
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-13 15:15:51 UTC (rev 4807)
@@ -217,7 +217,7 @@
<version name="dbversion" column="DBVERSION_" />
<property name="dueDate" column="DUEDATE_" type="timestamp" index="IDX_JOBDUEDATE" />
- <property name="isSuspended" column="ISSUSPENDED_" />
+ <property name="state" column="STATE_" />
<property name="isExclusive" column="ISEXCLUSIVE_" />
<property name="lockOwner" column="LOCKOWNER_" />
<property name="lockExpirationTime" column="LOCKEXPTIME_" index="IDX_JOBLOCKEXP" />
@@ -307,6 +307,8 @@
)
and
( job.retries > 0 )
+ and
+ ( job.state != 'suspended' )
)
order by job.dueDate asc
]]>
@@ -320,6 +322,7 @@
and job.processInstance = :processInstance
and job.isExclusive = true
and job.retries > 0
+ and job.state != 'suspended'
and ( (job.dueDate is null)
or (job.dueDate <= :now)
)
@@ -333,6 +336,7 @@
from org.jbpm.pvm.internal.job.JobImpl as job
where job.lockOwner is null
and job.retries > 0
+ and job.state != 'suspended'
order by job.dueDate asc
]]>
</query>
@@ -343,6 +347,7 @@
select execution
from org.jbpm.pvm.internal.model.ExecutionImpl as execution
where execution.id = :id
+ and execution.state != 'suspended'
]]>
</query>
@@ -352,6 +357,7 @@
from org.jbpm.pvm.internal.model.ExecutionImpl as processInstance
where processInstance.id = :processInstanceId
and processInstance.parent is null
+ and processInstance.state != 'suspended'
]]>
</query>
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.repository.hbm.xml 2009-05-13 15:15:51 UTC (rev 4807)
@@ -14,6 +14,7 @@
<property name="name" type="text" column="NAME_" />
<property name="timestamp" column="TIMESTAMP_" />
+ <property name="state" column="STATE_" />
<map name="resources" cascade="all-delete-orphan">
<key foreign-key="FK_LOB_DEPLOYMENT">
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.task.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.task.hbm.xml 2009-05-13 09:44:37 UTC (rev 4806)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.task.hbm.xml 2009-05-13 15:15:51 UTC (rev 4807)
@@ -76,6 +76,7 @@
<property name="id" column="ID_" unique="true" />
<property name="name" column="NAME_"/>
<property name="description" column="DESCR_"/>
+ <property name="state" column="STATE_"/>
<property name="assignee" column="ASSIGNEE_"/>
<property name="form" column="FORM_"/>
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/SuspendDeploymentTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/SuspendDeploymentTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/SuspendDeploymentTest.java 2009-05-13 15:15:51 UTC (rev 4807)
@@ -0,0 +1,152 @@
+/*
+ * 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.deploy;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SuspendDeploymentTest extends JbpmTestCase {
+
+ public void testSuspendDeployment() {
+ deployJpdlXmlString(
+ "<process name='claim'>" +
+ " <start>" +
+ " <transition to='c' />" +
+ " </start>" +
+ " <state name='c' />" +
+ "</process>"
+ );
+
+ long deploymentHireDbid = deployJpdlXmlString(
+ "<process name='hire'>" +
+ " <start>" +
+ " <transition to='h' />" +
+ " </start>" +
+ " <state name='h' />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fire'>" +
+ " <start>" +
+ " <transition to='f' />" +
+ " </start>" +
+ " <state name='f' />" +
+ "</process>"
+ );
+
+ Set<String> expectedProcessNames = new HashSet<String>();
+ expectedProcessNames.add("claim");
+ expectedProcessNames.add("hire");
+ expectedProcessNames.add("fire");
+
+ List<ProcessDefinition> processDefinitions = repositoryService
+ .createProcessDefinitionQuery()
+ .list();
+
+ assertEquals(expectedProcessNames, getProcessDefinitionNames(processDefinitions));
+
+ executionService.startProcessInstanceByKey("claim");
+ executionService.startProcessInstanceByKey("claim");
+
+ executionService.startProcessInstanceByKey("hire");
+ executionService.startProcessInstanceByKey("hire");
+
+ executionService.startProcessInstanceByKey("fire");
+ executionService.startProcessInstanceByKey("fire");
+
+ List<Execution> processInstances = executionService
+ .createProcessInstanceQuery()
+ .list();
+
+ assertEquals(2, countProcessInstancesFor(processInstances, "claim"));
+ assertEquals(2, countProcessInstancesFor(processInstances, "hire"));
+ assertEquals(2, countProcessInstancesFor(processInstances, "fire"));
+ assertEquals(6, processInstances.size());
+
+
+ repositoryService.suspendDeployment(deploymentHireDbid);
+
+
+ expectedProcessNames.remove("hire");
+
+ processDefinitions = repositoryService
+ .createProcessDefinitionQuery()
+ .list();
+
+ assertEquals(expectedProcessNames, getProcessDefinitionNames(processDefinitions));
+
+ processInstances = executionService
+ .createProcessInstanceQuery()
+ .list();
+
+ assertEquals(2, countProcessInstancesFor(processInstances, "claim"));
+ assertEquals(2, countProcessInstancesFor(processInstances, "fire"));
+ assertEquals(4, processInstances.size());
+
+ repositoryService.resumeDeployment(deploymentHireDbid);
+
+ expectedProcessNames.add("hire");
+
+ processDefinitions = repositoryService
+ .createProcessDefinitionQuery()
+ .list();
+
+ assertEquals(expectedProcessNames, getProcessDefinitionNames(processDefinitions));
+
+ processInstances = executionService
+ .createProcessInstanceQuery()
+ .list();
+
+ assertEquals(2, countProcessInstancesFor(processInstances, "claim"));
+ assertEquals(2, countProcessInstancesFor(processInstances, "hire"));
+ assertEquals(2, countProcessInstancesFor(processInstances, "fire"));
+ assertEquals(6, processInstances.size());
+ }
+
+ int countProcessInstancesFor(List<Execution> processInstances, String processDefinitionKey) {
+ int count = 0;
+ for (Execution processInstance: processInstances) {
+ if (processInstance.getProcessDefinitionId().startsWith(processDefinitionKey)) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ Object getProcessDefinitionNames(List<ProcessDefinition> processDefinitions) {
+ Set<String> processNames = new HashSet<String>();
+ for (ProcessDefinition processDefinition: processDefinitions) {
+ processNames.add(processDefinition.getName());
+ }
+ return processNames;
+ }
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/deploy/SuspendDeploymentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jbpm-commits
mailing list