Saturday, August 4, 2012

Data Access templates in spring





  •          JmsTemplate class.
  •          JdbcTemplate class.
  •         SimpleJdbcTemplate class.
  •          NamedParameterJdbcTemplate class.
  •          SqlMapClientTemplate class.
  •          HibernateTemplate class.
  •          JdoTemplate class.
  •          JpaTemplate class.


·         JmsTemplate class (org.springframework.jms.core.JmsTemplate)
It is a general-purpose class for managing Java Messaging Service (JMS) connections. One of the main advantages of this class is that it simplifies the JMS synchronous access codes.



           JdbcTemplate class (org.springframework.jdbc.core.JdbcTemplate)
It is a wrapper around a JDBC data source, enabling you to access a JDBC database using SQL operations.

  1. It simplifies the use of JDBC since it handles the creation and release of resources                      This helps to avoid common errors such as forgetting to always close the connection.
  2. It executes the core JDBC workflow like statement creation and execution, leaving application code to provide SQL and extract results                                                       This class executes SQL queries, update statements or stored procedure calls, imitating iteration over ResultSets and extraction of returned parameter values.
  3. It also catches JDBC exceptions and translates them to the generic, more informative, exception hierarchy defined in the org.springframework.dao package.


examples


 this.jdbcTemplate.queryForInt
 this.jdbcTemplate.queryForObject
 this.jdbcTemplate.query
 this.jdbcTemplate.update("insert/delete/update

·         SimpleJdbcTemplate class (org.springframework.jdbc.core.simple.SimpleJdbcTemplate)
It is a convenience wrapper around the JdbcTemplate class. This class has been tear down so that it includes only the most commonly used template methods and it has been optimized to exploit Java 5 features.

·         NamedParameterJdbcTemplate class (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)
It is a convenience wrapper around the JdbcTemplate class, which enables you to use named parameters instead of the usual ? placeholders embedded in a SQL statement.

·         SqlMapClientTemplate class (org.springframework.orm.ibatis.SqlMapClientTemplate)
It is a simplifying wrapper around the iBATIS SqlMapClient class. iBATIS is an Object Relational Mapper (ORM) that is capable of automatically instantiating Java objects based on a given SQL database schema.

·         HibernateTemplate class (org.springframework.orm.hibernate3.HibernateTemplate)
It provides an alternative to working with the raw Hibernate 3 session API (based on sessions returned from SessionFactory.getCurrentSession()).

·         JdoTemplate class (org.springframework.orm.jdo.JdoTemplate)
It provides an alternative to working with the raw JDO PersistenceManager API. The main difference between the APIs relates to their exception handling. See the Spring JavaDoc for details.

·         JpaTemplate class (org.springframework.orm.jpa.JpaTemplate)
It provides an alternative to working with the raw JPA EntityManager API..

No comments:

Post a Comment