JBPM学习(五):流程变量
1.啟動流程實例
?
[java]?view plaincopy
//?啟動流程實例??
@Test ??
public?void?startProcessInstance()?{??
????//?使用指定key的最新版本的流程定義啟動流程實例??
????ProcessInstance?pi?=?processEngine.getExecutionService().startProcessInstanceByKey("test");??
????System.out.println("processInstanceId="?+?pi.getId());??
}??
?
?
2.設置流程變量
a)?一個設置流程變量實例
?
[java]?view plaincopy
//設置流程變量??
@Test ??
public?void?setVariable()?{??
????String?executionId?=?"test.140001";??
????String?name?=?"請假天數";??
????Integer?value?=?3;??
??
????//將name為"請假天數",value=3的流程變量設置到executionId為test.140001的執行對象上??
????processEngine.getExecutionService().setVariable(executionId,?name,?value);??
}??
?
b)?所有設置流程變量方法
用到變量的類型:
?
[java]?view plaincopy
Object?value?=?"";??
String?executionId?=?"";??
String?taskId?=?"";??
String?name?=?"";??
String?processDefinitionKey?=?"";??
String?variableName?=?"";??
Set<String>?variableNames?=?new?HashSet<String>();??
Map<String,?Object>?variablesMap?=?new?HashMap<String,?Object>();??
?
具體方法:
?
[java]?view plaincopy
//?根據Execution設置一個流程變量??
processEngine.getExecutionService().setVariable(executionId,?name,?value);??
//?根據Execution設置多個流程變量(需要先把流程變量放到一個Map中)??
processEngine.getExecutionService().setVariables(executionId,?variablesMap);??
??
//?根據Task設置多個流程變量(需要先把流程變量放到一個Map中,通過Task方法,它會先找到它所屬的Execution然后設置流程變量)??
processEngine.getTaskService().setVariables(taskId,?variablesMap);??
??
//?使用指定key的最新版本的流程定義啟動流程實例,并設置一些流程變量??
processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey,?variablesMap);??
//?辦理完指定的任務,并設置一些流程變量??
processEngine.getTaskService().completeTask(taskId,?variablesMap);??
?
3.獲取流程變量
a)?一個獲取流程變量實例
?
[java]?view plaincopy
//獲取流程變量??
@Test ??
public?void?getVariable()?{??
????String?executionId?=?"test.140001";??
????String?variableName?=?"請假天數";??
??
????//從executionId為test.140001的執行對象上取出流程變量名為"請假天數"的流程變量的value??
????Integer?value?=?(Integer)?processEngine.getExecutionService().getVariable(executionId,?variableName);??
????System.out.println(variableName?+?"?=?"?+?value);??
}??
?
b)?所有獲取流程變量方法
用到變量的類型:
?
[java]?view plaincopy
String?executionId?=?"";??
String?taskId?=?"";??
String?variableName?=?"";??
Set<String>?variableNames?=?new?HashSet<String>();??
?
具體方法:
?
[java]?view plaincopy
//?根據Execution獲取指定名稱的一個流程變量??
processEngine.getExecutionService().getVariable(executionId,?variableName);??
//?根據Execution獲取所有流程變量的名稱??
processEngine.getExecutionService().getVariableNames(executionId);??
//?根據Execution獲取指定名稱的所有流程變量??
processEngine.getExecutionService().getVariables(executionId,?variableNames);??
??
//?根據Task獲取指定名稱的一個流程變量??
processEngine.getTaskService().getVariable(taskId,?variableName);??
//?根據Task獲取所有流程變量的名稱??
processEngine.getTaskService().getVariableNames(taskId);??
//?根據Task獲取指定名稱的所有流程變量??
processEngine.getTaskService().getVariables(taskId,?variableNames);??
?
4.流程變量所支持的值的類型(jBPM?User?Guide,7.2.?Variable?types)
jBPM?supports?following?Java?types?as?process?variables:
?
-
java.lang.String?
-
java.lang.Long?
-
java.lang.Double?
-
java.util.Date?
-
java.lang.Boolean?
-
java.lang.Character?
-
java.lang.Byte?
-
java.lang.Short?
-
java.lang.Integer?
-
java.lang.Float?
-
byte[]?(byte?array)?
-
char[]?(char?array)?
-
hibernate?entity?with?a?long?id?
-
hibernate?entity?with?a?string?id?
-
serializable
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的JBPM学习(五):流程变量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 事务概念
- 下一篇: javax.el.ELException