Thursday, September 23, 2010

Legacy System Refactoring - 1. Middle Tier Data Acess

The Legacy System I work on is lots of JSP pages with POJO classes application. The business logic all spread on JSP pages and the POJO classes, thought it is east to start but it is hard to maintain. And the starter not me, I am the maintainer. Everytime I got new requirement, I feel not like to work on it. It took time to understand all the related , even unrelated topic , so that I could work on.

First step, I think adopt Middle Tier Data Access using JdbcTemplate should be easy way.

JdbcTemplate

Let me work on the products table.

1. Domain -- create Product domain class with get/setter methods.

2. DAO -- create ProductDao interface with CRUD methods.

3. JDBC DAO implementation -- public class JdbcProductDao extends SimpleJdbcDaoSupport implements ProductDao

4. ProductManager -- create ProductManager interface so you could group the product related methods together.

5. SimpleProductManager -- implementation of ProductManager interface.

6. Config applicationContext.xml -- specify dataSource, productDao, productManager bean.

7. Jsp pages get the productManager bean --
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
ProductManager productManager = (ProductManager)ctx.getBean("productManager");

That's it. only 7 steps to Refactory that.

Thursday, September 16, 2010

jruby-rack error

After I deploy the war file created from warble to tomcat-5.5.27.
It gave me this error:
org.jruby.rack.RackInitializationException: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Goggling, someone sugguest downgrade to jruby-rack to 0.9.6.
But I can't install this version, it complain they can't find it.

Then I try to deploy to tomcat 6.0.29, it looks fine now. :)
It turn out the ServletContext.getContextPath() is in servlet 2.5 spec, tmcat-5.5 just servlet 2.4.

Reference: