taskquery Query API
There are two ways to query data from the engine: Query API and native query. The query API provides a fully type-safe API. You can add many conditions to your query criteria (so conditions are combined with and) and precise sorting criteria. The following code shows an example:
list<task> tasks = Taskservice.createtaskquery ()
. Taskassignee ("Kermit")
. Processvariablev Alueequals ("OrderId", "0815")
. Orderbyduedate (). ASC ()
. List ();
Sometimes you need more powerful queries, such as conditions that use an OR condition or that cannot be implemented using the query API. At this point, we recommend native queries, which allow you to write your own SQL queries. The return type is determined by the query object you are using, and the data is mapped to the correct object. For example, tasks, process instances, execution, and so on. Because the query works on the database, you must use the table and column names defined in the database, which requires an understanding of internal data structures, so be sure to use native queries. Table names can be obtained through the API to minimize dependency on the database.
list<task> tasks = Taskservice.createnativetaskquery () . SQL ("Selec T * from "+ managementservice.gettablename (task.class) +" T WHERE t.name_ = #{taskname} ") . P
Arameter ("TaskName", "Gonzotask") . List (); Long Count = Taskservice.createnativetaskquery () . SQL ("SELECT COUNT (*) FR OM "+ managementservice.gettablename (task.class) +" T1, " + Manag Ementservice.gettablename (Variableinstanceentity.class) + "V1 WHERE V1.
Task_id_ = t1.id_ ") . Count ();
Example: stringbuffer wheresql = new StringBuffer (); string ua = "";
String ub= ""; if (formcode!=null) {
Wheresql.append ("and Fi.form_no=#{form_no}"); } if (this.username!=null) { & nbsp; ua = ", Pub_user_info u"; ub= "and Fi.creator=u.userid";//performance Considerations
wheresql.append (" and u.emp_name like #{username}"); } tasks = Taskservice & nbsp; .createnativetaskquery () .sql ("select * from" & nbsp; + managementservice.gettablename (task.class) + "T,flow _ru_info fi "+ua+" where T.proc_inst_id_=fi.processinstanceid "+ub+" and t.assignee_=#{UserID} " + Wheresql + "ORDER by t.create_time_ Desc" & nbsp; ) .parameter ("userid", User.getuserid ()) .parameter ("Form_no", FormCode) . Parameter ("UserName", username+ "%")//This puts the wildcard in. .list ();
You can also query this. This is the most flexible.
String sql = "SELECT * from" +manageservice.gettablename (historicactivityinstance.class) + "T WHERE t.proc_inst_id_ = '" + Processinstanceid+ "' and t.act_id_ = '" +actid+ "and rownum<=" +num+ "ORDER by T.start_time_ DESC";
Nativehistoricactivityinstancequery Nhpiq = Historyservice
. Createnativehistoricactivityinstancequery ()
. SQL (SQL);