Java Reference
In-Depth Information
enabled us, for example, to replace the real implementation with a mock imple-
mentation when testing the transaction scripts.
The DAO interfaces define the methods that are called by the transaction
scripts to insert, find, update, and delete rows in the database. The DAO imple-
mentation classes use the Spring i BATIS support classes, which are a convenient
way to use the i BATIS framework and mirror the support that Spring provides for
JDBC and ORM frameworks such as JDO and Hibernate. These classes integrate
i BATIS with Spring's mechanisms for managing JDBC connections and transac-
tions. They allow i BATIS to be configured using Spring beans and enable the i BA-
TIS code to use the same JDBC DataSource as the rest of the application.
The two classes used by the DAO s are SqlMapClientTemplate and SqlMapClient-
DaoSupport . The SqlMapClientTemplate class provides methods for executing SQL
statements and is analogous to the JdoTemplate and HibernateTemplate classes you
have seen earlier in this topic. It invokes an i BATIS SqlClientMap to execute SQL
statements defined in XML descriptor files, and maps any exceptions to Spring data
access exceptions. SqlMapClientDaoSupport is a convenient base class for i BATIS
DAO s and makes a SqlMapClientTemplate available to its subclasses.
In this section, we'll look at how to implement DAO s using i BATIS and Spring.
You will learn how to develop DAO s using a test-driven approach that uses mock
objects for the Spring/i BATIS API s in order to be able to test the DAO s without a
database. We also describe strategies for testing with the database.
9.4.1
Overview of using iBATIS with Spring
The i BATIS framework is an open source project that was founded by Clinton
Begin with the goal of simplifying database access. The name “i BATIS ” is a combi-
nation of the letter “i” from the word “Internet” and the letters “b-a-t-i-s” from the
word “abatis,” which is a defensive barrier formed by cut-down trees with sharp-
ened branches facing the enemy. In case you were wondering who the enemy is,
the name reflects the fact that the i BATIS project first developed Internet cryptog-
raphy software.
Today, the i BATIS project is very much focused on database access software.
The i BATIS framework significantly simplifies the task of executing SQL state-
ments. It eliminates the need to write the error-prone and sometimes complex
JDBC code that manipulates PreparedStatement s and ResultSet s and maps
between them and Java objects. i BATIS uses XML descriptor files to map between
Java objects and SQL statements and JDBC result sets. It maps the properties of an
object to the parameters of a SQL statement and maps the columns of a ResultSet
 
 
 
 
Search WWH ::




Custom Search