Java Reference
In-Depth Information
Applications often need to access data from multiple data sources: relational data-
bases, file systems, directory services, web services, and other providers. Each of
these data stores has a different API to access the underlying storage mechanism,
along with a whole set of idiosyncrasies.
The Data Access Object ( DAO ) pattern is used to hide the unique implementa-
tion quirks of these API s. It provides a simple and common API for application
developers so that the consumers of the data can be free of the complexities of
the data access API s.
The i BATIS Data Access Objects subproject is a simple implementation of the
core J2EE pattern of the same name.
10.1 Hiding implementation details
One of the key principles of object-oriented programming is encapsulation—the
separation of an implementation and its public interface. The DAO pattern is one
more tool that allows you to do that in your applications. Before we go too far into
the DAO pattern, let's look at figure 10.1, to see what one looks like.
If you are thinking that figure 10.1 looks more like JDBC than a DAO , then you
are only half right. It is JDBC , but the JDBC API in Java is a good example of the
DAO pattern in action.
«interface»
javax.sql.DataSource
«interface»
java.sql.Connection
«interface»
java.sql.PreparedStatement
«interface»
java.sql.CallableStatement
«interface»
java.sql.ResultSet
Figure 10.1
A simplified DAO (or is it JDBC?)
Search WWH ::




Custom Search