ACTIVITI5 a custom query statement taskquery query condition query like query

Source: Internet
Author: User
Tags data structures stringbuffer
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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.