How to teach a Java EE app new NoSQL tricks

Sun dumped JavaEE Pet Store, but a bright developer modernized it, and we ported it to NoSQL with Couchbase

Java Blueprints were developed to show you design patterns in enterprise Java. The Java Pet Store was designed to demonstrate the quintessential Java 2 Enterprise Edition (J2EE) application. This was mainly in the heady days of EJB 1.1-2.1, which had many failed and defective technologies, including the now-dumped Container Managed Persistence.

Around the same time, Puff Daddy became P. Diddy, then dropped the "P" with the explanation that it was getting in between him and his fans. Likewise, J2EE dropped the "2" and became Java EE possibly for the same reason. Meanwhile, Sun abandoned the Pet Store business in 2007. But Antonio Goncalves recently picked the application back up and modernized it as the Pet Shop. It uses CDI and all Java EE's latest fixings and versions to demonstrate the "right way" to do a Java EE application. You can find the code for Goncalves's Pet Store on GitHub.

[ Know your Java? Test your skills in the Java IQ test. | Learn how to work smarter, not harder with InfoWorld's roundup of all the tips and trends programmers need to know in the Developers' Survival Guide. Download the PDF today! | Keep up with the latest developer news with InfoWorld's Developer World newsletter. ]

The opportunity: Port Pet Store to NoSQL

As frequently noted, I'm incredulous about the JavaEE programming model's continued relevance in the modern era. CDI is mainly a codification or "standardization" of Spring, assuming Oracle's blessing means "standardization" to you. The Spring Framework more or less won the programming model. Meanwhile, the traditional "there is only the RDBMS" thought pattern is a little less of a given now with the big data and NoSQL revolution in place. Moreover, in the era of consumerization of computing and the Web, the traditional transaction manager is less relevant. It is unlikely that a device (à la database) transaction is sufficient any longer to support consistency.

With Couchbase 2.0's recent release, it seemed to me the perfect time for my colleagues and I to try to port the Pet Store as a NoSQL application. What may surprise you is how little work it required. See for yourself in our extensive guide; you can find our code for this project on GitHub as well.

The example exposes a weakness of Java EE related to NoSQL in that we had to have a lot of direct to Couchbase API code to make it work. Ideally, we'd have used something more like Spring Data because Spring supports CDI. However, Spring Data does not yet support Couchbase 2.0 for more than caching. (Full support is in beta.)

This gave us a good chance to test drive Couchbase 2.0 with the Java Pet Store.

Couchbase 101: How it differs from what you're used to

At a high level, Couchbase is a combination of a back-end data store and a built-in, document-level cache. It provides auto-failover, auto-sharding, and automatic load balancing. Couchbase does not have the concepts of databases and tables. Instead, data isolation is achieved through buckets. Buckets are like a database, where users store documents with different schemas. Thus, in our new Pet Store application, we created one bucket called petstore where all the documents for the application reside.

1 2 3 4 Page
Join the discussion
Be the first to comment on this article. Our Commenting Policies