ofbiz ECA定义和使用

本文详细介绍了ECA(EventConditionActions)规则结构的概念,包括事件(Event)、条件(Condition)和动作(Action),并解释了如何在服务调用过程中应用SECA和EECA。通过实例展示了如何配置和使用这些规则来实现自动化处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里只讨论what和how,no why ^_^

ECA

ECA(Event Condition Actions)是一个过程(process)的规则结构(the structure of rules)。Event是触发器,或者为什么规则会被调用;Condition检测是否要继续调用Action;Action导致最后结果的改变。一个简单的例子“如果我们出门,看一下是否下雨,如果下雨则带上雨伞”,这里“出门”是Event,“下雨”是Condition,“带伞”是Action。

ECA分两类:SEAs(Service Event Condition Actions)和EECAs(Entity Event Condition Actions)

SECAs

Event: 一个Service被调用

Condition:一个参数是否满足什么条件(optional)

Action:调用另外一个Service

SECAs默认被定义在servicedef目录下secas.xml中,eg:

<eca service="changeOrderStatus" event="commit"
run-on-error="false">
<condition field-name="statusId" operator="equals"
value="ORDER_CANCELLED"/>
<action service="releaseOrderPayments" mode="sync"/>
</eca>

当changeOrderStatus事务将要提交时,框架会做一个查询操作,看是否有针对该Event的任何ECAs被定义,如果有,继续看statusId是否等于ORDER_CANCELLED,,如果满足,则Service releaseOrderPayments 会被同步调用。

SECAs触发器(event):

auth----认证前

in-validate----IN parameter校验前

out-validate----OUT parameter校验前

invoke ----service 被调用前

commit----事务提交前

return---service返回前

global-commit

global-rollback

最后两个有点不同,如果service是事务的一部分,则它会在回滚后或提交(commit)两个阶段(phases(JTA implementation??))间被调用

两个特殊属性(default:false):

run-on-failure

run-on-error

如果设为true,无论failure或error,SECA都会继续执行。除了不回滚外,failure和error没什么区别

在使用SECA前,需要在service-resources中指定声明位置:

<service-resource type="eca" loader="main" location="servicedef/secas.xml"/>

而service-resource元素在ofbiz-componen.xml中声明


EECAs

Event:entity 上的一个操作,

Condition:一个参数是否满足什么条件(optional)

Action:将被调用的service

    EECAs一般和entity定义在同一个目录并命名为eecas.xml

<eca entity="Product" operation="create-store" event="return">
<condition field-name="autoCreateKeywords" operator="not-equals" value="N"/>
<action service="indexProductKeywords" mode="sync" value-attr="productInstance"/>
</eca>

该ECA保证一旦Product上任何creation或update操作被提交,只要这个记录的autoCreateKeywords域部位N,service indexProductKeywords建辉自动被同步调用

operations:

create

store

remove

find

create-store(create or store/update)

create-remove

store-remove

create-store-remove

any

events:

validate,run,cache-check,cache-put,cache-clear


在使用EECAs前,需要指定eca entity-resource位置:

<entity-resource type="eca" loader="main" location="entitydef/eecas.xml"/>

        而<entity-resource>在ofbiz-component.xml中声明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值