Three data source factory implementations come with i BATIS ; each is listed in
table 3.5, along with a brief description. These will be discussed in more detail in
Data source factories
The simple data source factory is just that. It is used to configure a data
source that has a simple connection pool built into it, and everything it needs
is included with the iBATIS framework except the actual JDBC driver.
The DBCP data source factory is for using the Jakarta Commons Database
Connection Pool implementation.
The JNDI data source factory is used to allow iBATIS to share a container-
based data source that is located via JNDI.
Similar to the <transactionManager> element, the <dataSource> element can
have any number of properties passed to it for configuration using nested prop-
The <typeHandler> element
The i BATIS framework uses type handlers to convert data from the JDBC database-
specific data types to your application data types, so you can create an application
that uses a database in a way that makes the database as transparent as possible. A
type handler is essentially a translator—it takes a result set column and translates
it into a bean property.
In most cases, these components are very simple, like the StringTypeHandler
that simply calls the result set's getString method and returns it as a String. In
other cases, you may have more complex translation requirements. For example,
if your database does not have a Boolean data type, you may use a single character
with Y and N values to indicate true and false in the database, but then translate
that character to Boolean in your application classes.
In chapter 12, you will learn more about how to build custom type handlers to
deal with these sorts of situations, so we will not go into much more detail here.
To deal with this situation, you need to create two classes: a custom type handler
and a type handler callback.
If you write a custom type handler, you need to tell i BATIS how and when to
use them. You do that by using the <typeHandler> element and telling it what it is
translating between: the jdbcType and the javaType . In addition, the callback class
that is used to manage the type handler is required.