Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> J2EE Design Patterns >>> Data Access Object >>> DAO A simple example and guide
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : ISHTEK
Title :
DAO Data Access Object
Description : Advantages Discussed
More...


Written By : ISHTEK
Title :
Business Delegate
Description : Advantages or Benefits discussed
More...

Tags/Keywords : Data Access Object, DAO, Data, Access, Object, J2EE Design Patterns, Example, Code, Tutorial, Article
Author : Amit
Date (Year/Month/Date): 2009-01-25 Data Access Object - A J2EE Design Pattern explained with an example

Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this 
as it is without appropriate evaluation to their, so to say, 
specific programming context.

This page intends only to provide bit and piece of known ways  for
doing some sort of example and may not be fit for any other purpose.

Advertisement :
DAO - Data Access Object - A J2EE Design Pattern to isolate client/user from Persistence API, thus making no change in client code, in case there are changes in storage or persistence implementation. How to design application so as to achieve this functionality of DAO? Let us explore this possibility by a sample case study. Our objective is to make client code (user of database/ persistence API), compilation free, in case there is a major change in storage/database/ persistence API (such as ORM-Object Relational Mapping tools). Please write your suggestions / comments on this Page. I can remember a Java design Pattern - Factory pattern that returns different implementation of an Interface, based on some input parameter. So we shall use Factory design pattern as an interfacing between Client code (it can be business service, POJO or Servlet code etc.) and persistence layer (it can be JDBC, Hibernate, iBatis, or any other ORM implementations). Factory Pattern requires at least two major parts, one is an interface and other is an abstract class. We define this interface as follows: 1. EmployeeDAO.java ------------------------------------------------------------------------- public interface EmployeeDAO { public void findEmployee(int id) throws DatabaseException; public void deleteEmployee(int id) throws DatabaseException; public Employee saveEmployee(Employee employee) throws DatabaseException; public Employee updateEmployee(Employee employee) throws DatabaseException; .... .... } ------------------------------------------------------------------------- 2. An abstract class as follows: DAOFactory.java ------------------------------------------------------------------------- public abstract class DAOFactory { static int HIBERNATE_DAO_FACTORY = 1; protected DAOFactory() { } public static DAOFactory getInstance(int n) { if(n == HIBERNATE_DAO_FACTORY) return new HibernateDAOFactory(); else return null; } public abstract EmployeeDAO getEmployeeDAO(); ..... ..... } ------------------------------------------------------------------------- And a constants Java interface as follows: 3. Constants.java ------------------------------------------------------------------------- public interface Constants { int DAO_INDENTIFIER = 0; //For Hibernate as ORM Tool for this Application .... } ------------------------------------------------------------------------- Major parts/classes from users/client perspective is as follows: Those parts, that are ticked in this above class diagram (Created using ArgoUML) are prone to change, in case there is a change in persistence implementation, like from Hibernate to JDBC, or from JDBC to iBatis and if there is any change in business methods like findEmployee to locateEmployee etc. Implementation of the specific Factory implementation like factory for Hibernate , factory for iBatik etc are left to the visitor/reader of this writing as an exercise. We shall be discussing this in coming articles/writing. If interested, you can reply/write your ideas of implementing this Factory implementation for Hibernate. Thanks.
Advertisement :
Author of this article/writeup has expressed his/her willingness
to help or guide users with any technical difficulties he/she faces while working with the example code environment setting up, running and resolving any such exception raised during compile or at runtime. You may ask for any technical doubt or seek technical help related to this article by using following form to reach for technical help from the Author for FREE. This article's Author shall be reading your request and responding within reasonable time (no resolution timeframe defined as such).


	
Are you interested in solving a very interesting Technology Stack while Playing this Game          

Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
25,20
Enter bigger number from above :*
Home >>> J2EE Design Patterns >>> Data Access Object >>> DAO A simple example and guide
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
12,32
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed materials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.

By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or 
downloading any materials, you agree to and are bound by the terms of use 
described in this page and Usage Terms and Conditions. 
If you do not agree to all of 
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this 
website in any manner. If you are using the website on behalf of your 
employer, you represent that you are authorized to accept these Terms of Use 
on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any 
of these information, please refer original content/documentation from respective sources. 
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.