David Sills's muse is fueled by Bach, Beethoven, and Brahms (and Berlioz and Boulez). He has no life, which comports well with the über-geekitude to which he aspires. He reads and writes fitfully in English, Spanish, French, German, Italian (mostly medieval), C, VB, Perl.... Oh, and Java and XSLT, lots and lots of Java and XSLT. Trained somewhere in darkest Central America, he works today at DataSource, Inc., on the product team for the CASE tool Jetson.
| Author(s) | Clinton Begin, Brandon Goodin, Larry Meadors |
|---|---|
| Publisher | Manning |
| PubDate | 2007 |
| Reviewer | David Sills |
![]() |
Purchase and help Javalobby |
|
iBATIS is a solution between JDBC and object/relational mapping (ORM). The former is perhaps too low-level, and can be error-prone and hard to maintain, and the latter can be complex and invasive beyond the needs of many applications. In particular, applications sitting between a Web user and a database, without inordinately complex business logic (which, to be honest, is a lot of applications), can benefit enormously from the simplicity and ease of maintenance iBATIS brings to the table.
Anyone considering using iBATIS will want to have iBATIS In Action on their bookshelf, even if they do not in the end decide iBATIS is the right solution for them.
iBATIS In Action steers neatly between the Scylla of being an introduction to the technology and the Charybdis of being a reaonsably complete and easy-to-use reference work. After reading many an introduction and many a reference, I think it safe to say I have not read another text that so well combines the best attributes of both.
Chapter 1 (The iBATIS philosophy) introduces the philosophy behind iBATIS. iBATIS combines lessons learned from various approaches to building relational-database-centric applications: SQL, stored procedures, SQL embedded within some modern computer languages, dynamic SQL, and ORM. iBATIS allows SQL to be encapsulated outside the compiled code, minimizing the code impact of schema changes. By making no assumptions about the type, features, or design of the database, it allows working in a wide array of situations, from small to enterprise databases, from new to legacy designs.
Chapter 2 (What is iBATIS?) delves into the design and internal makeup of iBATIS. iBATIS is an instance of Martin Fowler's Data Mapper design pattern, distinguishable from ORM solutions by its focus. The latter focuses on the relationship between the database schema and object structure, mapping attributes to table columns in a variety of ways. iBATIS, instead, maps object attributes to result set columns produced by SQL statements. This chapter helps the user decide when to use iBATIS, and, more unusually, when iBATIS is not the right solution for your application. It introduces a simple, easily-understood example of an iBATIS configuration file, the nexus where the application and the framework meet.
Chapter 3 (Installing and configuring iBATIS) explores the process of obtaining and deploying iBATIS in stand-alone and container-managed situations. It continues with the basics of configuration files and a discussion of the elements available and their usages.
Chapter 4 (Working with mapped statements) introduces the working with iBATIS and JavaBeans, the iBATIS API, and working with a variety of input and outputs, including both application domain objects and maps with object and primitive types. iBATIS exposes a sensible and uncomplicated API to resolve many typical situations. Particularly valuable in this chapter is the discussion of SQL injection attacks and how iBATIS helps protect applications from them.
Chapter 5 (Executing nonquery statements) brings us to discussion of non query SQL statements, inserts, updates, and deletes. Dealing with auto generated keys is always a complex issue, and iBATIS provides straightforward solutions that make the best use of the various database options for retrieving such key values. One of the keys to understanding iBATIS is to understand that it doesn't claim to solve every conceivable problem interacting with databases, but focuses on giving the user enough information to solve those problems in a straightforward way. For example, iBATIS does not itself implement record locking to handle the concurrent update issue, but allows for the same kind of version ID fields used by ORM solutions, and returns in the API the number of values updated, allowing the user to know and handle the case when 0 records are been updated because the version number indicates that the data being updated is stale. A discussion of batch process and stored procedure handling concludes the chapter.
Chapter 6 (Using advanced query techniques) discusses more advanced query techniques. Applications can use XML to pass parameters in or results out of queries. Object relationships can be managed, using lazy loading and avoiding the well-known "N+1 select" problems that can come up with ORM solutions. Managing application object inheritance is also discussed, as is dealing with DDL statements. Extremely large data sets present major challenges to any database framework, but the extensibility of iBATIS allows for efficient and easily maintainable solutions.
Chapter 7 (Transactions) presents transactions and their management within iBATIS. For the most frequently encountered cases, this is essentially transparent to the iBATIS user, but special cases like global transactions or passive participation in externally managed transactions can be explicitly configured in straightforward fashion. The iBATIS API allows for custom management of transactions for those applications that require it. A clear and well-thought-out discussion of transaction demarcation ends the chapter.
Chapter 8 (Using Dynamic SQL) suggests various cases in which dynamic SQL can be useful and how it can be accommodated within iBATIS. The SQL for a query may depend, for instance, upon the condition of parameters passed to the statement, changing depending upon whether or not the parameters are null, within a given range, greater or less than a particular value, and so forth. A common case for dynamic situation is handling collection parameters using the "IN" operator in SQL. Another is query-by-example, where search results are implied by the condition of the supplied object parameter. iBATIS has clever, easy-to-use solutions for these cases. The chapter closes by comparing these solutions to what would be needed to resolve these cases using Java code or stored procedures, which only enhances our appreciation for the value of iBATIS's simplicity and clarity.
Chapter 9 (Improving performance with caching) offers thoughts on performance improvements available through judicious and appropriate use of iBATIS's caching options. iBATIS offers different caching choices that should be carefully considered and weighed before use, and important options for cache management. Different cache models enable fine-tuning the strategy your application uses to meet your requirements.
Chapter 10 (iBATIS data access objects) acquaints us with iBATIS's data-access-object (DAO) solution. This is now less relevant, as iBATIS has come to recommend using the Spring framework approach to DAO management since the iBATIS In Action was written, but can still be useful for those restricted to using older versions of the framework.
Chapter 11 (Doing more with DAO) expands upon DAO solutions, covering the integration of iBATIS with Spring DAOs, and enough information about other DAO implementation possibilities to allow the user to fairly and objectively decide between iBATIS and other available solutions. This kind of openness and fairness about iBATIS in relation to other solutions, and recognition of the self-evident fact that not all applications are right for iBATIS, is paradoxically one of the strongest recommendations for iBATIS and for this book on every programmer's shelf, even if iBATIS is not the right solution for your particular application.
Chapter 12 (Extending iBATIS) recommends cases where customization of iBATIS is appropriate and introduces the idea of pluggable component design as iBATIS's response to this need. iBATIS is designed for customization at a number of levels, so the process of customization is not complicated, but there are things to consider before abandoning the many built-in options, and this chapter presents the pros and cons of customization thoroughly.
Chapter 13 (iBATIS best practices) is perhaps the most important in the text. iBATIS has the advantage over ORM solutions or straight JDBC of taming complexities in the simple cases while allowing for it where it cannot be helped. In any solution, however, best practices develop, and it can lop much time off the learning curve necessary for any solution to understand these. This chapter discusses unit testing with iBATIS; managing iBATIS configuration files so they do not become an unruly, snarled mess; using naming conventions to clarify what can be found where; and managing the choice of JavaBeans, Map objects, or XML as parameters or result types.
Chapter 14 (Putting it all together) continues the lessons of the previous chapter by putting iBATIS in the context of developing a typical application. The ubiquitous Web-based shopping cart application provides a useful, well-understood paradigm for this context-building. Putting everything is place provides perspective on the place of iBATIS and other database solutions within an application and emphasizes the many problems iBATIS can remove from the application developer, who is left free to focus on other matters closer to the ultimate application user. This makes iBATIS all the more useful and more relevant to those working on tight deadlines with demanding clients (and who isn't, these days?).
A single appendix provides an invaluable iBATIS quick-start, which also discusses iBATIS.NET (not so relevant on this forum, but the ideas behind iBATIS are simple and comprehensive enough not to be restricted to a single language, even one so useful and ubiqitous as Java).
| Relevance | |
|---|---|
| Readability | |
| Overall | |
This is a truly fabulous text, as the rest of this review should make clear. It well justifies its inclusion in the stellar "In Action" series. It shares with every text I have read in that series a clear, easily read style and down-to-earth presentation.
A cardinal point about any technology text should be whether or not it helps you decide whether or not the technology it presents is right for your situation: iBATIS In Action meets this requirement admirably.
There are, of course, minor cavils. The text could be a bit clearer upfront about how to handle a query with multiple parameters (which is to say most queries to be used in real-life situations). It must have seemed so obvious to the authors how to do this that it never even occurred to them that it might not be equally obvious to the introductee (maps, people, maps!). This is such a small quibble in overall such an excellent text that I cannot bring myself even to deduct a half-star for it, since it eventually becomes crystal-clear how it is to be managed. But I did keep asking, "but how do I query on both first and last names?", for a bit too long.
Another extremely minor point is that there is no comparison between iBATIS and the new Java Persistence Architecture (JPA, or you may know it as part of EJB 3). The latter was not finalized when the book was written, but the comparisons with Hibernate and other similar ORM solutions contained within the book may fairly be extended to cover JPA as well.
Finally, unlike some 1000-plus-page tomes, this text (a slim 336 pages with a well-organized index) doesn't cover every conceivable situation in which the use of iBATIS may be considered. This increases its readability, of course (my first perusal took about two days), and Manning's web forum, which allows access to other users and the authors, should satisfy even the most arcane need.
The iBATIS pages at http://ibatis.apache.org/ are the central resource to be consulted for information.
Anyone intent upon considering iBATIS should probably also be considering the Spring framework, found at http://www.springframework.org/. Spring can make using iBATIS even easier than it is out of the box!