zoukankan      html  css  js  c++  java
  • JBPM学习(五):流程变量

    1.启动流程实例

    // 启动流程实例
    @Test
    public void startProcessInstance() {
    	// 使用指定key的最新版本的流程定义启动流程实例
    	ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");
    	System.out.println("processInstanceId=" + pi.getId());
    }
    

      

    2.设置流程变量

    a) 一个设置流程变量实例

    //设置流程变量
    @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) 所有设置流程变量方法

    用到变量的类型:

    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>();
    

      具体方法:

    // 根据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) 一个获取流程变量实例

    //获取流程变量
    @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) 所有获取流程变量方法

    用到变量的类型:

    String executionId = "";
    String taskId = "";
    String variableName = "";
    Set<String> variableNames = new HashSet<String>();
    

      具体方法:

    // 根据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

    For persistence of these variable, the type of the variable is checked in the order of this list. The first match will determine how the variable is stored.

      

  • 相关阅读:
    黑板客爬虫闯关 代码
    新浪云SAE搭建python环境 问题拾遗
    关于python中的字符串编码理解
    linux环境中使用转义字符使命令行字符颜色高亮
    python中list作为全局变量无需global声明的原因
    获取youku视频下载链接(wireshark抓包分析)
    改变linux默认配色方案(dircolors和dircolors-solarized使用)
    限流常规设计和实例
    连接池-Mybatis源码
    Transaction-Mybatis源码
  • 原文地址:https://www.cnblogs.com/a757956132/p/4449603.html
Copyright © 2011-2022 走看看