Flowable 6.6.0 BPMN用户指南 - 11 JPA - 11.3 用法(2~3)

Flowable 6.6.0 用户指南相关文档下载


《Flowable 6.6.0 BPMN用户指南》

1. 入门
2. 配置
3 The Flowable API
4 Flowable 6.6.0 BPMN用户指南 - (4)Spring集成
5 Spring Boot
6 部署
7 BPMN 2.0简介
8 BPMN 2.0的构造
9 表单(Forms)
10 流程实例迁移

11 JPA

11.1 要求
11.2 配置
11.3 用法


有关Flowable的更多文档,参见:

《Flowable文档大全》


11.3.2 查询JPA流程变量

You can query for ProcessInstances and Executions that have a certain JPA-entity as variable value. Note that only variableValueEquals(name, entity) is supported for JPA-Entities on ProcessInstanceQuery and ExecutionQuery. Methods variableValueNotEquals, variableValueGreaterThan, variableValueGreaterThanOrEqual, variableValueLessThan and variableValueLessThanOrEqual are unsupported and will throw an FlowableException when a JPA-Entity is passed as value.

您可以通过变量值查询具有特定JPA实体的ProcessInstances和Executions。注意,ProcessInstanceQuery和ExecutionQuery上的JPA实体只支持variableValueEquals(name, entity)。不支持variableValueNotEquals、variableValueGreaterThan、variableValueGreaterThanOrEqual、variableValueLessThan和variableValueLessThanOrEqual等方法,当JPA实体作为值传递时,将引发FlowableException。

ProcessInstance result = runtimeService.createProcessInstanceQuery()
.variableValueEquals("entityToQuery", entityToQuery).singleResult();

11.3.3 使用Sping Bean和JPA的复杂示例

A more advanced example, JPASpringTest, can be found in flowable-spring-examples. It describes the following simple use case:

JPASpringTest是一个更复杂的示例,可以在flowable-spring-examples中找到。它描述了以下简单的用例:

  • An existing Spring-bean which uses JPA entities already exists which allows for Loan Requests to be stored.
  • Using Flowable, we can use the existing entities, obtained through the existing bean, and use them as variable in our process. Process is defined in the following steps:
  • 存在一个Spring-bean,它使用已有的JPA实体,以保存Loan Requests。
  • 在Flowable中,我们可以使用现有实体(通过现有bean获取),并将它们用作流程中的变量。流程定义步骤如下:
    • Service task that creates a new LoanRequest, using the existing LoanRequestBean using variables received when starting the process (e.g. could come from a start form). The created entity is stored as a variable, using flowable:resultVariable which stores the expression result as a variable.
    • UserTask that allows a manager to review the request and approve/disapprove, which is stored as a boolean variable approvedByManager
    • ServiceTask that updates the loan request entity so the entity is in sync with the process.
    • Depending on the value of the entity property approved, an exclusive gateway is used to make a decision about what path to take next: When the request is approved, process ends, otherwise, an extra task will become available (Send rejection letter), so the customer can be notified manually by a rejection letter.
    • 创建新LanRequest的服务任务,使用现有的LanRequestBean,使用启动流程时接收到的变量(例如,可能来自启动表单)。使用flowable:resultVariable(它将表达式结果存储为变量),创建的实体存储为一个变量。
    • UserTask,允许经理审查请求并批准/不批准,它存储为布尔变量apprvedByManager
    • ServiceTask,更新贷款申请实体(loan request entity)以便实体与流程同步
    • 根据实体属性approved的值,使用一个独占网关来决定下一步要采取的路径:当请求被批准时,流程结束,否则,将有一个额外的任务可用(发送拒绝信,Send rejection letter),这样可以通过拒绝信手动通知客户。

Please note that the process doesn’t contain any forms, since it is only used in a unit test.
请注意,这个流程不包含任何表单,因为它只在单元测试中使用。
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<definitions id="taskAssigneeExample"
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:flowable="http://flowable.org/bpmn"
  targetNamespace="org.flowable.examples">

  <process id="LoanRequestProcess" name="Process creating and handling loan request">
    <startEvent id='theStart' />
    <sequenceFlow id='flow1' sourceRef='theStart' targetRef='createLoanRequest' />

    <serviceTask id='createLoanRequest' name='Create loan request'
      flowable:expression="${loanRequestBean.newLoanRequest(customerName, amount)}"
      flowable:resultVariable="loanRequest"/>
    <sequenceFlow id='flow2' sourceRef='createLoanRequest' targetRef='approveTask' />

    <userTask id="approveTask" name="Approve request" />
    <sequenceFlow id='flow3' sourceRef='approveTask' targetRef='approveOrDissaprove' />

    <serviceTask id='approveOrDissaprove' name='Store decision'
      flowable:expression="${loanRequest.setApproved(approvedByManager)}" />
    <sequenceFlow id='flow4' sourceRef='approveOrDissaprove' targetRef='exclusiveGw' />

    <exclusiveGateway id="exclusiveGw" name="Exclusive Gateway approval" />
    <sequenceFlow id="endFlow1" sourceRef="exclusiveGw" targetRef="theEnd">
      <conditionExpression xsi:type="tFormalExpression">${loanRequest.approved}</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="endFlow2" sourceRef="exclusiveGw" targetRef="sendRejectionLetter">
      <conditionExpression xsi:type="tFormalExpression">${!loanRequest.approved}</conditionExpression>
    </sequenceFlow>

    <userTask id="sendRejectionLetter" name="Send rejection letter" />
    <sequenceFlow id='flow5' sourceRef='sendRejectionLetter' targetRef='theOtherEnd' />

    <endEvent id='theEnd' />
    <endEvent id='theOtherEnd' />
  </process>

</definitions>

Although the example above is quite simple, it shows the power of using JPA combined with Spring and parametrized method-expressions. The process requires no custom Java code at all (except for the Spring-bean off course) and speeds up development drastically.

尽管上面的例子非常简单,但它展示了使用JPA与Spring和参数化方法表达式相结合的强大功能。这个过程根本不需要任何定制的Java代码(除了Spring-bean以外),从而大大加快了开发速度。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

月满闲庭

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

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

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

打赏作者

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

抵扣说明:

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

余额充值