Content deleted Content added
ClueBot NG (talk | contribs) m Reverting possible vandalism by 211.128.72.49 to version by Kku. Report False Positive? Thanks, ClueBot NG. (2935939) (Bot) |
rm whitespace |
||
(46 intermediate revisions by 38 users not shown) | |||
Line 1:
{{Short description|Abstract interface to a computer database}}
{{About|the software design pattern|the Microsoft library|Jet Data Access Objects}}
In [[
Although this [[design pattern]] is
{{cite web
| title = Core J2EE Patterns - Data Access Objects
| publisher = Sun Microsystems Inc.
| url = http://www.oracle.com/technetwork/java/dataaccessobject-138824.html
| date = 2007-08-02
}}</ref> "Core J2EE Patterns"
This object can be found in the [[Data_access_layer|Data Access layer]] of the [[Multitier_architecture|3-Tier Architecture]].
There are various ways in which this object can be implemented:
* One DAO for each table.
* One DAO for all the tables for a particular DBMS.
* Where the SELECT query is limited only to its target table and cannot incorporate JOINS, UNIONS, subqueries and Common Table Expressions (CTEs)
* Where the SELECT query can contain anything that the DBMS allows.
== Advantages ==
[[Unit testing]] the code is facilitated by substituting the DAO with a [[test double]] in the test, thereby making the tests non-dependent on the persistence layer.▼
Using data access objects (DAOs) offers a clear advantage: it separates two parts of an application that don't need to know about each other. This separation allows them to evolve independently. If business logic changes, it can rely on a consistent DAO interface. Meanwhile, modifications to persistence logic won't affect DAO clients.<ref>{{Cite web |date=2022-08-03 |title=Data Access Object(DAO) Design Pattern |url=https://www.digitalocean.com/community/tutorials/dao-design-pattern |access-date=2024-07-08 |website=DigitalOcean |language=en-US}}</ref><ref>{{Cite web |date=2017-08-26 |title=Data Access Object(DAO) Design Pattern |url=https://www.geeksforgeeks.org/data-access-object-pattern/#8-advantages-of-the-data-access-object-designdao-pattern |access-date=2024-07-08 |website=GeeksforGeeks |language=en-US}}</ref>
In the non specific context of the [[Java (programming language)|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. Technologies like [[Java Persistence API]] and [[Enterprise JavaBeans]] come built into application servers and can be used in applications that use a JavaEE application server. Commercial products like [[TopLink]] are available based on [[Object-relational mapping]] (ORM). Popular open source ORM products include [[Doctrine (PHP)|Doctrine]], [[Hibernate (Java)|Hibernate]], [[iBATIS]] and JPA implementations such as [[Apache OpenJPA]].▼
▲All details of storage are hidden from the rest of the application (see [[information hiding]]). [[Unit testing]]
== Disadvantages ==▼
Potential disadvantages of using DAO include [[leaky abstraction]],{{Citation needed|reason=What kind of leak?|date=August 2014}} [[Duplicate code|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.<ref>See http://www.ibm.com/developerworks/java/library/j-genericdao/index.html for workarounds</ref> Time consumption is moderate.{{Citation needed|date=December 2014}} ▼
▲In the
▲
▲== Disadvantages ==
▲Potential disadvantages of using DAO include [[leaky abstraction]],{{Citation needed|reason=What kind of leak?|date=August 2014}} [[Duplicate code|code duplication]], and [[abstraction inversion]]. In particular, the abstraction of the DAO as a regular Java object can
Note that these disadvantages only appear when you have a separate DAO for each table and the SELECT query is prevented from accessing anything other than the target table.
== Tools and frameworks ==
* [[ODB (C++)|ODB]] compiler-based [[
* ORMLite: Lightweight
* [[Entity Framework|Microsoft Entity Framework]]
* DBIx::Class [[object–relational mapping]] (ORM) module for [[Perl]]
* TuxORM: Simple [[object–relational mapping]] (ORM) library in Java for JDBC
* [[Persist (Java tool)]] Java-based [[object–relational mapping]] and data access object tool
== See also ==
Line 40 ⟶ 47:
* [[Data access layer]]
* [[Service Data Objects]]
* [[Object–relational mapping]]
== References ==
{{Reflist}}
{{Design Patterns Patterns}}
[[Category:Architectural pattern (computer science)]]
[[Category:Software design patterns]]
|