-
7/29/2019 DAO Design Pattern - A Core J2EE Design Pattern
1/4
05/02/2013 DAO Design Pattern - A Core J2EE Design Pattern
www.codefutures.com/j2ee-design-pattern/
Home
Products
Resources
Our Customers
Support
About CodeFutures
DAO Design Pattern: A Core J2EE Design
Pattern
DAO Design Pattern
Business applications almost always need access to data from relational or object databases and the Java
platform offers many techniques for accessing this data, the best of wich use the DAO Design Pattern. The oldes
and most mature technique is to use the Java Database Connectivity (JDBC) API, which provides the capability
to execute SQL queries against a database and then fetch the results, one column at a time. Although this API
provides everything a developer needs to access data and to persist application state, it is a cumbersome API todevelop against - which makes a code generator particularly useful.
Java 2 Enterprise Edition (J2EE) offers a newer persistence framework in the form of Entity Beans, a subset of
the Enterprise JavaBean (EJB) framework. Although there have been many improvements in the more recent
EJB 2.0 specification, many developers are now looking to alternative persistence frameworks, such as Java
Persistence API (JPA) and Hibernate DAO.
The Benefits of the DAO Design Pattern
The DAO Design Pattern provides a technique for separating object persistence and data access logic from anyparticular persistence mechanism or API. There are clear benefits to this approach from an architectural
perspective. The DAO Design Pattern approach provides flexibility to change an application's persistence
mechanism over time without the need to re-engineer application logic that interacts with the DAO Design
Pattern tier. For example, there may be performance benefits in changing an application's performance
mechanism from using Entity Beans to using direct JDBC calls from a session bean, or even a move to an
alternative persistence framework, such as Hibernate. Without a DAO Design Pattern tier in place, this sort of
transition would require extensive re-engineering of existing code.
The DAO design pattern also provides a simple, consistent API for data access that does not require knowledge
http://www.codefutures.com/company/about/http://www.codefutures.com/customers/http://www.codefutures.com/database-products/http://www.codefutures.com/http://www.dbshards.com/http://www.codefutures.com/http://www.codefutures.com/http://www.codefutures.com/hibernate/http://www.codefutures.com/company/about/http://www.codefutures.com/support/http://www.codefutures.com/customers/http://www.codefutures.com/library/http://www.codefutures.com/database-products/http://www.codefutures.com/http://www.codefutures.com/weblog/corporate/atom.xmlhttp://www.dbshards.com/http://www.codefutures.com/ -
7/29/2019 DAO Design Pattern - A Core J2EE Design Pattern
2/4
05/02/2013 DAO Design Pattern - A Core J2EE Design Pattern
www.codefutures.com/j2ee-design-pattern/
of JDBC or EJB interfaces. A typical DAO Design Pattern interface is shown below.
public interface CustomerDAO
{
public void insert(Customer customer)
throws CustomerDAOException;
public void update(CustomerPK pk, Customer customer)
throws CustomerDAOException;
public void delete(CustomerPK pk)
throws CustomerDAOException;
public Customer[] findAll()
throws CustomerDAOException;
public Customer findByPrimaryKey(String email)
throws CustomerDAOException;
public Customer[] findByCompany(int companyId)
throws CustomerDAOException;
}
It is important to note that DAO J2EE Design Pattern does not just apply to simple mappings of one object to
one relational table, but also allows complex queries to be performed and allows for stored procedures and
database views to be mapped into Java data structures.
Additional useful information on Data Access Objects J2EE Design Pattern is available here;
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
http://www.corej2eepatterns.com/Patterns2ndEd/DataAccessObject.htm
Minimizing the Impact of Moving to DAO
CodeFutures' objective is to minimize the importance of the main argument against using DAO Design Pattern:
the fact that it requires a significant amount of repetitive source code to be produced for no immediate advantage
over using JDBC or EJB directly. For many developers, this disadvantage is good enough reason to ignore the
long-term benefits of using a framework-neutral API, especially where there are strict project deadlines. Without
the code generation advantages of FireStorm/DAO, it is not easy to justify to a project manager or project
sponsor the time and cost of manually writing DAO code, regardless of any future benefits they may see.
DAO Design Pattern Code Generation
CodeFutures' solution to the manual coding problem is to automate the production of a DAO Design Pattern tier
as well as automating the actual implementation logic for whichever persistence framework is deemed
http://www.corej2eepatterns.com/Patterns2ndEd/DataAccessObject.htmhttp://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html -
7/29/2019 DAO Design Pattern - A Core J2EE Design Pattern
3/4
05/02/2013 DAO Design Pattern - A Core J2EE Design Pattern
www.codefutures.com/j2ee-design-pattern/
appropriate for an application. This approach is easy to adopt because almost all databases use a standard
language for defining their structure (SQL).
Additional Reading on Design Patterns
EJB Design Patterns by Floyd Marinescu
http://www.theserverside.com/books/wiley/EJBDesignPatterns/index.tss
The Hillside Group
http://hillside.net/patterns/onlinepatterncatalog.htm
JavaWorld list of design pattern articles
http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml
The Design Patterns Java Companion
http://www.patterndepot.com/put/8/JavaPatterns.htm
Data and Object Factory
http://www.dofactory.com/patterns/Patterns.aspx
A Learning Guide To Design Patterns
http://www.industriallogic.com/papers/learning.html
Design Patterns (good quality personal page)
http://home.earthlink.net/huston2/dp/patterns.html
Additional Resources
FireStorm/DAO is a database access tool based on the Data Access Object design pattern.
Download FireStorm/DAO
CodeFutures provides a free program to analyze the performance of your MySQL database.
Free MySQL Performance Analysis
Read about how Database Sharding helps many major companies to linearly scale their database applications.
Request Database Sharding White Paper
dbShards economically scales large, high transaction volume databases using Database Sharding.
View Introduction to dbShards Video
Products
http://www.codefutures.com/dbshards-product-presentation/http://www.codefutures.com/database-sharding/http://www.codefutures.com/database-sharding-white-paper/http://www.codefutures.com/database-sharding/http://www.codefutures.com/database-performance-analysis/http://www.codefutures.com/products/firestorm/download/http://www.codefutures.com/data-access-object/http://www.codefutures.com/products/firestorm/http://home.earthlink.net/huston2/dp/patterns.htmlhttp://www.industriallogic.com/papers/learning.htmlhttp://www.dofactory.com/patterns/Patterns.aspxhttp://www.patterndepot.com/put/8/JavaPatterns.htmhttp://www.javaworld.com/columns/jw-java-design-patterns-index.shtmlhttp://hillside.net/patterns/onlinepatterncatalog.htmhttp://www.theserverside.com/books/wiley/EJBDesignPatterns/index.tss -
7/29/2019 DAO Design Pattern - A Core J2EE Design Pattern
4/4
05/02/2013 DAO Design Pattern - A Core J2EE Design Pattern
www.codefutures.com/j2ee-design-pattern/
dbShards
FireStorm/DAO
FireStorm/DAO
FireStorm/DAO Overview
DAO Benefits
FireStorm/DAO FeaturesFireStorm/DAO Architecture
FireStorm/DAO FAQs
DAO Design Pattern
DAO Tutorial
DAO Download
FireStorm/DAO Editions
Product Range
Architect Edition
OEM Edition
Free
MySQL
Performance
Analysis
Click Here
DATABASE PERFORMANCE TOOLS
dbShards economically scales large, high transaction volume databases using Database Sharding, dramatically
improving the response times and scalability of OLTP databases, Software as a Service applications, and any
database application with many concurrent users.
FireStorm/DAO is a database access tool that generates Data Access Objects based on Java DAO, JDBC
DAO, Hibernate DAO, and Spring DAO.
Site Map | Legal | Site Search
Technologies Supported:Database Sharding | Data Access ObjectSpring DAO
Hibernate DAO | JDBC DAO | Java DAO | DAO Code
Copyright 2003-2009 CodeFutures Corporation. All rights reserved.
dbShards, FireStorm/DAO, FireStorm/SDO, and CodeFutures are trade marks of CodeFutures
Corporation.
http://www.codefutures.com/dao-code/http://www.codefutures.com/java-dao/http://www.codefutures.com/jdbc-dao/http://www.codefutures.com/hibernate/http://www.codefutures.com/spring-dao/http://www.codefutures.com/data-access-object/http://www.codefutures.com/database-sharding/http://www.codefutures.com/search/http://www.codefutures.com/company/legal/http://www.codefutures.com/company/sitemap/http://www.codefutures.com/spring-dao/http://www.codefutures.com/hibernate/http://www.codefutures.com/jdbc-dao/http://www.codefutures.com/java-dao/http://www.codefutures.com/data-access-object/http://www.codefutures.com/products/firestorm/http://www.codefutures.com/database-sharding/http://www.codefutures.com/http://www.codefutures.com/database-performance-analysis/http://www.codefutures.com/database-performance-analysis/http://www.codefutures.com/database-performance-analysis/http://www.codefutures.com/products/firestorm/editions/oem/http://www.codefutures.com/architect/http://www.codefutures.com/products/firestorm/editions/http://www.codefutures.com/products/firestorm/download/http://www.codefutures.com/products/firestorm/tutorial/http://www.codefutures.com/products/firestorm/benefits/http://www.codefutures.com/products/firestorm/faq/http://www.codefutures.com/products/firestorm/architecture/http://www.codefutures.com/products/firestorm/editions/matrix.htmlhttp://www.codefutures.com/dao-benefits/http://www.codefutures.com/products/firestorm/http://www.codefutures.com/products/firestorm/http://www.codefutures.com/dbshards/