Activiti process about custom SQL query, activitisql

Source: Internet
Author: User
Tags how to use sql

Activiti process about custom SQL query, activitisql

Because I was not familiar with Activiti, I was not familiar with the table structure. Even the entity classes corresponding to those tables were not clear, and I could not implement them through the chain query provided by Activiti; in this case, you do not know how to use SQL to implement the query you want. I have read a lot about Activiti on the Internet, and sometimes I read other people's information without knowing how to do it.

For example, I now need to make a process that has been done, and all the activiti users know that activiti will copy the task we are executing in the History table. If this task is completed, it will clear the data in the task table being executed so that the data end time in the History task table has a value. However, if the task being executed is not completed, we will use a piece of data in the History Table, if you present this data to users, the user experience will be poor.

Generally, we use a chain to query all the data in the History Table:

List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().taskAssignee(organid)                                            .orderByHistoricActivityInstanceStartTime().desc().listPage(pagin.getStartResult(), pagin.getPageSize());

In this way, the queried task list contains data with an empty end time. If it is displayed directly to the user, the user experience will be poor.

If I use the spelling SQL to query "END_TIME _ is not null", it is much simpler. But how should we write this SQL?

List<HistoricTaskInstance> tasks = historyService.createNativeHistoricTaskInstanceQuery()        .sql("select * from " + managementService.getTableName(HistoricTaskInstance.class)+" H where H.END_TIME_ is not null and H.ASSIGNEE_ like #{organid} order by H.END_TIME_ desc")        .parameter("organid", "%"+organid+"%")        .listPage(pagin.getStartResult(), pagin.getPageSize());

Code winning: 1. Find the class we need to use through the managementService interface and convert it to the corresponding table, in this case, we do not need to know who the table file corresponding to this object is.

2. I used fuzzy search to view others' posts on the Internet. I initially thought that activiti's fuzzy query is the same as other fuzzy queries, but after I tried it myself, it always indicates that the spelling of SQL statements is incorrect. It was found that the spelling of "%" was wrong. This thing needs to be spelled to the parameter side, rather than in the SQL statement.

 

 

Problem:As a matter of fact, I encountered a problem when I was doing my work. Although I used some tips to solve this problem later, however, I still want to know how activiti solves similar problems.

As there are many processes here, they have been used to separate different classification processes so that they can be distributed using different business actions. One attribute is required to differentiate them, therefore, the key of the process is defined as the class name of each business class (the class name cannot be repeated). The question is, how to obtain the ProcessDefinitionKey in a historical task?

Problem description:

If it is a to-do task, we can easilyProcessInstanceGet the ProcessDefinitionKey in the object (This field is the class name of the corresponding process business class), but in the handled items, this field isHistoricProcessInstanceThis object cannot be obtained. I don't know how to do it for colleagues who have used activiti.

Solution:

I store activiti like this: I set the BUSINESS_KEY (Class Name of the business class) when starting the process. business ID), because the key of my process is also the class name of the business class, so we can steal this lazy, of course, some people, this BUSINESS_KEY is the Business ID directly stored.

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.