But what if you only need one class for all of your DAOs? In one of my projects I just needed to put all records from a database view to a file. I decided not to use an ORM, but just Spring's JdbcTemplate, configured by view name and column to use in ORDER BY section. So I started to write Spring XML wiring and realized.... that I'm repeating the Spring beans! Every declaration looked something like:
<bean id="customerDAO" class="pl.touk.blog.GenericDao"> <property name="table" value="V_CUSTOMERS"/> <property name="orderColumn" value="CUST_ID"/> </bean> <bean id="contractDAO" class="pl.touk.blog.GenericDao"> <property name="table" value="V_CONTRACTS"/> <property name="orderColumn" value="CONTRACT_ID"/> </bean> ...
There were about 15 twin beans in my Spring XML files! That looked really ugly...