[英]Accessing current process instance variable information from Camunda BPMN engine
我希望將所有正在運行的流程實例的所有信息存儲在act_proc_in_表下的H2數據庫中(例如開始時間,結束時間,作者..)。
我在ExecutionListener方法(在實現JavaDelegate接口的類中)中,需要從那里進一步轉發信息。
我知道帶有RuntimeService接口的createExecutionQuery()方法,但是在所有示例中,我都看到它似乎已映射到某種實體類。 我不明白。 抱歉,但是我是Camunda BPM引擎的新手。
public class ProcessRequestDelegate implements JavaDelegate {
private final static Logger LOGGER = Logger.getLogger("LOAN-REQUESTS");
public void execute(DelegateExecution execution) throws Exception { LOGGER.info("Processing request by '"+execution.getVariable("customerId")+"'...");
System.out.println(execution.getVariable("amount"));
int Amount= ((Double) execution.getVariable("amount")).intValue(); System.out.println("Amountis"+Amount);
ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ResulstSet rs= runtimeService.createExecutionQuery("What to write here?");
while (rs.next()) {
String author=rs.getString("AUTHOR");
Date start = rs.getDate("START_TIME");
int sales = rs.getInt("SALES");
} }
從Camunda BPM 7.2開始,您可以使用方法execute.getProcessEngineServices()來訪問Java委托類中的引擎服務 。 使用HistoryService或RuntimeService可以創建一個(Historic-)ProcessInstanceQuery
HistoryService historyService = execution.getProcessEngineServices().getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
然后,您可以訪問HistoricProcessInstance上的信息。
請注意,您正在通過這些服務查詢數據庫。 在提交事務之前,當前事務中更改的數據無法通過服務獲得。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.