2015-05-20 62 views
1

訪問當前的流程實例變量信息我要上act_proc_in_桌子底下存儲在數據庫H2運行過程實例的所有信息。(如開始時間,結束時間,筆者..)從Camunda BPMN引擎

我在ExecutionListener方法(在實現JavaDelegate接口的類中)從我需要進一步轉發信息的位置開始。

我知道使用createExecutionQuery()方法的RuntimeService接口,但在所有示例中,我已經看到它似乎映射到某種實體類。我不明白。 對不起,但我是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"); 
 

 
} } 
 
    
+0

請格式化你的問題 –

+0

我希望這更可讀?對於那個很抱歉。 – Varda

回答

4

與Camunda BPM 7.2開始,你就可以使用該方法execution.getProcessEngineServices()來訪問engines services在Java委託類。使用HistoryService或RuntimeService創建(Historic-)ProcessInstanceQuery像

HistoryService historyService = execution.getProcessEngineServices().getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();

然後你就可以訪問該HistoricProcessInstance的信息。

請注意您正在通過這些服務查詢數據庫。在事務提交之前,當前事務中更改的數據不可通過服務使用。

+0

當我使用.singleResult()代碼引發異常。然後,我檢索列表中的數據(以檢查我是否檢索任何內容),而令人驚訝的是列表的大小爲0.我不知道這怎麼可能? – Varda

+1

這意味着該過程沒有被持久化到數據庫。您可能仍然處於第一筆交易中。參見[1]瞭解過程中的交易是什麼以及如何影響它們。 [1]:http://docs.camunda.org/7.2/guides/user-guide/#process-engine-transactions-in-processes – Hawky4s

+0

非常感謝,它通過將servicetask的asyncbefore的值更改爲true進行工作。 – Varda

相關問題