Java Reference
In-Depth Information
return productDao.getProductListByCategory(categoryId);
}
Explicit transaction management (see listing 14.15) is a bit more involved. It is
only needed when we are making more than one call to the data access objects.
Within a try block, we would first call daoManager.startTransaction() ; we would
then perform our calls to one or more data access objects. When we have com-
pleted our calls to the data access layer, we would commit the transaction by call-
ing daoManager.commitTransaction() . If the call(s) were to fail for any reason, we
would have a daoManager.endTransaction() located in the finally block. This
would roll back our transaction and prevent any damage to our data store. For the
simple select we are performing, there is no need for this level of transaction
management. However, you could do it either way if you prefer.
Listing 14.15
Example of explicit transaction management
public PaginatedList getProductListByCategory(
String categoryId
) {
PaginatedList retVal = null;
try {
// Get the next id within a separate transaction
daoManager.startTransaction();
retVal = productDao
.getProductListByCategory(categoryId);
daoManager.commitTransaction();
} finally {
daoManager.endTransaction();
}
return retVal;
}
Now that we have made it through the service layer in our simple view category
example, let's finish this up by assembling the remaining pieces in the DAO layer.
14.8 Writing the DAO
The data access layer is where the Java code touches the database. The i BATIS
SQLMap framework is used here to make handling SQL easier. A data access layer
that uses i BATIS SQLMap s can be broken out into three basics pieces: the SQLMap
configuration file, the associated SQLMap SQL files, and the data access objects.
Search WWH ::




Custom Search