Java Reference
In-Depth Information
Let's look at an example of this. Assume a class relationship like the one described
earlier in figure 10.2. In this diagram, there is an AccountDao interface and an
AccountDaoImpl class that implements that interface. To use the DaoManager to get
the DAO , use the following code:
AccountDao accountDao = (AccountDao)
In this line of code, we declare our AccountDao variable, request it from the
DaoManager instance using the interface name, and then cast it to the AccountDao
interface, because the DAO manager simply returns Object .
In the previous version of the DAO , it was also possible to pass in a String
instead of an interface class. In version 2. x , that functionality was dropped,
because it eliminated a potential point of failure. By forcing the use of a class
name for identifying DAO implementations, you ensure that misspellings can be
avoided in the Java environment, because if the interface name is misspelled, the
code will not compile. Early failure is a good thing.
So, now that you have a solid foundational understanding of what you can do
with the i BATIS DAO framework, we can start looking at other more advanced uses
of it.
10.3 Configuration tips
Although the DAO configuration looks very simple on the surface, it still offers a
great deal of flexibility. By creatively configuring the DAO manager, you can
accomplish some pretty sophisticated approaches to common problems. Let's
look at a few of them.
Multiple servers
As mentioned earlier, it is not uncommon in most development shops to have
different servers for their development, QC testing, UA testing, and production
In these cases, it is very useful to be able to remove the environment-specific
information from the dao.xml file and put it into an external file. The properties
element was created to accomplish just that sort of thing. Listing 10.3 is a sample
dao.xml file that uses this technique to make the JDBC settings external to the
dao.xml file.
Search WWH ::

Custom Search