我已经编写了一个网关来从我的数据库中获取结果集。我如何将每一行存储在一个单独的 dao 中,以便我可以进一步操作每条记录?或者我可以直接访问结果集来获取记录吗?
这是我的网关(顺便说一句,我是否应该将 cfquery 中的条件逻辑写入扩展此网关的单独 cfc?)
<cfcomponent name="MaterialDao" hint="data access object" output="false">
<cffunction name="init" hint="constructor" access="public" output="false" returntype="MaterialDao">
<cfargument name="dsn" type="String" required="true" hint="datasource" />
<cfset variables.instance.dsn = arguments.dsn />
<cfreturn this />
</cffunction>
<cffunction name="readMaterial" hint="read" access="public" output="false" returntype="Query">
<cfargument name="district" type="String" />
<cfset var qReadMaterial = "" />
<cfquery name="qReadMaterial" datasource="#variables.instance.dsn#">
<cfif StructKeyExists(arguments,"district")>
SELECT A.NR, A.BEZ, D.BES, D.STA
<cfelse>
SELECT A.NR, A.BEZ
</cfif>
FROM DEK AS D INNER JOIN ART AS A
ON D.NR = A.NR
WHERE 0=0
<cfif StructKeyExists(arguments,"district")>
AND D.BEZ = #arguments.district#
</cfif>
ORDER BY A.BEZ
</cfquery>
<cfreturn qReadMaterial />
</cffunction>
</cfcomponent>
我已经阅读了很多文章,似乎对这个问题有不同的看法(DAO vs. Gateway,DAO & Gateway 等)。什么是最佳实践,专业人士会做什么?