このガイドに従って、DSS の分散トランザクションをテストしています。
大丈夫です。addAccountToBank2 操作でエラーが発生したため、addAccountToBank1 サービス呼び出しがロールバックされました。このテストでは、2 つの操作が両方とも H2 DB に関係しています。
次に、別のテストを行います。
このテストでは、H2 DB の 1 つを MySQL DB に置き換えます。私の手順は次のとおりです。
- begin_boxcar 操作を実行します。
- MySQL DB にデータを挿入します。
- addToAccountBalanceInBank2 操作を実行し、「accountId」フィールドに「1」、「value」フィールドに「h200」の値を指定します。
- end_boxcar 操作を実行します。
- getAccountBalanceFromBank2 オペレーションを実行します。(残高は変更されません)
- MySQL DB のデータをクエリします。(挿入操作により変更されています)
MySQL DB でロールバックが発生しない理由がわかりません。また、DSS の分散トランザクションのロールバックにはどのような条件が必要ですか?
.dbs ファイルの内容:
<data enableBoxcarring="true" enableDTP="true" name="DTPSampleService" serviceNamespace="http://ws.wso2.org/dataservice/samples/dtp_sample">
<config id="H2DataSource1">
<property name="org.wso2.ws.dataservice.xa_datasource_class">org.h2.jdbcx.JdbcDataSource</property>
<property name="org.wso2.ws.dataservice.xa_datasource_properties">
<property name="URL">jdbc:h2:file:./samples/database/DATA_SERV_SAMP</property>
<property name="User">wso2ds</property>
<property name="Password">wso2ds</property>
</property>
</config>
<config id="H2DataSource2">
<property name="org.wso2.ws.dataservice.xa_datasource_class">org.h2.jdbcx.JdbcDataSource</property>
<property name="org.wso2.ws.dataservice.xa_datasource_properties">
<property name="URL">jdbc:h2:file:./samples/database/DATA_SERV_SAMP2</property>
<property name="User">wso2ds</property>
<property name="Password">wso2ds</property>
</property>
</config>
<config id="MySQL">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/customersdatabase</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">root123</property>
</config>
<config id="MySQL1">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://192.168.31.44:3306/guohtdb</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">root123</property>
</config>
<query id="addAccountToBank1Query" returnGeneratedKeys="true" useConfig="H2DataSource1">
<sql>insert into Accounts (balance) values (:balance)</sql>
<param defaultValue="0" name="balance" sqlType="DOUBLE"/>
<result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true">
<element column="1" name="ID" xsdType="integer"/>
</result>
</query>
<operation name="addAccountToBank1">
<call-query href="addAccountToBank1Query">
<with-param name="balance" query-param="balance"/>
</call-query>
</operation>
<query id="addToAccountBalanceInBank1Query" useConfig="H2DataSource1">
<sql>update Accounts set balance = balance + :value where accountId= :accountId</sql>
<param name="accountId" sqlType="INTEGER"/>
<param name="value" sqlType="DOUBLE">
<validateDoubleRange maximum="2000" minimum="-2000"/>
</param>
</query>
<operation name="addToAccountBalanceInBank1">
<call-query href="addToAccountBalanceInBank1Query">
<with-param name="accountId" query-param="accountId"/>
<with-param name="value" query-param="value"/>
</call-query>
</operation>
<query id="getAccountBalanceFromBank1Query" useConfig="H2DataSource1">
<sql>select balance from Accounts where accountId=:accountId</sql>
<param name="accountId" sqlType="INTEGER"/>
<result element="Balance">
<element column="balance" name="Value" xsdType="double"/>
</result>
</query>
<operation name="getAccountBalanceFromBank1">
<call-query href="getAccountBalanceFromBank1Query">
<with-param name="accountId" query-param="accountId"/>
</call-query>
</operation>
<query id="addAccountToBank2Query" returnGeneratedKeys="true" useConfig="H2DataSource2">
<sql>insert into Accounts (balance) values (:balance)</sql>
<param defaultValue="0" name="balance" sqlType="DOUBLE"/>
<result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true">
<element column="1" name="ID" xsdType="integer"/>
</result>
</query>
<operation disableStreaming="true" name="addAccountToBank2">
<call-query href="addAccountToBank2Query">
<with-param name="balance" query-param="balance"/>
</call-query>
</operation>
<query id="addToAccountBalanceInBank2Query" useConfig="H2DataSource2">
<sql>update Accounts set balance = balance + :value where accountId= :accountId</sql>
<param name="accountId" sqlType="INTEGER"/>
<param name="value" sqlType="DOUBLE">
<validateDoubleRange maximum="2000" minimum="-2000"/>
</param>
</query>
<operation name="addToAccountBalanceInBank2">
<call-query href="addToAccountBalanceInBank2Query">
<with-param name="accountId" query-param="accountId"/>
<with-param name="value" query-param="value"/>
</call-query>
</operation>
<query id="getAccountBalanceFromBank2Query" useConfig="H2DataSource2">
<sql>select balance from Accounts where accountId=:accountId</sql>
<param name="accountId" sqlType="INTEGER"/>
<result element="Balance">
<element column="balance" name="Value" xsdType="double"/>
</result>
</query>
<operation name="getAccountBalanceFromBank2">
<call-query href="getAccountBalanceFromBank2Query">
<with-param name="accountId" query-param="accountId"/>
</call-query>
</operation>
<query id="insert_customer_query" useConfig="MySQL">
<sql>INSERT INTO customer(NID,Name,customerID) VALUES(?,?,?)</sql>
<param name="NID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
<param name="Name" ordinal="2" paramType="SCALAR" sqlType="STRING" type="IN"/>
<param name="customerID" ordinal="3" paramType="SCALAR" sqlType="STRING" type="IN"/>
</query>
<operation name="insert_customer_operation">
<call-query href="insert_customer_query">
<with-param name="Name" query-param="Name"/>
<with-param name="customerID" query-param="customerID"/>
<with-param name="NID" query-param="NID"/>
</call-query>
</operation>
<query id="select_with_key_customer_query" useConfig="MySQL">
<sql>SELECT NID, Name, customerID FROM customer WHERE customerID=?</sql>
<param name="customerID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
<result element="customerCollection" rowName="customer">
<element column="NID" name="NID" xsdType="xs:string"/>
<element column="Name" name="Name" xsdType="xs:string"/>
<element column="customerID" name="customerID" xsdType="xs:string"/>
</result>
</query>
<operation name="select_with_key_customer_operation">
<call-query href="select_with_key_customer_query">
<with-param name="customerID" query-param="customerID"/>
</call-query>
</operation>
<query id="select_all_customer_query" useConfig="MySQL">
<sql>SELECT NID, Name, customerID FROM customer</sql>
<result element="customerCollection" rowName="customer">
<element column="NID" name="NID" xsdType="xs:string"/>
<element column="Name" name="Name" xsdType="xs:string"/>
<element column="customerID" name="customerID" xsdType="xs:string"/>
</result>
</query>
<operation name="select_all_customer_operation">
<call-query href="select_all_customer_query"/>
</operation>
<query id="insert_customer_query1" useConfig="MySQL1">
<sql>INSERT INTO user(NID,Name,customerID) VALUES(?,?,?)</sql>
<param name="NID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
<param name="Name" ordinal="2" paramType="SCALAR" sqlType="STRING" type="IN"/>
<param name="customerID" ordinal="3" paramType="SCALAR" sqlType="STRING" type="IN"/>
</query>
<operation name="insert_customer_operation1">
<call-query href="insert_customer_query1">
<with-param name="Name" query-param="Name"/>
<with-param name="customerID" query-param="customerID"/>
<with-param name="NID" query-param="NID"/>
</call-query>
</operation>
<query id="select_with_key_customer_query1" useConfig="MySQL1">
<sql>SELECT NID, Name, customerID FROM user WHERE customerID=?</sql>
<param name="customerID" ordinal="1" paramType="SCALAR" sqlType="STRING" type="IN"/>
<result element="customerCollection" rowName="user">
<element column="NID" name="NID" xsdType="xs:string"/>
<element column="Name" name="Name" xsdType="xs:string"/>
<element column="customerID" name="customerID" xsdType="xs:string"/>
</result>
</query>
<operation name="select_with_key_customer_operation1">
<call-query href="select_with_key_customer_query1">
<with-param name="customerID" query-param="customerID"/>
</call-query>
</operation>
<query id="select_all_customer_query1" useConfig="MySQL1">
<sql>SELECT NID, Name, customerID FROM user</sql>
<result element="customerCollection" rowName="user">
<element column="NID" name="NID" xsdType="xs:string"/>
<element column="Name" name="Name" xsdType="xs:string"/>
<element column="customerID" name="customerID" xsdType="xs:string"/>
</result>
</query>
<operation name="select_all_customer_operation1">
<call-query href="select_all_customer_query1"/>
</operation>
</data>