Learn Java for Web Development

(Tina Meador) #1
CHAPTER 1: Introducing Java Web Development 25

You can verify the populated Author table as illustrated in Figure 1-18.


Figure 1-18. All authors in the Author table


Figure 1-19. DAO pattern


Data Access Layer for the Bookstore Application

Now that the database is ready, you will build the data access layer for application. The data
access layer will retrieve the data via JDBC from the database and directly map the result set
into Java objects. These Java objects are the domain objects in the application that are the Java
representation of the tables in the database. The data access layer is responsible for interfacing with
the underlying persistence mechanism in a transparent way in order to store and retrieve objects
from the database. This transparency means that the data access layer can switch the persistence
mechanism from plain JDBC^14 to ORM^15 persistence technologies such as Hibernate,^16 JPA,^17 and so
on, without affecting the client of the data access layer. This transparency is achieved via the data
access object (DAO) pattern, as illustrated in Figure 1-19. The DAO object provides an interface to the
database or the underlying persistence mechanism, thus abstracting the underlying implementation
from the client.


(^14) http://www.oracle.com/technetwork/java/overview-141217.html
(^15) http://en.wikipedia.org/wiki/Object-relational_mapping
(^16) http://www.hibernate.org/
(^17) http://www.oracle.com/technetwork/java/javaee/tech/persistence-jsp-140049.html

Free download pdf