what kind of pattern for couchbase/membase use?
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.
精彩评论