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.

No comments: