How to teach a Java EE app new NoSQL tricks

Lessons learned from porting Pet Shop to NoSQL via Couchbase 2.0

1 2 Page 2
Page 2 of 2

public Customer createCustomer(final Customer customer) {

if (customer == null) throw new ValidationException("Customer object is null");

// Sets the customerId to the current time in millis

customer.setId(String.valueOf(new Date().getTime()));

try {

// Puts the document into the database.

// Uses customer login as the key since this should be unique

// EXP_TIME, Expiry time in seconds is set to 0, which means store forever.

// Uses the Jackson mapper to conver the customer to json

client.set(customer.getLogin(), EXP_TIME, mapper.writeValueAsString(customer));

} catch (Exception ex) {

ex.printStackTrace();

}

return customer;

}

Our experience in switching this J2EE application from Apache Derby, JPA, and Hibernate to Couchbase demonstrated that the switch was fairly simple. The most difficult part was designing the schema, which is an issue when switching any application from an RDBMS to a NoSQL database. Still, designing a document database schema is generally easier than designing a relational database schema.

With the design behind us, it was simply a matter of switching the service classes to use the Couchbase client. Although this is a small application, implementing the Couchbase version was relatively easy and quick, which bodes well for other existing Java EE applications' ability to take advantage of NoSQL.

Michael Brush, Elizabeth Edmiston, and Deep Mistry, who are all developers at Open Software Integrators, contributed to this article.

This article, "How to teach a Java EE app new NoSQL tricks," was originally published at InfoWorld.com. Keep up on the latest developments in application development and read more of Andrew Oliver's Strategic Developer blog at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.

This story, "How to teach a Java EE app new NoSQL tricks" was originally published by InfoWorld.

1 2 Page 2
Page 2 of 2