Data access object
In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism. By mapping application calls to the persistence layer, the DAO provides some specific data operations without exposing details of the database. This isolation supports the Single responsibility principle. It separates what data access the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO).
Although this design pattern is equally applicable to the following: (1- most programming languages; 2- most types of software with persistence needs; and 3- most types of databases) 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[1] "Core J2EE Patterns" for that platform).
open source ORM products include Doctrine, Hibernate, iBATIS and JPA implementations such as Apache OpenJPA.
Disadvantages
Potential disadvantages of using DAO include leaky abstraction,[citation needed] code duplication, and abstraction inversion. In particular, the abstraction of the DAO as a regular Java object can hide the high cost of each database access, and can also force developers to trigger multiple database queries to retrieve information that could otherwise be returned in a single operation with normal SQL set operations. If an application requires multiple DAOs, one might find oneself repeating essentially the same create, read, update, and delete code for each DAO. This boiler-plate code may be avoided however, by implementing a generic DAO that handles these common operations.[2] Time consumption is moderate.[citation needed]
Tools and frameworks
- ODB compiler-based object-relational mapping (ORM) system for C++
- ORMLite Lightweight Object Relational Mapping (ORM) Framework in Java for JDBC and Android[3]
- Microsoft Entity Framework
See also
References
- ^ "Core J2EE Patterns - Data Access Objects". Sun Microsystems Inc. 2007-08-02.
- ^ See http://www.ibm.com/developerworks/java/library/j-genericdao/index.html for workarounds
- ^ Hodgson, Kyle; Reid, Darren. ServiceStack 4 Cookbook. Packt Publishing Ltd. p. Chapter 4. ISBN 9781783986576. Retrieved 22 June 2016.