开发者

what kind of pattern for couchbase/membase use?

开发者 https://www.devze.com 2023-03-11 17:18 出处:网络
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.

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 kin开发者_运维百科d of design patterns?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号