Index: modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java =================================================================== --- modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java (revision 6471) +++ modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java (working copy) @@ -40,24 +40,24 @@ String taskLaundryId; String taskDishesId; String taskIronId; - + protected void setUp() throws Exception { super.setUp(); - + deploymentId = repositoryService.createDeployment() .addResourceFromClasspath("org/jbpm/examples/hql/process.jpdl.xml") .deploy(); - + // add task laundry Task task = taskService.newTask(); task.setName("laundry"); taskLaundryId = taskService.saveTask(task); - + // add task dishes task = taskService.newTask(); task.setName("dishes"); taskDishesId = taskService.saveTask(task); - + // add task iron task = taskService.newTask(); task.setName("iron"); @@ -66,11 +66,11 @@ protected void tearDown() throws Exception { repositoryService.deleteDeploymentCascade(deploymentId); - + taskService.deleteTaskCascade(taskLaundryId); taskService.deleteTaskCascade(taskDishesId); taskService.deleteTaskCascade(taskIronId); - + super.tearDown(); } @@ -81,7 +81,8 @@ Set expectedTaskNames = new HashSet(); expectedTaskNames.add("dishes"); expectedTaskNames.add("iron"); - Collection taskNames = (Collection) executionService.getVariable(processInstanceId, "tasknames with i"); + Collection taskNames = (Collection) executionService.getVariable(processInstanceId, + "tasknames with i"); taskNames = new HashSet(taskNames); assertEquals(expectedTaskNames, taskNames); Index: modules/examples/src/test/java/org/jbpm/examples/hql/HqlUpdateTest.java =================================================================== --- modules/examples/src/test/java/org/jbpm/examples/hql/HqlUpdateTest.java (revision 0) +++ modules/examples/src/test/java/org/jbpm/examples/hql/HqlUpdateTest.java (revision 0) @@ -0,0 +1,80 @@ +/* + * 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.examples.hql; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.jbpm.api.ProcessInstance; +import org.jbpm.api.task.Task; +import org.jbpm.test.JbpmTestCase; + + +/** + * @author Huisheng Xu + */ +public class HqlUpdateTest extends JbpmTestCase { + + String deploymentId; + + String taskLaundryId; + String taskDishesId; + String taskIronId; + + protected void setUp() throws Exception { + super.setUp(); + + deploymentId = repositoryService.createDeployment() + .addResourceFromClasspath("org/jbpm/examples/hql/hqlupdate.jpdl.xml") + .deploy(); + + // add task laundry + Task task = taskService.newTask(); + task.setName("laundry"); + taskLaundryId = taskService.saveTask(task); + + // add task dishes + task = taskService.newTask(); + task.setName("dishes"); + taskDishesId = taskService.saveTask(task); + + // add task iron + task = taskService.newTask(); + task.setName("iron"); + taskIronId = taskService.saveTask(task); + } + + protected void tearDown() throws Exception { + repositoryService.deleteDeploymentCascade(deploymentId); + + super.tearDown(); + } + + public void testHql() { + ProcessInstance processInstance = executionService.startProcessInstanceByKey("HqlUpdate"); + String processInstanceId = processInstance.getId(); + + Object activities = executionService.getVariable(processInstanceId, "tasks"); + assertEquals("3", activities.toString()); + } +} Index: modules/examples/src/test/java/org/jbpm/examples/sql/SqlUpdateTest.java =================================================================== --- modules/examples/src/test/java/org/jbpm/examples/sql/SqlUpdateTest.java (revision 0) +++ modules/examples/src/test/java/org/jbpm/examples/sql/SqlUpdateTest.java (revision 0) @@ -0,0 +1,80 @@ +/* + * 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.examples.sql; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.jbpm.api.Execution; +import org.jbpm.api.task.Task; +import org.jbpm.test.JbpmTestCase; + + +/** + * @author Tom Baeyens + */ +public class SqlUpdateTest extends JbpmTestCase { + + String deploymentId; + + String taskLaundryId; + String taskDishesId; + String taskIronId; + + protected void setUp() throws Exception { + super.setUp(); + + deploymentId = repositoryService.createDeployment() + .addResourceFromClasspath("org/jbpm/examples/sql/sqlupdate.jpdl.xml") + .deploy(); + + // add task laundry + Task task = taskService.newTask(); + task.setName("laundry"); + taskLaundryId = taskService.saveTask(task); + + // add task dishes + task = taskService.newTask(); + task.setName("dishes"); + taskDishesId = taskService.saveTask(task); + + // add task iron + task = taskService.newTask(); + task.setName("iron"); + taskIronId = taskService.saveTask(task); + } + + protected void tearDown() throws Exception { + repositoryService.deleteDeploymentCascade(deploymentId); + + super.tearDown(); + } + + public void testSql() { + Execution execution = executionService.startProcessInstanceByKey("SqlUpdate"); + String executionId = execution.getId(); + + Object activities = executionService.getVariable(executionId, "tasks"); + assertEquals("3", activities.toString()); + } +} Index: modules/examples/src/test/resources/org/jbpm/examples/hql/hqlupdate.jpdl.xml =================================================================== --- modules/examples/src/test/resources/org/jbpm/examples/hql/hqlupdate.jpdl.xml (revision 0) +++ modules/examples/src/test/resources/org/jbpm/examples/hql/hqlupdate.jpdl.xml (revision 0) @@ -0,0 +1,31 @@ + + + + + + + + + + + delete from org.jbpm.pvm.internal.task.TaskImpl + + + + + + + delete from org.jbpm.pvm.internal.history.model.HistoryTaskImpl + + + + + + + Index: modules/examples/src/test/resources/org/jbpm/examples/sql/sqlupdate.jpdl.xml =================================================================== --- modules/examples/src/test/resources/org/jbpm/examples/sql/sqlupdate.jpdl.xml (revision 0) +++ modules/examples/src/test/resources/org/jbpm/examples/sql/sqlupdate.jpdl.xml (revision 0) @@ -0,0 +1,31 @@ + + + + + + + + + + + delete from JBPM4_TASK + + + + + + + delete from JBPM4_HIST_TASK + + + + + + + Index: modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlActivity.java =================================================================== --- modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlActivity.java (revision 6471) +++ modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlActivity.java (working copy) @@ -37,15 +37,17 @@ * @author Tom Baeyens */ public class HqlActivity extends JpdlAutomaticActivity { - + private static final Log log = Log.getLog(HqlActivity.class.getName()); private static final long serialVersionUID = 1L; - + protected String query; protected ListDescriptor parametersDescriptor; protected String resultVariableName; protected boolean isResultUnique; + /** if this flag is set to true, then we will execute update than query. */ + protected boolean isUpdate; public void perform(OpenExecution execution) { EnvironmentImpl environment = EnvironmentImpl.getCurrent(); @@ -53,9 +55,9 @@ throw new JbpmException("no environment for jpdl activity "+HqlBinding.TAG); } Session session = environment.get(Session.class); - + Query q = createQuery(session); - + if (parametersDescriptor!=null) { for (Descriptor valueDescriptor: parametersDescriptor.getValueDescriptors()) { String parameterName = valueDescriptor.getName(); @@ -63,14 +65,16 @@ applyParameter(q, parameterName, value); } } - + Object result = null; - if (isResultUnique) { + if (isUpdate) { + result = q.executeUpdate(); + } else if (isResultUnique) { result = q.uniqueResult(); } else { result = q.list(); } - + execution.setVariable(resultVariableName, result); } @@ -100,4 +104,7 @@ public void setResultVariableName(String resultVariableName) { this.resultVariableName = resultVariableName; } + public void setUpdate(boolean isUpdate) { + this.isUpdate = isUpdate; + } } Index: modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java =================================================================== --- modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java (revision 6471) +++ modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java (working copy) @@ -43,35 +43,41 @@ public HqlBinding() { super(TAG); } - + protected HqlBinding(String tagName) { super(tagName); } public Object parseJpdl(Element element, Parse parse, JpdlParser parser) { HqlActivity hqlActivity = createHqlActivity(); - + Element queryElement = XmlUtil.element(element, "query", parse); - if (queryElement!=null) { + if (queryElement != null) { String query = XmlUtil.getContentText(queryElement); hqlActivity.setQuery(query); } - + Boolean resultUnique = XmlUtil.attributeBoolean(element, "unique", parse); - if (resultUnique!=null) { + if (resultUnique != null) { hqlActivity.setResultUnique(resultUnique); } - + + Boolean update = XmlUtil.attributeBoolean(element, "update", parse); + if (update != null) { + hqlActivity.setUpdate(update); + } + String variableName = XmlUtil.attribute(element, "var", parse); hqlActivity.setResultVariableName(variableName); - + Element parametersElement = XmlUtil.element(element, "parameters"); List paramElements = XmlUtil.elements(parametersElement); if (!paramElements.isEmpty()) { List parametersDescriptor = new ArrayList(); for (Element paramElement: paramElements) { WireParser wireParser = WireParser.getInstance(); - Descriptor paramDescriptor = (Descriptor) wireParser.parseElement(paramElement, parse, WireParser.CATEGORY_DESCRIPTOR); + Descriptor paramDescriptor = (Descriptor) wireParser.parseElement(paramElement, + parse, WireParser.CATEGORY_DESCRIPTOR); parametersDescriptor.add(paramDescriptor); } @@ -79,7 +85,7 @@ parametersListDescriptor.setValueDescriptors(parametersDescriptor); hqlActivity.setParametersDescriptor(parametersListDescriptor); } - + return hqlActivity; }