Java Reference
In-Depth Information
public void close() throws SQLException,
TransactionException;
public Connection getConnection()
throws SQLException, TransactionException;
}
There's really nothing special about this particular interface. If you have any expe-
rience with transactions at all, it will look familiar. The
commit()
method is, as
expected, the means of making permanent all of the changes involved in the unit
of work. The
rollback()
method, on the other hand, is meant to undo all of the
changes that have occurred in the unit of work, or at least since the last commit.
The
close()
method is responsible for releasing any, and all, resources that may
have been allocated or reserved for the transaction.
The last method,
getConnection()
, is the one that you may not have expected.
By design,
iBATIS
is a high-level framework around the
JDBC
API
. Loosely speak-
ing, the connection is the transaction in
JDBC
. At the very least, transactions are
managed, controlled, and understood at the
JDBC
connection level. For that rea-
son, most transaction implementations are bound to a
Connection
instance. This
is useful, because
iBATIS
needs access to the connection currently associated to
the transaction.
12.6 Summary
In this chapter we've explored various ways of extending
iBATIS
. Standard exten-
sions are important, even for open source software, to avoid uncontrolled custom-
ization of the framework in potentially undesirable and unmaintainable ways.
iBATIS
supports a number of different extensions, including
TypeHandlerCall-
back
,
CacheController
,
DataSourceFactory
, and
TransactionConfig
.
TypeHandlerCallback
is the most common type of extension, since it deals with
the common problem of proprietary data types.
TypeHandlerCallback
is simple to
implement; it requires only a few methods to be implemented that allow for cus-
tomization of the mapping between Java types and
JDBC
types. In a nutshell,
Type-
HandlerCallback
becomes responsible for setting parameters on statements,
getting results from the result set, and translating null value replacements for
mapping nullable database types to non-nullable Java types.
CacheController
s provide a simple means of integrating third-party caching
solutions into
iBATIS
. Of course, you could also write your own, but writing a decent
cache is amazingly difficult. The
CacheController
interface includes methods for


