我遇到了以下错误:
Datasource names for all the database tags within the cftransaction tag must be the same.
这来自以下代码:
transaction action="begin" {
try {
var data = {};
data.time = getTickCount();
addToLog("Persist", "Started persist operations");
doClientPersist();
cleanUp(arguments.importId);
addToLog("Persist", "Completed the persist operations successfully", ((getTickCount()-data.time)/1000));
return true;
} catch (any e) {
transactionRollback();
data.error = e;
}
}
该事务有效地将较低级别的方法包装在doClientPersist()
. 一个这样的调用,在我们的框架数据库抽象层的深处,从一个单独的数据源(比如说邮政编码数据源)获取(SELECTs)经度和纬度信息——这个数据源是严格只读的。
<cffunction name="getLatitudeAndLongitude" access="package" returntype="query" output="false">
<cfargument name="postcode" type="string" required="true" />
<cfset var qPostcode = ''/>
<cfquery name="qPostcode" datasource="postcodesDatasource">
SELECT
a.latitude,
a.longitude
FROM
postcodes AS a
WHERE
a.postcode = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#postcode#"/>
</cfquery>
<cfreturn qPostcode/>
</cffunction>
<cffunction name="getPostcodeCoordinates" access="public" returntype="struct" output="false">
<cfargument name="postcode" type="string" required="true"/>
<cfscript>
var data = {};
data.postcode = getFormattedPostcode(arguments.postcode);
data.valid = isValidPostcode(data.postcode);
data.coords = {};
if (data.valid) {
data.query = getLatitudeAndLongitude(data.postcode);
if (isQuery(data.query) && data.query.recordCount) {
data.coords["latitude"] = data.query["latitude"][1];
data.coords["longitude"] = data.query["longitude"][1];
} else if (data.valid == 2) {
/** No match, try short postcode (RECURSIVE) **/
data.coords = getPostcodeCoordinates(trim(left(data.postcode, len(data.postcode)-3)));
}
}
return data.coords;
</cfscript>
</cffunction>
阅读这个问题,文档说以下内容:
In a transaction block, you can write queries to more than one database, but you must commit or roll back a transaction to one database before writing a query to another.
不幸的是,如上所述,获取此邮政编码数据的代码与实际的持久化操作完全无关,因为它执行了一个无法更改的较低级别方法的网络,我无法在调用之前提交“顶级”事务远程数据源。
无论如何我可以在事务中包装“顶级”方法并且仍然可以调用“邮政编码”数据源 - 我们必须为每个客户端复制邮政编码信息是愚蠢的,但是操作必须是如果出现问题,则回滚。
提前致谢。