Jbpm 流程变量

一、流程图:
这里写图片描述

二、设置与获取变量:

这里写图片描述

三、代码:

public class ProcessVariableTest {
private ProcessEngine processEngine = Configuration.getProcessEngine();

    //部署(添加)
    @Test
    public void deploy() throws Exception {
        String deployId = processEngine.getRepositoryService().createDeployment()
        .addResourceFromClasspath("state/testState.jpdl.xml")
        .addResourceFromClasspath("state/testState.png")
        .deploy();

        System.out.println("部署成功:deployId=="+deployId);
    }

    //启动流程实例
    @Test
    public void start() throws Exception {
        ProcessInstance processInstance = processEngine.getExecutionService().startProcessInstanceByKey("testState");
        System.out.println("启动成功:id=="+processInstance.getId() 
                + ", state=="+processInstance.getState() 
                + ",pid=="+processInstance.getProcessDefinitionId());
    }

    //设置变量
    //executionId==processInstance.getId()
    @Test
    public void setVariable() throws Exception {
        String executionId = "testState.140001";
        //processEngine.getExecutionService().setVariable(executionId, "请假天数", 12);
        Form form = new Form(1L, "我要请假,我是张三"); // 通过指定id来模拟一个游离状态的对象
        processEngine.getExecutionService().setVariable(executionId, "form", form);
    }
    //获取变量
    @Test
    public void getVariable() throws Exception {
        String executionId = "testState.140001";
        //Object variable = processEngine.getExecutionService().getVariable(executionId, "请假天数");
        //Integer days = (Integer) variable;
        //System.out.println("请假天数==" + days);

        Form form = (Form) processEngine.getExecutionService().getVariable(executionId, "form");
        System.out.println(form);
    }

    /**
    {
        ExecutionService executionService = processEngine.getExecutionService();
        TaskService taskService = processEngine.getTaskService();

        // ============ 设置变量 ========================
        executionService.setVariable(executionId, name, value); // 设置一个变量
        executionService.setVariables(executionId, variablesMap); // 设置多个变量
        taskService.setVariables(taskId, variables); // 设置多个变量

        executionService.startProcessInstanceByKey(processDefinitionKey, variablesMap); // 启动流程实例时,先设置一些变量
        taskService.completeTask(taskId, variablesMap); // 真正办理完任务前先设置一些变量


        // ============ 获取变量 ========================
        executionService.getVariable(executionId, variableName); // 获取一个变量
        executionService.getVariableNames(executionId); // 返回Set<String>,是所有变量的名称集合
        executionService.getVariables(executionId, variableNames); //获取多个变量,返回Map<String,Object>,表示指定名称的变量信息

        taskService.getVariable(taskId, variableName);
        taskService.getVariableNames(taskId);
        taskService.getVariables(taskId, variableNames);
    }
    */

}

四、实体类:

public class Form /* implements java.io.Serializable */{

    private Long id;
    private String title;

    // ...

    public Form() {
    }

    public Form(String title) {
        this.title = title;
    }

    public Form(Long id, String title) {
        this.id = id;
        this.title = title;
    }

    public Long getId() {
        return id;
    }

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

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "[Form: id=" + id + ", title=" + title + "]";
    }

}

五、配置文件

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

<hibernate-mapping package="com.itcast.processvariable">

    <class name="Form" table="itcast_form" lazy="false">
        <id name="id">
            <generator class="native"/>
        </id>
        <property name="title"/>
    </class>

</hibernate-mapping>

六、jbpm.hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>

     <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
     <property name="hibernate.connection.url">jdbc:mysql:///jbpm4?useUnicode=true&amp;characterEncoding=utf8</property>
     <property name="hibernate.connection.username">root</property>
     <property name="hibernate.connection.password">root</property>

     <property name="hibernate.hbm2ddl.auto">update</property>
     <property name="hibernate.show_sql">true</property>
     <property name="hibernate.current_session_context_class">thread</property>

     <mapping resource="jbpm.repository.hbm.xml" />
     <mapping resource="jbpm.execution.hbm.xml" />
     <mapping resource="jbpm.history.hbm.xml" />
     <mapping resource="jbpm.task.hbm.xml" />
     <mapping resource="jbpm.identity.hbm.xml" />

     <mapping resource="com/itcast/processvariable/Form.hbm.xml" />

  </session-factory>
</hibernate-configuration>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lovoo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值