Data Access Layer

Using the Data Access Object Design (DAO) Pattern to Build a Data Access Layer (DAL)

A data access layer can be an imporant part of a software application. Business applications almost always need access to data from relational or object databases and the Java platform offers many techniques for accessing this data, regardless of whether a data access layer is used. The oldest, and most mature and reliable 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, Java Enterprise Edition (JEE) 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).

The Benefits of Using Data Access Objects for your Data Access Layer

The DAO design pattern provides a technique for separating object persistence and data access logic from any particular persistence mechanism or API, making it ideal for a data access layer. There are clear benefits to this approach from an architectural perspective. The DAO approach provides flexibility to change an application's persistence mechanism over time without the need to re-engineer application logic that interacts with the data access layer. 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 Spring. Without a data access layer 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 of JDBC, EJB, Spring DAO, and Hibernate DAO interfaces. A typical DAO interface for a data access layer 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 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.

Minimizing the Impact of Moving to DAO for you Data Access Layer

CodeFutures' objective is to minimize the importance of the main argument against using DAO: 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 Java 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.

Data Access Layer Code Generation

CodeFutures' solution to the manual coding problem is to automate the production of a DAO tier, as well as automating the actual implementation logic for whichever persistence framework is deemed appropriate for an application. This approach is easy to adopt because almost all databases use a standard language for defining their structure (SQL).

Product Information

 FireStorm/DAO Overview (PDF)
Provides brief (2 pages) introduction to FireStorm/DAO, the product benefits, and the product editions.

 FireStorm/DAO Architect Edition Overview (PDF)
Provides brief (2 pages) introduction to Architect Edtion, the product benefits, and using the Architect Edition with development teams.

 FireStorm/DAO Technical Overview (PDF)
Provides detailed technical overview of FireStorm/DAO.

Click on a product edition for more details or view an overview of the product range.

FireStorm/DAO Enterprise Edition generates JDBC, JDO, and EJB source code

Enterprise Edition

FireStorm/DAO Architect Edition allows custom code generators to be built

Architect Edition