ACCU London March 2010

Paul Grenyer: Enterprise Web Application Development in Java with AJAX and ORMs

 

March 2010 saw the London branch of the ACCU meet to listen to Paul Grenyer talk about Enterprise Web Application Development. After a brief biography and definition of what an Enterprise Application is he leapt into the heart of the topic – writing code to communicate with a database. Unlike his previous talks where he demonstrated code with slides, this time he decided to go ‘live’ and use Eclipse, a shell and later a web browser as his presentation tools. This is always a brave move but aside from one minor glitch it went very smoothly and I think everyone appreciated seeing real code running against a real database.

 

The first half of the presentation looked at techniques for mapping objects to relational databases. His first example was a classic manual SQL approach where the developer writes all the code to invoke the query, extract the result data and clean up. Anyway who attended his previous talk about resource management in database access code will know the lengths required for this approach. He then switched to using one of the most popular O/RM tools (Hibernate) to take much of the legwork out of this affair. This was then refined over subsequent iterations to slowly reduce the amount of client code at the expense of a more complex class hierarchy using the Data Mapper and Registry patterns. The payoff though was the ability to Unit Test and Integration Test your Database Access layer.

 

The Integration Testing aspect was of particular interest to me as I had been working on this issue myself, albeit in C#, and was glad to see I was following a similar approach. Paul had MySQL running locally and the technique involved creating a database from scratch that contained just the tables and objects – no data. The tests would then be responsible for adding and removing any data; he used the natural rollback feature of transactions to perform the clean up. His test code essentially performed a round-trip by writing a new object and then reading it back again, being careful to ensure he was really hitting the database and not being served up his previous object from some internal cache.

 

The latter part of his presentation looked at the GUI side of things and the Google Web Toolkit (GWT) in particular. This toolkit allows you to write your presentation code in Java as well - turning it into JavaScript to run in the client’s browser – so that you can use the same code on both client and server. The server-side logic was exposed as a web service using JETTY and invoked from the client via AJAX. Having only done classic ASP in the past I found it quite impressive to see what could be achieved with such little code and the murmurs from the audience seemed to concur. His parting gift was to skin the UI with a light dash of CSS to show it could easily be tarted up without touching the code.

 

As always we moved from the conference room to the pub across the road to continue any discussions, although I probably monopolised the speaker as I had a number of questions about his Integration Testing methods. His talk may have had Java in the title, but as is often the case many of the concepts and techniques he illustrated apply equally well to other similar platforms such as C#/.Net. I look forward to watching the full version at this years ACCU conference next month.