Data Access Object
Encyclopedia
In computer software
, a data access object (DAO) is an object
that provides an abstract interface
to some type of database
or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer. This isolation separates the concerns
of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS
, database schema, etc. (the implementation of the DAO).
This design pattern
is equally applicable to most programming languages, most types of software with persistence needs and most types of database, but it is traditionally associated with Java EE
applications and with relational databases accessed via the JDBC API because of its origin in Sun Microsystems' best practice guidelines ("Core J2EE Patterns") for that platform.
Changing business logic can rely on the same DAO interface, while changes to persistence logic do not affect DAO clients as long as the interface remains correctly implemented.
In the specific context of the Java
programming language, Data Access Objects as a design concept can be implemented in a number of ways. This can range from a fairly simple interface that separates the data access parts from the application logic, to frameworks and commercial products.
DAO coding paradigms can require some skill. Use of technologies like Java persistence technologies
and JDO
ensures to some extent that the design pattern is implemented. Technologies like Enterprise JavaBeans come built into application servers and can be used in applications that use a JEE application server. Commercial products like TopLink
are available based on Object-relational mapping
(ORM). Popular open source ORM products include Hibernate
, Ebean
, pureQuery, iBATIS
and Apache OpenJPA
.
The expected benefit of use of Data Access Objects in a Java scenario is:
Computer software
Computer software, or just software, is a collection of computer programs and related data that provide the instructions for telling a computer what to do and how to do it....
, a data access object (DAO) is an object
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
that provides an abstract interface
Interface (computer science)
In the field of computer science, an interface is a tool and concept that refers to a point of interaction between components, and is applicable at the level of both hardware and software...
to some type of database
Database
A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...
or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer. This isolation separates the concerns
Separation of concerns
In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...
of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS
Database management system
A database management system is a software package with computer programs that control the creation, maintenance, and use of a database. It allows organizations to conveniently develop databases for various applications by database administrators and other specialists. A database is an integrated...
, database schema, etc. (the implementation of the DAO).
This design pattern
Design pattern
A design pattern in architecture and computer science is a formal way of documenting a solution to a design problem in a particular field of expertise. The idea was introduced by the architect Christopher Alexander in the field of architecture and has been adapted for various other disciplines,...
is equally applicable to most programming languages, most types of software with persistence needs and most types of database, but it is traditionally associated with Java EE
Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...
applications and with relational databases accessed via the JDBC API because of its origin in Sun Microsystems' best practice guidelines ("Core J2EE Patterns") for that platform.
Advantages
The advantage of using data access objects is the relatively simple and rigorous separation between two important parts of an application that can and should know almost nothing of each other, and which can be expected to evolve frequently and independently.Changing business logic can rely on the same DAO interface, while changes to persistence logic do not affect DAO clients as long as the interface remains correctly implemented.
In the specific context of the Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
programming language, Data Access Objects as a design concept can be implemented in a number of ways. This can range from a fairly simple interface that separates the data access parts from the application logic, to frameworks and commercial products.
DAO coding paradigms can require some skill. Use of technologies like Java persistence technologies
Java Persistence API
The Java Persistence API, sometimes referred to as JPA, is a Java programming language framework managing relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition....
and JDO
Java Data Objects
Java Data Objects is a specification of Java object persistence. One of its features is a transparency of the persistent services to the domain model. JDO persistent objects are ordinary Java programming language classes ; there's no requirement for them to implement certain interfaces or extend...
ensures to some extent that the design pattern is implemented. Technologies like Enterprise JavaBeans come built into application servers and can be used in applications that use a JEE application server. Commercial products like TopLink
TopLink
In computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....
are available based on Object-relational mapping
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...
(ORM). Popular open source ORM products include Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...
, Ebean
Ebean
Ebean is an object-relational mapping product written in Java. It is designed to be simpler to use and understand than JPA or JDO products.- Simple API :...
, pureQuery, iBATIS
IBATIS
iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java, .NET, and Ruby on Rails. In Java, the objects are POJOs . The mappings are decoupled from the application logic by packaging the SQL statements in XML configuration files...
and Apache OpenJPA
Apache OpenJPA
OpenJPA is an open source implementation of the Java Persistence API specification. It is an object-relational mapping solution for the Java language, which simplifies storing objects in databases. It is open source software distributed under the Apache 2.0 Licence.- History :Kodo, a Java Data...
.
The expected benefit of use of Data Access Objects in a Java scenario is:
- Improved efficiency and performance of the data layer since it is standard reusable software.
- Modifications can be made to the DAO implementation without altering other decoupled modules of the application.
See also
- Create, read, update and delete (CRUD)
- Data Access LayerData access layerA data access layer is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database....
- Data Transfer ObjectData Transfer ObjectData transfer object , is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database....
- Design Patterns (book)
- Object-relational mappingObject-relational mappingObject-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...
- Service Data ObjectsService Data ObjectsService Data Objects is a technology that allows heterogeneous data to be accessed in a uniform way. The SDO specification was originally developed in 2004 as a joint collaboration between BEA and IBM and approved by the Java Community Process...
External links
- Core J2EE Patterns - Data Access Object
- Data Access Objects versus Object Relational Mapping
- Inner Class strategy
Tools and Frameworks
- AuDAO Generator for JDBC DAO (MySQLMySQLMySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...
, OracleOracle DatabaseThe Oracle Database is an object-relational database management system produced and marketed by Oracle Corporation....
) and Google App EngineGoogle App EngineGoogle App Engine is a platform as a service cloud computing platform for developing and hosting web applications in Google-managed data centers. It virtualizes applications across multiple servers,...
datastore - CodeFutures (Firestorm/DAO) Generator for JDBC DAO, Spring DAO, Hibernate DAO
- ComtorDAO Data Access Object Library for java Data Access Object Library for java
- DB Solo EJB 3.0 DAO code generator
- EasyDriver Java libray to create queries in order to be used in a DAO context.
- IBM pureQuery data access platform
- JingDAO DAO framework
- MDAOG DAO code generator for PostgreSQLPostgreSQLPostgreSQL, often simply Postgres, is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, MS Windows and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, and is thus free and open source software...
databases - nHydrate DAO/DTO framework, code generator for .NET
- ODBODB (C++)ODB is an object-relational mapping system for the C++ language. It allows an application developer to persist C++ objects to a relational database without having to deal with tables, columns, or SQL and without manually writing any mapping code...
compiler-based object-relational mappingObject-relational mappingObject-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...
(ORM) system for C++ - ORMLiteORMLiteORMLite is an open source software framework that provides lightweight object relational mapping between Java classes and SQL databases. It supports JDBC databases as well as Android mobile platform...
Lightweight Object Relational Mapping (ORM) Framework in Java for JDBC and Android - PerfectJPattern Open Source Project, Provides componentized implementation of the DAO Pattern in Java (JPA, Hibernate and Spring)
- Persist ORM tool
- Simplest ORM
- EclipseLink Delivers a comprehensive open-source Java persistence solution addressing relational, XML, and database web services.