0% found this document useful (0 votes)
86 views

DAO - Data Access Object - Design Pattern

The document discusses the Data Access Object (DAO) design pattern. The DAO pattern separates persistence logic from other application logic, making the persistence logic more flexible to modify without disturbing other logic. A DAO class contains logic to establish and release database connections and perform operations like update, delete, and insert. It can be implemented using technologies like JDBC or Hibernate. Business components access the DAO class to perform persistence operations rather than containing the persistence logic themselves. An example shows a BaseDAO class with common methods and a BComp1 class that uses the BaseDAO to insert and fetch records.

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

DAO - Data Access Object - Design Pattern

The document discusses the Data Access Object (DAO) design pattern. The DAO pattern separates persistence logic from other application logic, making the persistence logic more flexible to modify without disturbing other logic. A DAO class contains logic to establish and release database connections and perform operations like update, delete, and insert. It can be implemented using technologies like JDBC or Hibernate. Business components access the DAO class to perform persistence operations rather than containing the persistence logic themselves. An example shows a BaseDAO class with common methods and a BComp1 class that uses the BaseDAO to insert and fetch records.

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JAVA Means DURGA SOFT

DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 1
JAVA Means DURGA SOFT

Enterprise Level Design Patterns

DAO (Data Access Object) Design Pattern

Problem: In any project if persistence is combined with the other logics of the application (like
business logic, service logic etc) then persistence logic will not become flexible to modify i.e. the
modifications done in persistence logic may disturb other logics of the application.

Solution: Use DAO design pattern.

Def: The java class or component that separates persistence logic from other logics of the
application to make persistence logic as flexible logic to modify is called as DAO

 Generally DAO class or contains:


 Logic to establish the connection
 Logic to release the connection
 Logic to perform persistence operations like update, delete, insert etc
 Some transaction management code (if require)
 We can develop this DAO class/ component using any persistence logic like JDBC,
Hibernate, EJB entity bean component etc.
 A single DAO class/ component can be used by all business components or each
business component can contain their own DAO class/ component. But it is always
recommended to use separate DAO class/ component for each business component.

DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 2
JAVA Means DURGA SOFT

Ex:

// BaseDAO.java

public class BaseDAO

public static Connection getConnection()

----

----

public int insert(-,-)

----

----

public List fetch()

----

----

DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 3
JAVA Means DURGA SOFT

public static void closeConnection()

----

----

public class BComp1

public BComp1()

Connection con =BaseDAO.getConnection();

public void insertRecords()

----

con.insert(-,-);

----

public void fetchRecords()

----

con.fetch(-);

----

}
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 4
JAVA Means DURGA SOFT

DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 5
JAVA Means DURGA SOFT

DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 6

You might also like