现在使用xml作为数据描述语言已经非常普遍了,xml schema也成为了创建新的数据交换规范的最佳定义工具,通过xml schema定义的soa规范完整,易于理解,充分证明了schema的强大。
在这里我不想定义一套新的数据格式,只是想尝试用xml schema来描述事务操作,因为数据是有形的东西,描述起来相对容易,而事务处理是更加抽象的,实际开发中的很多精力都花在这个上面,如果能像数据重用那样减少这方面的工作量,也许能够有效提高生产率。
先来看看事务都做些什么吧!
事务的基本功能是“操作”,也就是“do something”。比如让某个人把一封信送到邮局,让财务会计统计一下这个月的收支等,一个大的操作可能需要包含很多小的操作,操作内部又涉及一些业务相关的逻辑,比如什么情况做什么操作,反复执行,甚至要执行某些错误处理等。
在操作的基础上,事务定义了四个属性ACID,acid就是:原子性(atomicity )、一致性( consistency )、隔离性( isolation)和持久性(durabilily)。由于这些属性涉及运行上下文,定义起来比较复杂,我们先考虑最基本的操作定义,但这也已经够我们烦恼的了。
|
<!--?xml version="1.0" encoding="UTF-8"?-->
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.inature.org/xmlns/pdl/1.0" xmlns:pdl="http://www.inature.org/xmlns/pdl/1.0" elementFormDefault="qualified">
<element name="transaction" type="pdl:transaction" /> <complexType name="transaction"> <sequence> <choice minOccurs="0" maxOccurs="unbounded"> <element name="execute" type="string" minOccurs="0" maxOccurs="unbounded" /> </choice> </sequence> </complexType> </schema>
|
上面的最简单的定义只说明了transaction由一系列的操作组成。但是事务中的操作就像我们普通程序流程一样需要控制,包括循环,分支,中途返回等。而对于操作execute,从面向对象的角度来看,也需要指明由哪个实例执行什么动作,同时需要给出动作发生的上下文,也就是参数。这样我们就有了下面的例子。注意其中的参数定义pdl:param还没有给出真正的定义。
|
<element name="execute" type="pdl:execute" /> <complexType name="execute"> <sequence> <element name="param" type="pdl:param" minOccurs="0" maxOccurs="unbounded" /> </sequence> <attribute name="role" type="string" use="required" /> <attribute name="action" type="string" use="required" /> </complexType>
<element name="transaction" type="pdl:transaction" /> <complexType name="transaction"> <sequence> <choice minOccurs="0" maxOccurs="unbounded"> <element name="execute" type="pdl:execute" minOccurs="0" maxOccurs="unbounded" /> <element name="if" type="pdl:block" minOccurs="0" maxOccurs="unbounded" /> <element name="loop" type="pdl:block" minOccurs="0" maxOccurs="unbounded" /> </choice> </sequence> </complexType> <element name="block" type="pdl:block" /> <complexType name="block"> <complexContent> <extension base="pdl:transaction"> <attribute name="condition" type="string" use="required" /> </extension> </complexContent> </complexType>
|