Java Reference
In-Depth Information
As an example of the complexity that i BATIS takes care of for you, let's look at
the pattern for properly allocating and ensuring the release of a JDBC connection:
Connection connection = null;
try {
connection = dataSource.getConnection();
if (null == connection){
// kaboom
} else {
useConnection(connection);
}
} catch (SQLException e) {
// kaboom
}finally{
if (null != connection) {
try {
connection.close();
} catch (SQLException e) {
// kaboom
}
}
}
That is almost 20 lines of code to simply get a Connection object, use it, and then
close it properly. Beyond that, the same pattern is required for safely working with
Statement and ResultSet objects. When you consider what is required to imple-
ment many of the features using plain JDBC that i BATIS handles for you—such as
getting a connection to the database, parameter and result mapping, lazy loading,
and caching—it becomes clear that it would take a great deal of careful coding.
Luckily, i BATIS is a lot easier to configure and work with, as you'll see in the
remainder of this and the next few chapters.
3.6 i BATIS configuration continued
In chapter 2, we looked very briefly at how to configure i BATIS (so briefly, in fact,
that if you haven't read that section, don't worry about it). In this section, we build
on that basic configuration by creating the SQL Map configuration file. This file is
the brain of i BATIS , as shown in figure 3.1.
In this figure, we have the SqlMapConfig file at the top, which is where we define
global configuration options, and also reference the individual SqlMap s them-
selves. The SqlMap s in turn define the mapped statements that will be used in con-
junction with input that your application provides to interact with the database.
Let's take a closer look at how you'd use this configuration file.
Search WWH ::




Custom Search