Java Reference
In-Depth Information
return returnValue;
} catch (GoogleSearchFault googleSearchFault) {
throw new DaoException(googleSearchFault);
The Google API is very similar to the DAO interface, which is no surprise, but it
requires a key to work. This is not a problem in our example, because we just
hardcoded the key into our implementation. In a production application, you
would want something better than that, perhaps providing a way for you to use a
user-specific key instead of a shared key.
This shows another limitation of the i BATIS DAO layer. Because it cannot pro-
vide multiple instances of a DAO class and can only use the default constructor,
making this DAO work the way we want it to will require that we jump through
some extra hoops.
In the next section, we look at how to use the Spring framework to make a
more capable DAO layer that allows us to perform some pretty advanced tricks
with configuration.
11.3 Using the Spring DAO
There are many different ways that you could use the Spring framework in the
data access layer of your application that do not have anything to do with i BATIS .
In this section, you'll learn how to use Spring's support for i BATIS to build a data
access layer.
Writing the code
The Spring framework supports i BATIS using a template pattern for the data
access objects, meaning that you start with an existing Spring class ( SqlMapClient-
Template ) and extend it for your DAO . Using this technique, our AccountDao
implementation would look like listing 11.6 using Spring.
Listing 11.6
Spring version of our SQL Maps Account DAO
public class AccountDaoImplSpring
extends SqlMapClientTemplate
implements AccountDao
public Integer insert(Account account) {
return (Integer) insert("Account.insert", account);
Search WWH ::

Custom Search