[英]How to use Data Access Objects for serialized & relational database data access
I am developing a C++ domain model class library which should provide some facilities or a framework (ie interface classes etc) for writing/reading class instance data to/from both a binary file and a RDBMS. 我正在开发一个C ++域模型类库,该类库应提供一些工具或框架(即接口类等),用于向/从二进制文件和RDBMS写入/读取类实例数据。 The basis for this library is an application that uses a RDBMS, and there are several methods which instantiate a class by performing a sequence of database retrieve and update calls to fetch collections of member data.
该库的基础是使用RDBMS的应用程序,并且有几种方法可以通过执行一系列数据库检索和更新调用以获取成员数据的集合来实例化类。 The serialized data access has a different way of organizing its data, so I want the domain model to be completely ignorant of primary/foreign keys, IDs etc.
序列化的数据访问有一种不同的方式来组织其数据,因此我希望域模型完全不了解主键/外键,ID等。
To solve this problem, I consider using the Data Access Object (DAO) pattern, and would like to have some advice on the 'granularity', lifetime and use of DAO objects (in your replies, please note that I'll be using C++, not Java, and that the domain class cannot hold any ID/key info from the RDBMS or binary file store): 为了解决此问题,我考虑使用数据访问对象 (DAO)模式,并希望对DAO对象的“粒度”,生存期和使用提供一些建议(在您的答复中,请注意,我将使用C ++ ,而不是Java,并且该域类不能保存RDBMS或二进制文件存储中的任何ID /密钥信息):
Thanks for your help! 谢谢你的帮助!
I don't have a good solution for you, but I can tell you what I have, and some thoughts and experiences. 我没有适合您的解决方案,但是我可以告诉您我所拥有的以及一些想法和经验。 I have built something very similar, based on a model I had seen used before, as a C++ library.
我已经基于以前使用的模型(作为C ++库)构建了非常相似的东西。
Some thoughts, in no particular order: 一些想法,没有特别的顺序:
On top of the DAO classes I build more accessible classes which represent the data in my application, and may or may not map 1-1 to a DAO class. 在DAO类的顶部,我构建了更多可访问的类,这些类代表我的应用程序中的数据,并且可能(也可能不)将1-1映射到DAO类。 These are allowed to have any type of members and structure, are supposed to be what the app uses, and have methods to copy data to/from the DAO classes which underlie them.
它们被允许具有任何类型的成员和结构,被假定为应用程序所使用的成员,并具有将数据复制到作为基础的DAO类/从DAO类复制数据的方法。
Hope that helps. 希望能有所帮助。
I don't know the best implementation, but here's what I've seen done: 我不知道最好的实现,但是这是我已经看到的完成的事情:
Disclaimer: This is just what I've seen done. 免责声明:这就是我所看到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.