### Eclipse Workspace Patch 1.0 #P jbpm4 Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java (working copy) @@ -26,11 +26,13 @@ import org.hibernate.Query; import org.jbpm.api.ProcessInstance; import org.jbpm.api.ProcessInstanceQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.pvm.internal.model.ExecutionImpl; import org.jbpm.pvm.internal.util.CollectionUtil; /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class ProcessInstanceQueryImpl extends AbstractQuery implements ProcessInstanceQuery { @@ -74,15 +76,15 @@ } if (processInstanceId != null) { - appendWhereClause("processInstance.processInstance.id = '" + processInstanceId+"' ", hql); + appendWhereClauseWithOperand(processInstanceId, "processInstance.processInstance.id", "processInstanceId", hql); } if (processDefinitionId != null) { - appendWhereClause("processInstance.processDefinitionId = '" + processDefinitionId+"' ", hql); + appendWhereClauseWithOperand(processDefinitionId, "processInstance.processDefinitionId", "processDefinitionId", hql); } if (processInstanceKey != null) { - appendWhereClause("processInstance.key = '" + processInstanceKey + "'", hql); + appendWhereClauseWithOperand(processInstanceKey, "processInstance.key", "processInstanceKey", hql); } appendOrderByClause(hql); @@ -91,6 +93,17 @@ } protected void applyParameters(Query query) { + if (processInstanceId != null) { + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); + } + + if (processDefinitionId != null) { + applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query); + } + + if (processInstanceKey != null) { + applyParameterWithOperand(processInstanceKey, "processInstanceKey", String.class, query); + } } public ProcessInstanceQuery orderAsc(String property) { @@ -132,5 +145,27 @@ this.suspended = false; return this; } - + public String operand(String parameter, QueryOperand operand) { + parameterOperands.put(parameter, operand); + + return parameter; + } + + public ProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) { + this.processDefinitionId = processDefinitionId; + parameterOperands.put(processDefinitionId, operand); + return this; + } + + public ProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + return this; + } + + public ProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand) { + this.processInstanceKey = processInstanceKey; + parameterOperands.put(processInstanceKey, operand); + return this; + } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java (working copy) @@ -26,6 +26,7 @@ import org.hibernate.Query; import org.jbpm.api.JbpmException; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryActivityInstance; import org.jbpm.api.history.HistoryActivityInstanceQuery; import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl; @@ -34,6 +35,7 @@ /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class HistoryActivityInstanceQueryImpl extends AbstractQuery implements HistoryActivityInstanceQuery { @@ -63,7 +65,7 @@ hql.append(" as hai "); if (processDefinitionId!=null) { - appendWhereClause(" hai.historyProcessInstance.processDefinitionId = '"+processDefinitionId+"' ", hql); + appendWhereClauseWithOperand(processDefinitionId, "hai.historyProcessInstance.processDefinitionId", "processDefinitionId", hql); } if (tookLessThen!=null) { @@ -83,15 +85,15 @@ } if (processInstanceId!=null) { - appendWhereClause(" hai.historyProcessInstance.processInstanceId = '"+processInstanceId+"'", hql); + appendWhereClauseWithOperand(processInstanceId, "hai.historyProcessInstance.processInstanceId", "processInstanceId", hql); } if (executionId!=null) { - appendWhereClause(" hai.executionId = '"+executionId+"'", hql); + appendWhereClauseWithOperand(executionId, "hai.executionId", "executionId", hql); } if (activityName!=null) { - appendWhereClause(" hai.activityName = '"+activityName+"'", hql); + appendWhereClauseWithOperand(activityName, "hai.activityName", "activityName", hql); } appendOrderByClause(hql); @@ -115,6 +117,22 @@ if (startedAfter!=null) { query.setTimestamp("startedAfter", startedAfter); } + + if (processDefinitionId!=null) { + applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query); + } + + if (processInstanceId!=null) { + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); + } + + if (executionId!=null) { + applyParameterWithOperand(executionId, "executionId", String.class, query); + } + + if (activityName!=null) { + applyParameterWithOperand(activityName, "activityName", String.class, query); + } } public List list() { @@ -182,4 +200,32 @@ this.tookLongerThen = durationInMillis; return this; } + + public HistoryActivityInstanceQuery activityName(String activityName, QueryOperand operand) { + this.activityName = activityName; + parameterOperands.put(activityName, operand); + + return this; + } + + public HistoryActivityInstanceQuery executionId(String executionId, QueryOperand operand) { + this.executionId = executionId; + parameterOperands.put(executionId, operand); + + return this; + } + + public HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) { + this.processDefinitionId = processDefinitionId; + parameterOperands.put(processDefinitionId, operand); + + return this; + } + + public HistoryActivityInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + + return this; + } } Index: modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java (working copy) @@ -24,10 +24,13 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; + /** query for task comments, task assignments and so on. * * @author Tom Baeyens + * @author Maciej Swiderski */ public interface HistoryDetailQuery { @@ -44,7 +47,16 @@ /** only select details for the given taskId */ HistoryDetailQuery taskId(String taskId); + + /** only select details for the given processInstanceId, allows to specify query operand */ + HistoryDetailQuery processInstanceId(String processInstanceId, QueryOperand operand); + /** only select details for the given activityInstanceId, allows to specify query operand */ + HistoryDetailQuery activityInstanceId(String activityInstanceId, QueryOperand operand); + + /** only select details for the given taskId, allows to specify query operand */ + HistoryDetailQuery taskId(String taskId, QueryOperand operand); + /** only select details after the given time */ HistoryDetailQuery timeAfter(Date time); Index: modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java (revision 6420) +++ modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java (working copy) @@ -29,6 +29,7 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; import org.jbpm.api.TaskQuery; import org.jbpm.api.task.Task; import org.jbpm.test.JbpmTestCase; @@ -132,7 +133,31 @@ deleteTasks(tasks); } + public void testTaskQueryAssigneeLike() { + List tasks = createTestTasks(); + + assertEquals(2, taskService.createTaskQuery().assignee("%o%m", QueryOperand.LIKE).count()); + + deleteTasks(tasks); + } + public void testTaskQueryAssigneeIn() { + List tasks = createTestTasks(); + + assertEquals(2, taskService.createTaskQuery().assignee("Koen,Tom", QueryOperand.IN).count()); + + deleteTasks(tasks); + } + + public void testTaskQueryAssigneeNotIn() { + List tasks = createTestTasks(); + + assertEquals(1, taskService.createTaskQuery().assignee("Koen,Tom,Alex", QueryOperand.NOT_IN).count()); + + deleteTasks(tasks); + } + + /* ------------------------------------------------------------------- * HELPER METHODS * ------------------------------------------------------------------- */ Index: modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java (working copy) @@ -55,7 +55,19 @@ /** select only process definitions within the given deployment */ ProcessDefinitionQuery deploymentId(String deploymentId); + + /** select only the process definition with the given id, allows to specify query operand */ + ProcessDefinitionQuery processDefinitionId(String processDefinitionId, QueryOperand operand); + /** select only process definitions with the given key, allows to specify query operand */ + ProcessDefinitionQuery processDefinitionKey(String key, QueryOperand operand); + + /** select only process definitions with an exact match for the given name, allows to specify query operand */ + ProcessDefinitionQuery processDefinitionName(String name, QueryOperand operand); + + /** select only process definitions within the given deployment, allows to specify query operand */ + ProcessDefinitionQuery deploymentId(String deploymentId, QueryOperand operand); + /** select only suspended process definitions */ ProcessDefinitionQuery suspended(); Index: modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java (revision 6403) +++ modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java (working copy) @@ -31,6 +31,7 @@ import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessInstance; import org.jbpm.api.ProcessInstanceQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.test.JbpmTestCase; @@ -217,6 +218,94 @@ } + public void testProcessInstanceLike() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(4, executionService.createProcessInstanceQuery().processInstanceId("testProcess1.%", QueryOperand.LIKE).count()); + + assertEquals(6, executionService.createProcessInstanceQuery().processInstanceId("testProcess2.%", QueryOperand.LIKE).count()); + } + + public void testProcessDefinitionLike() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(10, executionService.createProcessInstanceQuery().processDefinitionId("testProcess%", QueryOperand.LIKE).count()); + + } + + public void testProcessInstanceKeyLike() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(4, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-%", QueryOperand.LIKE).count()); + + } + + public void testProcessInstanceIn() { + Map> processInstanceIds = startTestProcesses(4, 6); + List idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY); + List idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(2, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess1.get(0) + "," + idsForTestProcess1.get(1), QueryOperand.IN).count()); + + assertEquals(2, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess2.get(0) + "," + idsForTestProcess2.get(1), QueryOperand.IN).count()); + } + + public void testProcessDefinitionIn() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(4, executionService.createProcessInstanceQuery().processDefinitionId("testProcess1-1,testProcess2", QueryOperand.IN).count()); + + } + + public void testProcessInstanceKeyIn() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(2, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-0,testProcess1-1", QueryOperand.IN).count()); + + } + + public void testProcessInstanceNotIn() { + Map> processInstanceIds = startTestProcesses(4, 6); + List idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY); + List idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(8, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess1.get(0) + "," + idsForTestProcess1.get(1), QueryOperand.NOT_IN).count()); + + assertEquals(8, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess2.get(0) + "," + idsForTestProcess2.get(1), QueryOperand.NOT_IN).count()); + } + + public void testProcessDefinitionNotIn() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(6, executionService.createProcessInstanceQuery().processDefinitionId("testProcess1-1,testProcess2", QueryOperand.NOT_IN).count()); + + } + + public void testProcessInstanceKeyNotIn() { + startTestProcesses(4, 6); + + assertEquals(10, executionService.createProcessInstanceQuery().count()); + + assertEquals(8, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-0,testProcess1-1", QueryOperand.NOT_IN).count()); + + } + /** * Returns a map containing a processKey - processInstanceId mapping. * eg. TEST_PROCESS_1 - {"1", "5", "7", "8"} Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java (revision 6426) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java (working copy) @@ -22,12 +22,15 @@ package org.jbpm.pvm.internal.query; import java.io.ObjectStreamException; +import java.lang.reflect.Array; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.hibernate.Query; import org.hibernate.Session; - import org.jbpm.api.JbpmException; +import org.jbpm.api.QueryOperand; import org.jbpm.api.cmd.Command; import org.jbpm.api.cmd.Environment; import org.jbpm.pvm.internal.cmd.CommandService; @@ -35,6 +38,7 @@ /** * @author Tom Baeyens + * @author Maciej Swiderski */ public abstract class AbstractQuery implements Command { @@ -47,6 +51,8 @@ protected boolean count; protected boolean uniqueResult; + protected Map parameterOperands = new HashMap(); + protected abstract void applyParameters(Query query); public abstract String hql(); @@ -155,7 +161,66 @@ this.commandService = null; return this; } + + protected QueryOperand getOperand(String param) { + if (parameterOperands.containsKey(param)) { + return parameterOperands.get(param); + } + return QueryOperand.EQUALS; + } + + protected boolean isListOperand(String param) { + QueryOperand operand = getOperand(param); + + if (operand == QueryOperand.IN || operand == QueryOperand.NOT_IN) { + return true; + } else { + return false; + } + } + + /** + * Transforms given string (parameter) to an array of given type (clazz). + * parameter will be split using separator ',' (comma). + * Array will be populated based on split string by creating new instance of class clazz + * using its constructor that accepts String argument. + * All exceptions will be silently skipped. + */ + @SuppressWarnings("unchecked") + protected T[] transformToArray(String parameter, T clazz) { + String[] idsStr = parameter.split(","); + if (clazz instanceof String) { + return (T[]) idsStr; + } + T[] ids = (T[]) Array.newInstance( (Class)clazz, idsStr.length); + + for (int i = 0; i < idsStr.length; i++) { + try { + ids[i] = (T) ((Class)clazz).getConstructor(String.class).newInstance(idsStr[i]); + } catch (Exception e) { + } + } + return ids; + } + + protected void appendWhereClauseWithOperand(String parameter, String where, String namedParam, StringBuilder hql) { + QueryOperand operand = getOperand(parameter); + if (isListOperand(parameter)) { + appendWhereClause(where + " " + operand + " (:" + namedParam + ") ", hql); + } else { + appendWhereClause(where + " " + operand + " :" + namedParam + " ", hql); + } + } + + protected void applyParameterWithOperand(String parameter, String namedParam, Class clazz, Query query) { + if (isListOperand(parameter)) { + query.setParameterList(namedParam, transformToArray(parameter, clazz)); + } else { + query.setString(namedParam, parameter); + } + } + public void setCommandService(CommandService commandService) { this.commandService = commandService; } Index: modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java (revision 6403) +++ modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java (working copy) @@ -26,6 +26,7 @@ import java.util.List; import org.jbpm.api.JobQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.api.job.Job; import org.jbpm.test.JbpmTestCase; import org.jbpm.test.assertion.QueryAssertions; @@ -143,6 +144,38 @@ } + public void testProcessIdLike() { + startTestProcessInstances(6); + + JobQuery query = managementService.createJobQuery(); + assertEquals(6, query.processInstanceId("TimerQueryTest%", QueryOperand.LIKE).count()); + + } + + public void testProcessIdEquals() { + List procInstIds = startTestProcessInstances(6); + + JobQuery query = managementService.createJobQuery(); + assertEquals(1, query.processInstanceId(procInstIds.get(0), QueryOperand.EQUALS).count()); + + } + + public void testProcessIdIn() { + List procInstIds = startTestProcessInstances(6); + + JobQuery query = managementService.createJobQuery(); + assertEquals(2, query.processInstanceId(""+procInstIds.get(0)+","+procInstIds.get(1)+"", QueryOperand.IN).count()); + + } + + public void testProcessIdNotIn() { + List procInstIds = startTestProcessInstances(6); + + JobQuery query = managementService.createJobQuery(); + assertEquals(4, query.processInstanceId(""+procInstIds.get(0)+","+procInstIds.get(1)+"", QueryOperand.NOT_IN).count()); + + } + private List startTestProcessInstances(int nrOfInstances) { deployJpdlXmlString( "" + Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java (working copy) @@ -25,6 +25,7 @@ import java.util.List; import org.hibernate.Query; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryDetail; import org.jbpm.api.history.HistoryDetailQuery; import org.jbpm.pvm.internal.history.model.HistoryCommentImpl; @@ -34,6 +35,7 @@ /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class HistoryDetailQueryImpl extends AbstractQuery implements HistoryDetailQuery { @@ -54,15 +56,15 @@ hql.append(" as hd "); if (taskId!=null) { - appendWhereClause(" hd.historyTask.dbid = "+taskId+" ", hql); + appendWhereClauseWithOperand(taskId, "hd.historyTask.dbid", "taskId", hql); } if (processInstanceId!=null) { - appendWhereClause(" hd.historyProcessInstance.processInstanceId = '"+processInstanceId+"' ", hql); + appendWhereClauseWithOperand(processInstanceId, "hd.historyProcessInstance.processInstanceId", "processInstanceId", hql); } if (activityInstanceId!=null) { - appendWhereClause(" hd.historyActivityInstance.dbid = "+activityInstanceId+" ", hql); + appendWhereClauseWithOperand(activityInstanceId, "hd.historyActivityInstance.dbid", "activityInstanceId", hql); } if (timeBefore!=null) { @@ -86,6 +88,18 @@ if (timeBefore!=null) { query.setTime("timeBefore", timeBefore); } + + if (taskId!=null) { + applyParameterWithOperand(taskId, "taskId", Long.class, query); + } + + if (processInstanceId!=null) { + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); + } + + if (activityInstanceId!=null) { + applyParameterWithOperand(activityInstanceId, "activityInstanceId", Long.class, query); + } } public List list() { @@ -140,4 +154,25 @@ this.timeBefore = timeBefore; return this; } + + public HistoryDetailQuery activityInstanceId(String activityInstanceId, QueryOperand operand) { + this.activityInstanceId = activityInstanceId; + parameterOperands.put(activityInstanceId, operand); + + return this; + } + + public HistoryDetailQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + + return this; + } + + public HistoryDetailQuery taskId(String taskId, QueryOperand operand) { + this.taskId = taskId; + parameterOperands.put(taskId, operand); + + return this; + } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java (working copy) @@ -25,6 +25,7 @@ import org.hibernate.Query; import org.jbpm.api.JobQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.api.job.Job; import org.jbpm.pvm.internal.job.JobImpl; import org.jbpm.pvm.internal.job.MessageImpl; @@ -34,6 +35,7 @@ /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class JobQueryImpl extends AbstractQuery implements JobQuery { @@ -43,6 +45,8 @@ protected boolean timersOnly = false; protected String processInstanceId = null; protected Boolean exception; + + public String hql() { StringBuilder hql = new StringBuilder(); @@ -65,8 +69,9 @@ hql.append(" j "); if (processInstanceId!=null) { - appendWhereClause("j.processInstance.id = '"+processInstanceId+"' ", hql); - } + appendWhereClauseWithOperand(processInstanceId, "j.processInstance.id", "processInstanceId", hql); + } + if (exception!=null) { if (exception) { @@ -82,6 +87,9 @@ } protected void applyParameters(Query query) { + if (processInstanceId != null) { + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); + } } public List list() { @@ -126,4 +134,11 @@ this.processInstanceId = processInstanceId; return this; } + + public JobQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + + return this; + } } Index: modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java (revision 6403) +++ modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java (working copy) @@ -28,6 +28,7 @@ import org.jbpm.api.Deployment; import org.jbpm.api.DeploymentQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.test.JbpmTestCase; import org.jbpm.test.assertion.QueryAssertions; @@ -113,6 +114,42 @@ deleteCascade(deploymentIds); } + public void testEquals() { + List deploymentIds = deployTestProcesses(); + + assertEquals(1, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.EQUALS).count()); + + + deleteCascade(deploymentIds); + } + + public void testLike() { + List deploymentIds = deployTestProcesses(); + + assertEquals(1, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.LIKE).count()); + + + deleteCascade(deploymentIds); + } + + public void testIn() { + List deploymentIds = deployTestProcesses(); + + assertEquals(2, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0) + ","+deploymentIds.get(1), QueryOperand.IN).count()); + + + deleteCascade(deploymentIds); + } + + public void testNotIn() { + List deploymentIds = deployTestProcesses(); + + assertEquals(2, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.NOT_IN).count()); + + + deleteCascade(deploymentIds); + } + /* -------------- * HELPER METHODS * -------------- */ Index: modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java (revision 6403) +++ modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java (working copy) @@ -32,6 +32,7 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryTask; import org.jbpm.api.history.HistoryTaskQuery; import org.jbpm.pvm.internal.util.Clock; @@ -104,6 +105,75 @@ .taskId("-1").count()); } + public void testAssigneeLike() { + createTestHistoryTasks(); + + assertEquals(2, historyService.createHistoryTaskQuery().assignee("%o%", QueryOperand.LIKE).count()); + + } + + public void testAssigneeIn() { + createTestHistoryTasks(); + + assertEquals(2, historyService.createHistoryTaskQuery().assignee("Tom,Alex", QueryOperand.IN).count()); + + } + + public void testAssigneeNotIn() { + createTestHistoryTasks(); + + assertEquals(1, historyService.createHistoryTaskQuery().assignee("Tom,Alex", QueryOperand.NOT_IN).count()); + + } + + public void testTaskIdLike() { + createTestHistoryTasks(); + + assertEquals(3, historyService.createHistoryTaskQuery().taskId("%", QueryOperand.LIKE).count()); + + } + + public void testTaskIdIn() { + List taskIds = createTestHistoryTasks(); + + assertEquals(2, historyService.createHistoryTaskQuery().taskId(taskIds.get(0) + "," + taskIds.get(1), QueryOperand.IN).count()); + + } + + public void testTaskIdNotIn() { + List taskIds = createTestHistoryTasks(); + + assertEquals(1, historyService.createHistoryTaskQuery().taskId(taskIds.get(0) + "," + taskIds.get(1), QueryOperand.NOT_IN).count()); + + } + + public void testExecutionIdLike() { + createTestHistoryTasks(); + + assertEquals(3, historyService.createHistoryTaskQuery().executionId("theProcess%", QueryOperand.LIKE).count()); + + } + public void testStateLike() { + createTestHistoryTasks(); + + assertEquals(3, historyService.createHistoryTaskQuery().state("%", QueryOperand.LIKE).count()); + + } + + public void testStateIn() { + createTestHistoryTasks(); + + assertEquals(3, historyService.createHistoryTaskQuery().state(HistoryTask.STATE_COMPLETED + "," + HistoryTask.STATE_OBSOLETE, QueryOperand.IN).count()); + + } + + public void testStateNotIn() { + createTestHistoryTasks(); + + assertEquals(0, historyService.createHistoryTaskQuery().state(HistoryTask.STATE_COMPLETED + "," + HistoryTask.STATE_OBSOLETE, QueryOperand.NOT_IN).count()); + + } + @SuppressWarnings("unchecked") private void testOrderBy(String property, List expectedValues, Integer expectedNrOfResults, boolean naturalOrderCheck) { Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java (revision 6479) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java (working copy) @@ -31,6 +31,7 @@ import org.jbpm.api.Deployment; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessDefinitionQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.pvm.internal.env.EnvironmentImpl; import org.jbpm.pvm.internal.model.ProcessDefinitionImpl; import org.jbpm.pvm.internal.repository.DeploymentImpl; @@ -51,6 +52,7 @@ * to get the properly initialized ProcessDefinitionImpl. * * @author Tom Baeyens + * @author Maciej Swiderski */ public class ProcessDefinitionQueryImpl extends AbstractQuery implements ProcessDefinitionQuery { @@ -126,24 +128,25 @@ appendWhereClause("versionProperty.deployment = deployment ", hql); if (id!=null) { - appendWhereClause("idProperty.stringValue = '"+id+"'", hql); + appendWhereClauseWithOperand(id, "idProperty.stringValue", "id", hql); } - if (nameLike!=null) { - appendWhereClause("idProperty.objectName like '"+nameLike+"' ", hql); - } - if (name!=null) { - appendWhereClause("idProperty.objectName = '"+name+"' ", hql); + appendWhereClauseWithOperand(name, "idProperty.objectName", "name", hql); } if (key!=null) { - appendWhereClause("keyProperty.stringValue = '"+key+"' ", hql); + appendWhereClauseWithOperand(key, "keyProperty.stringValue", "key", hql); } if (deploymentId!=null) { - appendWhereClause("idProperty.deployment.dbid = "+deploymentId+" ", hql); + appendWhereClauseWithOperand(deploymentId, "idProperty.deployment.dbid", "deploymentId", hql); } + + // @deprecated, should be used with operand + if (nameLike!=null) { + appendWhereClause("idProperty.objectName like '"+nameLike+"' ", hql); + } appendOrderByClause(hql); @@ -151,6 +154,22 @@ } protected void applyParameters(Query query) { + if (id != null) { + applyParameterWithOperand(id, "id", String.class, query); + } + + if (name != null) { + applyParameterWithOperand(name, "name", String.class, query); + } + + if (key != null) { + applyParameterWithOperand(key, "key", String.class, query); + } + + if (deploymentId != null) { + applyParameterWithOperand(deploymentId, "deploymentId", Long.class, query); + } + } public List list() { @@ -215,4 +234,32 @@ this.page = new Page(firstResult, maxResults); return this; } + + public ProcessDefinitionQuery deploymentId(String deploymentId, QueryOperand operand) { + this.deploymentId = deploymentId; + parameterOperands.put(deploymentId, operand); + + return this; + } + + public ProcessDefinitionQuery processDefinitionId(String processDefinitionId, QueryOperand operand) { + this.id = processDefinitionId; + parameterOperands.put(processDefinitionId, operand); + + return this; + } + + public ProcessDefinitionQuery processDefinitionKey(String key, QueryOperand operand) { + this.key = key; + parameterOperands.put(key, operand); + + return this; + } + + public ProcessDefinitionQuery processDefinitionName(String name, QueryOperand operand) { + this.name = name; + parameterOperands.put(name, operand); + + return this; + } } Index: modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java (revision 6555) +++ modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java (working copy) @@ -30,6 +30,7 @@ import java.util.List; import org.jbpm.api.ProcessDefinition; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryProcessInstance; import org.jbpm.api.history.HistoryProcessInstanceQuery; import org.jbpm.pvm.internal.util.Clock; @@ -86,7 +87,61 @@ .count()); } } + + public void testQueryByProcessInstanceIdLike() { + createTestHistoryProcessInstances(7); + assertEquals(7, historyService.createHistoryProcessInstanceQuery() + .processInstanceId("theProcess%", QueryOperand.LIKE) + .count()); + + } + + public void testQueryByProcessInstanceIdIn() { + List procInstIds = createTestHistoryProcessInstances(7); + + assertEquals(2, historyService.createHistoryProcessInstanceQuery() + .processInstanceId(procInstIds.get(0) + "," + procInstIds.get(1), QueryOperand.IN) + .count()); + + } + + public void testQueryByProcessInstanceIdNotIn() { + List procInstIds = createTestHistoryProcessInstances(7); + + assertEquals(5, historyService.createHistoryProcessInstanceQuery() + .processInstanceId(procInstIds.get(0) + "," + procInstIds.get(1), QueryOperand.NOT_IN) + .count()); + + } + + public void testQueryByProcessInstanceKeyLike() { + createTestHistoryProcessInstances(7); + + assertEquals(7, historyService.createHistoryProcessInstanceQuery() + .processInstanceKey("theProcess-%", QueryOperand.LIKE) + .count()); + + } + + public void testQueryByProcessInstanceKeyIn() { + createTestHistoryProcessInstances(7); + + assertEquals(2, historyService.createHistoryProcessInstanceQuery() + .processInstanceKey("theProcess-1,theProcess-5", QueryOperand.IN) + .count()); + + } + + public void testQueryByProcessInstanceKeyNotIn() { + createTestHistoryProcessInstances(7); + + assertEquals(4, historyService.createHistoryProcessInstanceQuery() + .processInstanceKey("theProcess-1,theProcess-5,theProcess-6", QueryOperand.NOT_IN) + .count()); + + } + public void testOrderByStartTime() { testOrderByNaturalOrdening(HistoryProcessInstanceQuery.PROPERTY_STARTTIME, 4); } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java (working copy) @@ -26,12 +26,14 @@ import org.hibernate.Query; import org.jbpm.api.Deployment; import org.jbpm.api.DeploymentQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.pvm.internal.repository.DeploymentImpl; import org.jbpm.pvm.internal.util.CollectionUtil; /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class DeploymentQueryImpl extends AbstractQuery implements DeploymentQuery { @@ -53,7 +55,7 @@ hql.append(" as d "); if (deploymentId!=null) { - appendWhereClause("d.dbid = "+deploymentId+" ", hql); + appendWhereClauseWithOperand(deploymentId, "d.dbid", "deploymentId", hql); } if (suspended!=null) { @@ -70,6 +72,10 @@ } protected void applyParameters(Query query) { + + if (deploymentId != null) { + applyParameterWithOperand(deploymentId, "deploymentId", Long.class, query); + } } public DeploymentQuery deploymentId(String deploymentId) { @@ -109,4 +115,10 @@ public Deployment uniqueResult() { return (Deployment) untypedUniqueResult(); } + + public DeploymentQuery deploymentId(String id, QueryOperand operand) { + this.deploymentId = id; + parameterOperands.put(id, operand); + return this; + } } Index: modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java (revision 6403) +++ modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java (working copy) @@ -25,6 +25,7 @@ import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessDefinitionQuery; +import org.jbpm.api.QueryOperand; import org.jbpm.test.JbpmTestCase; @@ -135,4 +136,127 @@ assertEquals("make_friends-3", processDefinitions.get(2).getId()); assertEquals("make_print-1", processDefinitions.get(3).getId()); } + + public void testQueryProcessDefinitionsLike() { + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + List processDefinitions = + repositoryService.createProcessDefinitionQuery().processDefinitionName("%make%", QueryOperand.LIKE) + .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME) + .list(); + + assertEquals("fix coffeemaker", processDefinitions.get(0).getName()); + assertEquals("make friends", processDefinitions.get(1).getName()); + assertEquals("make print", processDefinitions.get(2).getName()); + } + + public void testQueryProcessDefinitionsIn() { + String dbId1 = deployJpdlXmlString( + "" + + " " + + "" + ); + + String dbId2 = deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery(); + List processDefinitions = + query.deploymentId(dbId1+","+dbId2, QueryOperand.IN) + .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME) + .list(); + + assertEquals(2, processDefinitions.size()); + + } + + public void testQueryProcessDefinitionsNotIn() { + String dbId1 = deployJpdlXmlString( + "" + + " " + + "" + ); + + String dbId2 = deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + deployJpdlXmlString( + "" + + " " + + "" + ); + + + List processDefinitions = + repositoryService.createProcessDefinitionQuery().deploymentId(dbId1+","+dbId2, QueryOperand.NOT_IN) + .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME) + .list(); + + assertEquals(3, processDefinitions.size()); + + } } Index: modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java (working copy) @@ -24,10 +24,13 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; + /** query for {@link HistoryActivityInstance activity occurrences}. * * @author Tom Baeyens + * @author Maciej Swiderski */ public interface HistoryActivityInstanceQuery { @@ -50,7 +53,16 @@ /** only select activity instances for the given process instance id */ HistoryActivityInstanceQuery processInstanceId(String processInstanceId); + + /** only select activity instances for the given process definition, allows to specify query operand */ + HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand); + /** only select activity instances for the given execution, allows to specify query operand */ + HistoryActivityInstanceQuery executionId(String executionId, QueryOperand operand); + + /** only select activity instances for the given process instance id, allows to specify query operand */ + HistoryActivityInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand); + /** only select activity instances started after the given time */ HistoryActivityInstanceQuery startedAfter(Date time); @@ -60,6 +72,10 @@ /** only select activity instances for the given activity * (this usually used in combination with {@link #processDefinitionId(String)}) */ HistoryActivityInstanceQuery activityName(String activityName); + + /** only select activity instances for the given activity, allows to specify query operand + * (this usually used in combination with {@link #processDefinitionId(String)}) */ + HistoryActivityInstanceQuery activityName(String activityName, QueryOperand operand); /** only select activity instances that took longer then the given duration in milliseconds */ HistoryActivityInstanceQuery tookLongerThen(long durationInMillis); Index: modules/api/src/main/java/org/jbpm/api/QueryOperand.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/QueryOperand.java (revision 0) +++ modules/api/src/main/java/org/jbpm/api/QueryOperand.java (revision 0) @@ -0,0 +1,26 @@ +package org.jbpm.api; + + +public enum QueryOperand { + + EQUALS(0, "="), + LIKE(1, "like"), + IN(2, "in"), + NOT_IN(3, "not in"); + + @SuppressWarnings("unused") + private int id; + private String value; + + QueryOperand(int id, String value) { + this.id = id; + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + +} Property changes on: modules\api\src\main\java\org\jbpm\api\QueryOperand.java ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + LF Index: modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java (working copy) @@ -45,7 +45,16 @@ /** select only specific process instances using a business key */ ProcessInstanceQuery processInstanceKey(String processInstanceKey); + + /** select only process instances for the given process definition, allows to specify query operand */ + ProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand); + /** select only a specific process instances using the process instance id, allows to specify query operand */ + ProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand); + + /** select only specific process instances using a business key, allows to specify query operand */ + ProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand); + /** select only suspended process definitions */ ProcessInstanceQuery suspended(); @@ -69,4 +78,5 @@ /** execute a count(*) query and returns number of results */ long count(); + } Index: modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java (working copy) @@ -24,11 +24,14 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; + /** query for ongoing and finished * {@linkplain HistoryProcessInstance process instances}. * * @author Tom Baeyens + * @author Maciej Swiderski */ public interface HistoryProcessInstanceQuery { @@ -56,7 +59,19 @@ /** select only process instances in the given state */ HistoryProcessInstanceQuery state(String state); + + /** select only the process instances with the given id, allows to specify query operand */ + HistoryProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand); + /** select only process instances with the given process definition, allows to specify query operand */ + HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand); + + /** select only process instances with the given business key, allows to specify query operand */ + HistoryProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand); + + /** select only process instances in the given state, allows to specify query operand */ + HistoryProcessInstanceQuery state(String state, QueryOperand operand); + /** order selected process instances ascending for certain {@link #PROPERTY_STARTTIME properties} */ HistoryProcessInstanceQuery orderAsc(String property); Index: modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java (revision 6420) +++ modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java (working copy) @@ -30,6 +30,7 @@ import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessInstance; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryActivityInstance; import org.jbpm.api.history.HistoryActivityInstanceQuery; import org.jbpm.pvm.internal.util.Clock; @@ -104,6 +105,79 @@ assertEquals(1, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(3)).list().size()); } + public void testQueryByExecutionIdLike() { + deployStartAndSignalTestProcesses(); + + assertEquals(9, historyService.createHistoryActivityInstanceQuery().executionId("abc%", QueryOperand.LIKE).list().size()); + + } + + public void testQueryByExecutionIdIn() { + List ids = deployStartAndSignalTestProcesses(); + + assertEquals(6, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0) + "," + ids.get(1), QueryOperand.IN).list().size()); + + } + + public void testQueryByExecutionIdNotIn() { + List ids = deployStartAndSignalTestProcesses(); + + assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0) + "," + ids.get(1), QueryOperand.NOT_IN).list().size()); + + } + + public void testQueryByProcessInstanceIdLike() { + deployStartAndSignalTestProcesses(); + + assertEquals(9, historyService.createHistoryActivityInstanceQuery().processInstanceId("abc%", QueryOperand.LIKE).list().size()); + + } + + public void testQueryByProcessInstanceIdIn() { + List ids = deployStartAndSignalTestProcesses(); + + assertEquals(6, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + ids.get(1), QueryOperand.IN).list().size()); + + } + + public void testQueryByProcessInstanceIdNotIn() { + List ids = deployStartAndSignalTestProcesses(); + + assertEquals(3, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + ids.get(1), QueryOperand.NOT_IN).list().size()); + + } + + public void testQueryByProcessDefinitionIdLike() { + deployStartAndSignalTestProcesses(); + deployTestProcessWithTask(); + generateHistoryForTestProcessWithTask(); + deployTestProcessWithTask(); + + assertEquals(12, historyService.createHistoryActivityInstanceQuery().processInstanceId("abc%", QueryOperand.LIKE).list().size()); + + } + + public void testQueryByProcessDefinitionIdIn() { + deployStartAndSignalTestProcesses(); + deployTestProcessWithTask(); + List idsTask = generateHistoryForTestProcessWithTask(); + List ids = deployStartAndSignalTestProcesses(); + + + assertEquals(6, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + idsTask.get(0), QueryOperand.IN).list().size()); + + } + + public void testQueryByProcessDefinitionIdNotIn() { + deployStartAndSignalTestProcesses(); + deployTestProcessWithTask(); + List idsTask = generateHistoryForTestProcessWithTask(); + List ids = deployStartAndSignalTestProcesses(); + + assertEquals(15, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + idsTask.get(0), QueryOperand.NOT_IN).list().size()); + + } + // Currently only verifies the size of the result set public void testQueryByStartedAfter() { deployTestProcess(); @@ -146,6 +220,24 @@ assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("c").list().size()); } + public void testQueryByActivityNameLike() { + deployStartAndSignalTestProcesses(); + assertEquals(9, historyService.createHistoryActivityInstanceQuery().activityName("%", QueryOperand.LIKE).list().size()); + + } + + public void testQueryByActivityNameIn() { + deployStartAndSignalTestProcesses(); + assertEquals(6, historyService.createHistoryActivityInstanceQuery().activityName("a,c", QueryOperand.IN).list().size()); + + } + + public void testQueryByActivityNameNotIn() { + deployStartAndSignalTestProcesses(); + assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("a,b", QueryOperand.NOT_IN).list().size()); + + } + //Currently only verifies the size of the result set public void testQueryByTookLessThen() { deployStartAndSignalTestProcesses(); Index: modules/api/src/main/java/org/jbpm/api/JobQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/JobQuery.java (revision 6478) +++ modules/api/src/main/java/org/jbpm/api/JobQuery.java (working copy) @@ -49,6 +49,9 @@ /** only select jobs related to the given process instance */ JobQuery processInstanceId(String processInstanceId); + + /** only select jobs related to the given process instance, allows to specify query operand*/ + JobQuery processInstanceId(String processInstanceId, QueryOperand operand); /** only select jobs that were rolled back due to an exception */ JobQuery exception(boolean hasException); Index: modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java (working copy) @@ -35,6 +35,9 @@ /** only include a specific deployment by id */ DeploymentQuery deploymentId(String id); + /** only include a specific deployment by id allows to specify query operand*/ + DeploymentQuery deploymentId(String id, QueryOperand operand); + /** only select suspended deployments */ DeploymentQuery suspended(); @@ -60,4 +63,5 @@ /** execute a count(*) query and returns number of results */ long count(); + } Index: modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java (revision 6403) +++ modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java (working copy) @@ -24,10 +24,13 @@ import java.util.Date; import java.util.List; +import org.jbpm.api.QueryOperand; + /** query for history tasks. * * @author Tom Baeyens + * @author Maciej Swiderski */ public interface HistoryTaskQuery { @@ -59,9 +62,24 @@ /** only select history tasks in the given state */ HistoryTaskQuery state(String state); + + /** only select the history task for the given id, allows to specify query operand */ + HistoryTaskQuery taskId(String taskId, QueryOperand operand); + + /** only select history tasks within the given execution, allows to specify query operand */ + HistoryTaskQuery executionId(String executionId, QueryOperand operand); + + /** only select history tasks for the given assignee, allows to specify query operand */ + HistoryTaskQuery assignee(String assignee, QueryOperand operand); + /** only select history tasks in the given state, allows to specify query operand */ + HistoryTaskQuery state(String state, QueryOperand operand); + /** only select history tasks that have the given outcome */ HistoryTaskQuery outcome(String outcome); + + /** only select history tasks that have the given outcome, allows to specify query operand */ + HistoryTaskQuery outcome(String outcome, QueryOperand operand); /** order selected history tasks ascending for certain {@link #PROPERTY_ID properties} */ HistoryTaskQuery orderAsc(String property); Index: modules/api/src/main/java/org/jbpm/api/TaskQuery.java =================================================================== --- modules/api/src/main/java/org/jbpm/api/TaskQuery.java (revision 6478) +++ modules/api/src/main/java/org/jbpm/api/TaskQuery.java (working copy) @@ -70,7 +70,26 @@ /** only select tasks that are associated to the given activity name. This * can be used in combination with the {@link #processDefinitionId(String)} */ TaskQuery activityName(String activityName); + + /** only query for tasks for which the given user is a candidate, allows to specify query operand. + * The user could be associated directly as a candidate participant + * to the task or the user could be a member of a group that is + * associated as a candidate group to the task. */ + TaskQuery assignee(String userId, QueryOperand operand); + + /** only select tasks that are associated to the given execution, allows to specify query operand */ + TaskQuery executionId(String executionId, QueryOperand operand); + /** only select tasks that are associated to the given process instance, allows to specify query operand */ + TaskQuery processInstanceId(String processInstanceId, QueryOperand operand); + + /** only select tasks that are associated to the given process definition, allows to specify query operand */ + TaskQuery processDefinitionId(String processDefinitionId, QueryOperand operand); + + /** only select tasks that are associated to the given activity name, allows to specify query operand. This + * can be used in combination with the {@link #processDefinitionId(String)} */ + TaskQuery activityName(String activityName, QueryOperand operand); + /** only select suspended tasks */ TaskQuery suspended(); @@ -94,4 +113,5 @@ /** execute the query and obtain the unique {@link Task} */ Task uniqueResult(); + } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java (revision 6555) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java (working copy) @@ -30,6 +30,7 @@ import org.hibernate.Session; import org.jbpm.api.JbpmException; +import org.jbpm.api.QueryOperand; import org.jbpm.api.TaskQuery; import org.jbpm.api.identity.Group; import org.jbpm.api.task.Task; @@ -45,6 +46,7 @@ * @author Tom Baeyens * @author Heiko Braun * @author Huisheng Xu + * @author Maciej Swiderski */ public class TaskQueryImpl extends AbstractQuery implements TaskQuery { @@ -134,7 +136,7 @@ if (log.isDebugEnabled()) { log.debug("setting parameter assignee: " + assignee); } - query.setString("assignee", assignee); + applyParameterWithOperand(assignee, "assignee", String.class, query); } // canidate parameter @@ -157,28 +159,28 @@ if (log.isDebugEnabled()) { log.debug("setting parameter executionId: " + executionId); } - query.setString("executionId", executionId); + applyParameterWithOperand(executionId, "executionId", String.class, query); } if (processInstanceId != null) { if (log.isDebugEnabled()) { log.debug("setting parameter processInstanceId: " + processInstanceId); } - query.setString("processInstanceId", processInstanceId); + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); } if (activityName != null) { if (log.isDebugEnabled()) { log.debug("setting parameter activityName: " + activityName); } - query.setString("activityName", activityName ); + applyParameterWithOperand(activityName, "activityName", String.class, query); } if (processDefinitionId != null) { if (log.isDebugEnabled()) { log.debug("setting parameter processDefinitionId: " + processDefinitionId); } - query.setString("processDefinitionId", processDefinitionId); + applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query); } } @@ -235,23 +237,23 @@ } if (executionId != null) { - appendWhereClause("task.execution.id = :executionId ", hql); + appendWhereClauseWithOperand(executionId, "task.execution.id", "executionId", hql); } if (processInstanceId != null) { - appendWhereClause("task.processInstance.id = :processInstanceId ", hql); + appendWhereClauseWithOperand(processInstanceId, "task.processInstance.id", "processInstanceId", hql); } if (activityName != null) { - appendWhereClause("task.execution.activityName = :activityName ", hql); + appendWhereClauseWithOperand(activityName, "task.execution.activityName", "activityName", hql); } if (processDefinitionId != null) { - appendWhereClause("task.processInstance.processDefinitionId = :processDefinitionId ", hql); + appendWhereClauseWithOperand(processDefinitionId, "task.processInstance.processDefinitionId", "processDefinitionId", hql); } if (assignee != null) { - appendWhereClause("task.assignee = :assignee ", hql); + appendWhereClauseWithOperand(assignee, "task.assignee", "assignee", hql); } else if (unassigned) { appendWhereClause("task.assignee is null ", hql); } @@ -296,4 +298,39 @@ public Task uniqueResult() { return (Task) untypedUniqueResult(); } + + public TaskQuery activityName(String activityName, QueryOperand operand) { + this.activityName = activityName; + parameterOperands.put(activityName, operand); + + return this; + } + + public TaskQuery assignee(String userId, QueryOperand operand) { + this.assignee = userId; + parameterOperands.put(userId, operand); + + return this; + } + + public TaskQuery executionId(String executionId, QueryOperand operand) { + this.executionId = executionId; + parameterOperands.put(executionId, operand); + + return this; + } + + public TaskQuery processDefinitionId(String processDefinitionId, QueryOperand operand) { + this.processDefinitionId = processDefinitionId; + parameterOperands.put(processDefinitionId, operand); + + return this; + } + + public TaskQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + + return this; + } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java (working copy) @@ -25,6 +25,7 @@ import java.util.List; import org.hibernate.Query; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryProcessInstance; import org.jbpm.api.history.HistoryProcessInstanceQuery; import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl; @@ -33,6 +34,7 @@ /** * @author Tom Baeyens * @author Alejandro Guizar + * @author Maciej Swiderski */ public class HistoryProcessInstanceQueryImpl extends AbstractQuery implements HistoryProcessInstanceQuery { @@ -62,19 +64,19 @@ hql.append(" as hpi "); if (processInstanceId!=null) { - appendWhereClause(" hpi.processInstanceId = '"+processInstanceId+"' ", hql); + appendWhereClauseWithOperand(processInstanceId, "hpi.processInstanceId", "processInstanceId", hql); } if (processDefinitionId!=null) { - appendWhereClause(" hpi.processDefinitionId = '"+processDefinitionId+"' ", hql); + appendWhereClauseWithOperand(processDefinitionId, "hpi.processDefinitionId", "processDefinitionId", hql); } if (state!=null) { - appendWhereClause(" hpi.state = '"+state+"' ", hql); + appendWhereClauseWithOperand(state, "hpi.state", "state", hql); } if (processInstanceKey!=null) { - appendWhereClause(" hpi.key = '" + processInstanceKey + "'", hql); + appendWhereClauseWithOperand(processInstanceKey, "hpi.key", "processInstanceKey", hql); } if (ended) { @@ -99,6 +101,22 @@ if (endedAfter != null) { query.setTimestamp("after", endedAfter); } + + if (processInstanceId!=null) { + applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query); + } + + if (processDefinitionId!=null) { + applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query); + } + + if (state!=null) { + applyParameterWithOperand(state, "state", String.class, query); + } + + if (processInstanceKey!=null) { + applyParameterWithOperand(processInstanceKey, "processInstanceKey", String.class, query); + } } public List list() { @@ -167,4 +185,32 @@ ended = false; return this; } + + public HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) { + this.processDefinitionId = processDefinitionId; + parameterOperands.put(processDefinitionId, operand); + + return this; + } + + public HistoryProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) { + this.processInstanceId = processInstanceId; + parameterOperands.put(processInstanceId, operand); + + return this; + } + + public HistoryProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand) { + this.processInstanceKey = processInstanceKey; + parameterOperands.put(processInstanceKey, operand); + + return this; + } + + public HistoryProcessInstanceQuery state(String state, QueryOperand operand) { + this.state = state; + parameterOperands.put(state, operand); + + return this; + } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java (revision 6478) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java (working copy) @@ -26,6 +26,7 @@ import org.hibernate.Query; +import org.jbpm.api.QueryOperand; import org.jbpm.api.history.HistoryTask; import org.jbpm.api.history.HistoryTaskQuery; import org.jbpm.pvm.internal.history.model.HistoryTaskImpl; @@ -33,6 +34,7 @@ /** * @author Tom Baeyens + * @author Maciej Swiderski */ public class HistoryTaskQueryImpl extends AbstractQuery implements HistoryTaskQuery { @@ -61,23 +63,23 @@ hql.append(" as ht "); if (taskId!=null) { - appendWhereClause(" ht.dbid = "+taskId+" ", hql); + appendWhereClauseWithOperand(taskId, "ht.dbid", "taskId", hql); } if (executionId!=null) { - appendWhereClause(" ht.executionId = '"+executionId+"' ", hql); + appendWhereClauseWithOperand(executionId, "ht.executionId", "executionId", hql); } if (assignee!=null) { - appendWhereClause(" ht.assignee = '"+assignee+"' ", hql); + appendWhereClauseWithOperand(assignee, "ht.assignee", "assignee", hql); } if (state!=null) { - appendWhereClause(" ht.state = '"+state+"' ", hql); + appendWhereClauseWithOperand(state, "ht.state", "state", hql); } if (outcome!=null) { - appendWhereClause(" ht.outcome = '"+outcome+"' ", hql); + appendWhereClauseWithOperand(outcome, "ht.outcome", "outcome", hql); } if (tookLessThen!=null) { @@ -117,6 +119,26 @@ if (startedAfter!=null) { query.setTimestamp("startedAfter", startedAfter); } + + if (taskId!=null) { + applyParameterWithOperand(taskId, "taskId", Long.class, query); + } + + if (executionId!=null) { + applyParameterWithOperand(executionId, "executionId", String.class, query); + } + + if (assignee!=null) { + applyParameterWithOperand(assignee, "assignee", String.class, query); + } + + if (state!=null) { + applyParameterWithOperand(state, "state", String.class, query); + } + + if (outcome!=null) { + applyParameterWithOperand(outcome, "outcome", String.class, query); + } } public List list() { @@ -186,4 +208,39 @@ this.tookLongerThen = durationInMillis; return this; } + + public HistoryTaskQuery assignee(String assignee, QueryOperand operand) { + this.assignee = assignee; + parameterOperands.put(assignee, operand); + + return this; + } + + public HistoryTaskQuery executionId(String executionId, QueryOperand operand) { + this.executionId = executionId; + parameterOperands.put(executionId, operand); + + return this; + } + + public HistoryTaskQuery state(String state, QueryOperand operand) { + this.state = state; + parameterOperands.put(state, operand); + + return this; + } + + public HistoryTaskQuery taskId(String taskId, QueryOperand operand) { + this.taskId = taskId; + parameterOperands.put(taskId, operand); + + return this; + } + + public HistoryTaskQuery outcome(String outcome, QueryOperand operand) { + this.outcome = outcome; + parameterOperands.put(outcome, operand); + + return this; + } }