天天看點

SAP Hybris和ABAP Netweaver裡的DAO(Data access object)

DAO在Hybris裡的定義:

A DAO (Data Access Object) is an interface to the storage back end system. DAOs store and retrieve objects. You use DAOs to save, remove, and find models. DAOs are the place to put SQL or FlexibleSearch statements and nowhere else. This is to ensure further decoupling from the underlying storage facility. DAOs interact with services via models and with the database via FlexibleSearch and SQL statements.

确實這是一個common的concept, 就是對持久層的CRUD進行封裝,以實作上一層對持久層具體實作的解耦。

随便抽一個ABAP的DAO實作:

Hybris裡所有DAO實作的super class是hybris标準的架構DAO, 定義在如下namespace裡. 讨論都是一個DAO作為interface定義操作,

另一個default開頭的DAO提供default實作: 拼SQL然後call flexibile search.

這裡的flexible search就相當于ABAP的OPEN SQL, 把DB的access同具體的DB provider解耦。

runtime時具體用哪個DAO的實作,是在Spring的配置檔案裡注入的:

本文來自雲栖社群合作夥伴“汪子熙”,了解相關資訊可以關注微信公衆号"汪子熙"。