couchbase/membase 使用什么样的模式?
Dao 模式是关系数据库的经典模式。现在我需要实现一个 couchbase 层,我想知道什么是键/值访问的最佳设计模式。
您有关于这种设计模式的经验可以分享吗?
Dao pattern is a classic with relational database. Now i need to implement a couchbase tier, and I wonder what would be the best design pattern for key/value access.
Have you some experience to share about this kind of design patterns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 DAO 模式用于任何类型的持久存储机制,无论是关系数据库、文件系统、文本文档、Couchbase 等。DAO 层非常通用,它只做一件事:在运行时对象与持久存储对象之间进行转换同行。
因此,对于关系数据库,您的 DAO 层采用 Java 对象,将它们转换为表和行,并使用 SQL 将它们存储在数据库中;反之亦然。对于 Couchbase,您的 DAO 层将获取 Java 对象,将它们转换为 JSON 文档,并使用 HTTP 将它们存储在数据库中。相同的图案,只是细节不同。
DAO 模式的优势显而易见:如果明年出现一些令人惊叹的新存储机制,其性能是 Couchbase 的两倍,并且围绕 SQL 数据库运行,那么您需要更改的只是 DAO 层。应用程序的其余部分甚至不知道或不关心。
You can use the DAO pattern for any kind of persistent storage mechanism, be it relational database, filesystem, text document, Couchbase, etc. The DAO layer is very generic and it does only one thing: converts your runtime objects to and from their persisted counterparts.
So for a relational database, your DAO layer takes Java objects, converts them to tables and rows and stores them in the DB using SQL; and vice-versa. For Couchbase, your DAO layer would take Java objects, convert them to JSON documents, and store them in the DB using HTTP. Same pattern, just different details.
The advantage of the DAO pattern is then readily evident: if next year, some amazing new storage mechanism comes out that's twice as good as Couchbase and runs circles around SQL databases, all you need to change is your DAO layer. The rest of the application doesn't even know or care.