diff --git a/modules/activiti-engine/src/main/java/org/activiti/engine/TaskService.java b/modules/activiti-engine/src/main/java/org/activiti/engine/TaskService.java index 86194b131e01e219a913c819e511a52f1014ab50..d7da8e740d753fab281baafcd38d0e88e4287acf 100644 --- a/modules/activiti-engine/src/main/java/org/activiti/engine/TaskService.java +++ b/modules/activiti-engine/src/main/java/org/activiti/engine/TaskService.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.activiti.engine.query.NativeQuery; import org.activiti.engine.task.Attachment; import org.activiti.engine.task.Comment; import org.activiti.engine.task.DelegationState; @@ -280,7 +281,7 @@ public interface TaskService { TaskQuery createTaskQuery(); /** - * Returns a new + * Returns a new {@link NativeQuery} for tasks. */ NativeTaskQuery createNativeTaskQuery(); diff --git a/modules/activiti-engine/src/test/java/org/activiti/engine/test/api/task/TaskQueryTest.java b/modules/activiti-engine/src/test/java/org/activiti/engine/test/api/task/TaskQueryTest.java index 838ba423dc47ee07952f2738dc0fd0047df6f9cd..b37f18c7101ff6ebac453a9c5f484f129c5c6681 100644 --- a/modules/activiti-engine/src/test/java/org/activiti/engine/test/api/task/TaskQueryTest.java +++ b/modules/activiti-engine/src/test/java/org/activiti/engine/test/api/task/TaskQueryTest.java @@ -899,8 +899,8 @@ public class TaskQueryTest extends PluggableActivitiTestCase { assertEquals(144, taskService.createNativeTaskQuery().sql("SELECT count(*) FROM ACT_RU_TASK T1, ACT_RU_TASK T2").count()); // join task and variable instances - assertEquals(1, taskService.createNativeTaskQuery().sql("SELECT count(*) FROM " + managementService.getTableName(Task.class) + " T1, "+managementService.getTableName(VariableInstanceEntity.class)+" V1 WHERE V1.TASK_ID_ = T1.ID_").count()); - List tasks = taskService.createNativeTaskQuery().sql("SELECT * FROM " + managementService.getTableName(Task.class) + " T1, "+managementService.getTableName(VariableInstanceEntity.class)+" V1 WHERE V1.TASK_ID_ = T1.ID_").list(); + assertEquals(1, taskService.createNativeTaskQuery().sql("SELECT count(*) FROM " + managementService.getTableName(Task.class) + " T1, " + managementService.getTableName(VariableInstanceEntity.class)+" V1 WHERE V1.TASK_ID_ = T1.ID_").count()); + List tasks = taskService.createNativeTaskQuery().sql("SELECT * FROM " + managementService.getTableName(Task.class) + " T1, " + managementService.getTableName(VariableInstanceEntity.class)+" V1 WHERE V1.TASK_ID_ = T1.ID_").list(); assertEquals(1, tasks.size()); assertEquals("gonzoTask", tasks.get(0).getName()); diff --git a/userguide/src/en/chapters/ch04-API.xml b/userguide/src/en/chapters/ch04-API.xml index 9fd9b05ce5410534187495b5682f5bf54486beaa..283fc9ba7f0accf20b1ee9b0b17dfce45f1cacbd 100644 --- a/userguide/src/en/chapters/ch04-API.xml +++ b/userguide/src/en/chapters/ch04-API.xml @@ -93,24 +93,24 @@ FormService formService = processEngine.getFormService(); currently is. Lastly, the RuntimeService is used whenever a process instance is waiting for an external trigger and the process needs to be continued. A process instance can have various wait states and this service contains - various operations to 'signal' the instance that the external trigger is received and the process instance can be continues. + various operations to 'signal' the instance that the external trigger is received and the process instance can be continued. - Task that need to be performed by actual human users of the system are core to a BPM engine such as Activiti. + Tasks that need to be performed by actual human users of the system are core to a BPM engine such as Activiti. Everything around tasks is grouped in the TaskService, such as Querying tasks assigned to users or groups - Creating new standalone tasks. This are tasks that are not related to a process instances. + Creating new standalone tasks. These are tasks that are not related to a process instances. Manipulating to which user a task is assigned or which users are in some way involved with the task. - Claiming and completing task. Claiming means that someone decided to be the assigee for the task, meaninung + Claiming and completing a task. Claiming means that someone decided to be the assigee for the task, meaning that this user will complete the task. Completing means 'doing the work of the tasks'. Typically this is filling in a form of sorts. @@ -118,7 +118,7 @@ FormService formService = processEngine.getFormService(); - The IdentityService is pretty simple. It allows the management (creation, update, deletion, querying, ...) + The IdentityService is pretty simple. It allows the management (creation, update, deletion, querying, ...) of groups and users. It is important to understand that Activiti actually doesn't do any checking on users at runtime. For example, a task could be assigned to any user, but the engine does not verify if that user is known to the system. This is because the Activiti engine can also used in conjunction with services such as ldap, active directory, etc. @@ -461,27 +461,20 @@ try { Sometimes you need more powerful queries, e.g. queries using an OR operator or restrictions you can not express using the Query API. For these cases, we introduced native queries, which allow you to write your own SQL queries. The return type is defined by the Query object you use - and the data is mapped into the correct objects, e.g. Tasks. Since the query will be fired at the database you have to + and the data is mapped into the correct objects, e.g. Task, ProcessInstance, Execution, etc.... Since the query will be fired at the database you have to use table and column names as they are defined in the database; this requires some knowledge about the internal data structure and it is recommended to use native queries with care. The table names can be retrieved via the API to keep the dependency as small as possible. List<Task> tasks = taskService.createNativeTaskQuery() - .from(managementService.getTableName(Task.class) + " WHERE NAME_ = #{taskName}") - .parameter("taskName", "gonzoTask").list(); + .sql("SELECT count(*) FROM " + managementService.getTableName(Task.class) + " T WHERE T.NAME_ = #{taskName}") + .parameter("taskName", "gonzoTask") + .list(); - List<Task> tasks = taskService.createNativeTaskQuery() - .from("ACT_RU_TASK") - .list(); - - List<Task> tasks = taskService.createNativeTaskQuery() - .select("DISTINCT T1.*") // default is "*", but can be overwritten if you need it - .from("ACT_RU_TASK T1, ACT_RU_TASK T2 WHERE T1.ID_ = T2.ID_") // okay, joining with ourselves doesn't make too much sense, agreed - .list(); - - List<Task> tasks = taskService.createNativeTaskQuery() - .from(managementService.getTableName(Task.class) + " TASK, " + managementService.getTableName(VariableInstanceEntity.class) + " var WHERE VAR.TASK_ID_ = TASK.ID_") - .list(); + long count = taskService.createNativeTaskQuery() + .sql("SELECT count(*) FROM " + managementService.getTableName(Task.class) + " T1, " + + managementService.getTableName(VariableInstanceEntity.class) + " V1 WHERE V1.TASK_ID_ = T1.ID_") + .count();