04-jbpm工作流执行变量Variable

java操作类:

package cn.edu.zust.itee;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.junit.Test;

import cn.edu.zust.itee.model.Form;

/**
 * @author 郑勇
 * 2013-07-09 22:14
 *  流程变量(操作表:jbpm4_variable)
 */
public class ProcessVariable {
	
	
	private ProcessEngine processEngine = Configuration.getProcessEngine();
	
	//启动流程实例
	//jbpm4_execution :正在执行的流程信息
	//jbpm4_hist_procinst :执行的历史信息
	@Test
	public void startProcessInstance(){
		//使用指定key的最新版本的流程定义启动流程实例
		String processDefinitionKey = "test";
		ProcessInstance pi =  processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey);
		System.out.println("processInstanceId="+pi.getId()+",key="+pi.getKey()+",name="+pi.getName()+",state="+pi.getState()+",processDefinitionId="+pi.getProcessDefinitionId());
	}
	
	@Test
	public void setVariable(){
		String executionId = "test.150001";
		String name = "请假天数";
		Object value = 2;
		
		Form form  = new Form();
		form.setId(1l);        //模拟hibernate中的游离状态的对象
		form.setName("张三");
		form.setDisc("请假3天");
		processEngine.getExecutionService().setVariable(executionId, "form", form);
		
	}
	
	@Test
	public void getVariable(){
		String executionId = "test.150001";
		String variableName = "请假天数";
	//	Integer days = (Integer) processEngine.getExecutionService().getVariable(executionId, variableName);
		Form form  = (Form) processEngine.getExecutionService().getVariable(executionId, "form");
//		System.out.println(variableName+"="+days);
		System.out.println(variableName+"="+form.getDisc());
	}
	
	//流程变量相关操作的API说明
    public void testVariables(){
		String executionId = "";
		String name = "";
		Object value = "";
		String taskId = "";
		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中)
    	processEngine.getTaskService().setVariables(taskId, variablesMap);
    
        //使用指定key的最新版本的流程定义启动流程实例,并设置一些流程变量
    	processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey, variablesMap);
    
    	//办理完指定的任务,并设置一些流程变量
    	processEngine.getTaskService().completeTask(taskId, variablesMap);
    	
    	
    	//======================================获取流程变量==========================================
    	
    	//根据Execution获取指定名称的一个流程变量
    	processEngine.getExecutionService().getVariable(executionId, variableName);
   
    	//根据Execution获取所有流程的变量名称
    	processEngine.getExecutionService().getVariableNames(executionId);
    	
    	//根据Execution获取指定名称的所有流程的变量
    	processEngine.getExecutionService().getVariables(executionId, variableNames);
  
    	//根据task获取
    	processEngine.getTaskService().getVariable(taskId, variableName);
    	
    	processEngine.getTaskService().getVariableNames(taskId);
    	
    	processEngine.getTaskService().getVariables(taskId, variableNames);
    	
    }
    
    /**
    * 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. 
     */
}

Form实体类的映射文件:Form.hbm.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
         "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="cn.edu.zust.itee.model" >
	<class name="Form" table="jbpm4_from" lazy="false">
		<id name="id" column="id">
			<generator class="native" />
		</id>
		<property name="name" column="name" />
		<property name="disc" column="disc" />
	</class>
</hibernate-mapping>


实体Form.java类:

package cn.edu.zust.itee.model;

public class Form {

	private String disc;
	private String name;
	private Long id;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getDisc() {
		return disc;
	}

	public void setDisc(String disc) {
		this.disc = disc;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值