Java Reference
In-Depth Information
i BATIS supports XML directly to and from the database, either as a Document
Object Model ( DOM ) or simply as a String. There is somewhat limited value in
doing so; however, it can be useful in simpler applications that just need to con-
vert data into a portable and parsable format quickly.
However, like maps, XML should not be your first choice for a domain model.
XML is the slowest, least type-safe, and most memory-demanding type of all. It is
the closest thing to the end state of your data (i.e., often HTML ), but that advan-
tage comes at the price of being difficult to manipulate and hard to maintain over
time. As with maps, use XML judiciously.
Primitives are supported directly by i BATIS as parameters and results. There is no
issue with using a primitive in either way. Primitives are fast and type-safe. Obviously
you're somewhat limited with how complex your data can be; however, if you have
a simple requirement to count the rows for a given query, a primitive integer is the
way to go. Feel free to use primitives as long as they can satisfy the requirement.
13.5 Summary
Using i BATIS is not hard, but as with any framework, you can always improve the
results if you follow the recommended best practices.
In this chapter we discussed how to ensure that the persistence layer of your
application is appropriately tested. Using two popular unit-testing frameworks,
JU nit and JM ock, we are able to test three separate layers of our application in a
simple and consistent way. We discussed appropriate ways to set up a test database
to ensure that your tests don't require a network connection or a complex piece
of infrastructure such as a relational database management system.
We also discussed the best way to manage your XML files. Location
transparency is the key to simple deployment and ensures easy testing and future
maintainability. Location transparency can be achieved in Java applications by
keeping all of the SQL map files in the classpath. Because in some cases you can't
keep all of them in the classpath, we discussed an approach to separating the
configuration so that it can be kept in a centralized location while keeping all of
the other mapping files on the classpath where you want them.
Next, we discussed how to name all of the different i BATIS objects. Naming is
as important as organization to ensure that your maps are easy to read and follow.
Keeping statement names consistent with method names makes for a familiar
Search WWH ::

Custom Search