wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes DAO  Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "DAO  Pattern" Watch "DAO  Pattern" New topic
Author

DAO Pattern

Ganesh Kannusamy
Ranch Hand

Joined: Sep 15, 2005
Posts: 35
Hi All,
Can anyone explain DAO ( Data Access Object) Design pattern with examples,

Thanks,
Ganesh.K


Thanks,
Ganesh
sakalareddy tiyyagura
Greenhorn

Joined: Aug 18, 2005
Posts: 2
Context
Access to data varies depending on the source of the data. Access to persistent storage, such as to a database, varies greatly depending on the type of storage (relational databases, object-oriented databases, flat files, and so forth) and the vendor implementation.

Use a Data Access Object (DAO) to abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.

The DAO implements the access mechanism required to work with the data source. The data source could be a persistent store like an RDBMS, an external service like a B2B exchange, a repository like an LDAP database, or a business service accessed via CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets. The business component that relies on the DAO uses the simpler interface exposed by the DAO for its clients. The DAO completely hides the data source implementation details from its clients. Because the interface exposed by the DAO to clients does not change when the underlying data source implementation changes, this pattern allows the DAO to adapt to different storage schemes without affecting its clients or business components. Essentially, the DAO acts as an adapter between the component and the data source.

TransferObject
This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source.
[ January 16, 2006: Message edited by: sakalareddy tiyyagura ]
Ramasubbhu Allur Kuppusamy
Ranch Hand

Joined: Sep 16, 2005
Posts: 120
Thanks Sakalareddy for your lucid explanation. I benefitted from it.


Regards,<br />Ram.<br />SCJP 1.4
Ganesh Kannusamy
Ranch Hand

Joined: Sep 15, 2005
Posts: 35
That was really easy and understandable.

Thanks Sakalareddy , for your time.

Thanks.
K.Ganesh
Pj Murray
Ranch Hand

Joined: Sep 24, 2004
Posts: 194
Hi Ganesh,

As you might expect from a company that named its product after the DAO pattern, we have plenty of material that you might find interesting.



DAO benefits
http://www.codefutures.com/data-access-object/

Data Persistence Technology Comparison
http://www.codefutures.com/weblog/corporate/archives/2005/02/data_persistenc.html


DAO versus ORM
http://www.codefutures.com/weblog/andygrove/archives/2005/02/data_access_obj.html

Choosing a Java Persistence Strategy
http://www.codefutures.com/weblog/andygrove/archives/2005/01/choosing_a_java.html

You can also find out why we choose DAO as the focus of our Java persistence tool here:
http://www.codefutures.com/weblog/andygrove/archives/2005/07/early_product_s.html

Hopefully there's some material that you'll find useful.


PJ Murray -
Pj Murray
Ranch Hand

Joined: Sep 24, 2004
Posts: 194
Originally posted by sakalareddy tiyyagura:
Context
The DAO completely hides the data source implementation details from its clients. Because the interface exposed by the DAO to clients does not change when the underlying data source implementation changes, this pattern allows the DAO to adapt to different storage schemes without affecting its clients or business components.



This is one of the key reasons why you should consider using the DAO pattern. The most common data source will be relational databases, so the DAO allows you to swap between databases easily.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DAO Pattern
 
Similar Threads
Books/Examples/Links to use DAO Pattern
What is the best way to obtain a DataBase Connection ??
Suggestion on choosing a right pattern !!
Design Patterns for DAO & VO
EJB with DB Access