Spring notes(六) - DAO and ORMapping support
filed in Java, 设计模式 on Mar.18, 2008, by javafuns
Spring provides all kinds of DAO layers:
- JdbcDaoSupport: you can get JdbcTemplate.
- HibernateDaoSupport:you can get hibernateTemplate and SessionFactory
- JdoDaoSupport: you can get jdoTemplate and PersistenceManagerFactory
- JpaDaoSupport: you can get jpaTemplate and EntityManagerFactory
- SqlMapDaoSupport: you can get sqlMapDaoTemplate and SqlMapClient
So, you can extend these XxxDaoSupport to expose CRUD APIs.
In spring applicationContext.xml, you should inject Datasource, SessionFactory, PersistenceManagerFactory, EntityManagerFactory, SqlMapClient bean to these XxxDaoSupport descendants respectively, so that you can get their XxxTemplate in your DAO subclasses.
Lets see these XxxTemplates:
JdbcTemplate encapsulates Jdbc operations, so that you can use it handily. The other XxxTemplates encapsulate the respective OR-Mappings.
E.g. jdbcTemplate.queryForObject(”select **** “);
Next, i will talk about how smartly the XxxTemplates are designed. They are all best practices of Template-Method. Please keep your focus on.




