Java, Wicket and Hibernate on EC2 (pre-interview project)
Over the weekend I put together a project as a precursor to an interview. I really like interviews where I have a chance to solve a problem that’s more meaningful than generating a random number efficiently.
Choice of technology
The instructions indicated that I could use any technology that I was familiar with, as long as I included the libraries necessary to compile the code. Since I’ve been interested in Wicket lately and wanted to get into the latest version of Hibernate (it’s been a few years), I chose Java, Wicket and Hibernate.
For the development IDE I chose NetBeans due to its native support of Maven. Wicket quickstart projects base their build on a Maven pom.xml.
I started my project using the Wicket quickstart. This makes use of Maven archetypes which require Maven2+. Some development benefits that come along with the quickstart include tests that are verified at each compile of the project. This ensures, at a minimum, that your markup and Java files agree.
I used Mercurial (hg) to create a local repository to manage revision control. Even for small projects revision control is a key element and reduces the risk of big refactorings and other explorations. The hg repository can also be ‘pushed’ to anyone else that wants to collaborate on the project.
In some ways, the story that the revision history tells is as important (maybe more so) than the finished product. The revisions themselves provide valuable insight into the way a developer approaches his work.
For the database I chose HyperSQL (HSQLDB). This is a pure Java database with an in memory mode. Hibernate abstracts the database access and makes it easy to move to a more robust production database at some point in the future. HSQLDB makes development easy since the database is initialized each time I restart the jetty server.
Documentation and collaboration
TRAC is my preferred artifact tracking system for software projects. It integrates directly with Mercurial. It provides roadmap, wiki, timeline and other reporting and collaboration devices. Once I got the project to a stable point, I pushed the repository up to a public location with an integrated TRAC instance.
You can checkout the code or view it online using the URL below:
To checkout the code using the URL above just enter this command:
hg clone http://danielwatrous.repositoryhosting.com/hg_public/danielwatrous/favorite-movies favorite-movies
Once you have the code cloned to your local system as shown above, run the commands below to compile and run the application (this requires that you have Maven 2+).
mvn compile mvn jetty:run
You should now be able to view the application at this URL:
Next steps in the development of this application may include additional tests, better encapsulation and refined access mechanisms.
For example, aside from the default tests that are a result of the Wicket quickstart, I haven’t added any additional unittests. If the complexity of the application increased if might be worthwhile to add unittests to the Movie and RatingModel classes.
At some point data access could be encapsulated into a DAO for the Movie class. This might be beneficial if access to Movie objects spread to additional pages and those pages duplicated the code required to access those objects.
I’ve been keen to play around with Amazon’s EC2 service for a while. This seemed like a perfect opportunity, so I added EC2 to my Amazon Web Services account and created an instance. I chose 64 bit Amazon Linux. I chose Tomcat as the web server.
I added the Tomcat server running on my EC2 instance to the Maven files, which made it possible to build and deploy in a single step from the command line
As development continues I can redeploy easily using this command
Download the source
The following resources were helpful during the development of this application:
Enum support in Java/Wicket
Wicket users list
I also found the wicket users list very helpful, as usual: