ofbiz ECA定义和使用

来源:互联网 发布:linux怎么退出vi 编辑:程序博客网 时间:2024/05/01 16:20

这里只讨论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中声明

0 0
原创粉丝点击