Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DAO design pattern and using it across multiple tables

Tags:

I'm looking for feedback on the Data Access Object design pattern and using it when you have to access data across multiple tables. It seems like that pattern, which has a DAO for each table along with a Data Transfer Object (DTO) that represents a single row, isn't too useful for when dealing with data from multiple tables. I was thinking about creating a composite DAO and corresponding DTO that would return the result of, let's say performing a join on two tables. This way I can use SQL to grab all the data instead of first grabbing data from one using one DAO and than the second table using the second DAO, and than composing them together in Java.

Is there a better solution? And no, I'm not able to move to Hibernate or another ORM tool at the moment. Just straight JDBC for this project.

like image 206
Casey Avatar asked Mar 24 '10 02:03

Casey


People also ask

What is use of DAO design pattern?

DAO Design Pattern is used to separate the data persistence logic in a separate layer. This way, the service remains completely in dark about how the low-level operations to access the database is done. This is known as the principle of Separation of Logic.

What kind of pattern is DAO?

The Data Access Object (DAO) pattern is a structural pattern that allows us to isolate the application/business layer from the persistence layer (usually a relational database but could be any other persistence mechanism) using an abstract API.

How does data access object DAO pattern abstract away the details of?

The Data Access Object ( DAO ) pattern abstract away the details of persistence in an application. Instead of having the domain logic communicate directly with the database, file system, web service, or any other persistence mechanism : The domain logic speaks to a DAO layer instead.

What type of methods does a DAO interface specify?

In software, a data access object (DAO) is a pattern 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.


1 Answers

I would agree with your approach. My DAOs tend to be aligned more at the object level, rather than from a DB Table perspective. I may manage more than one object through a DAO, but they will very likely be closely related. There is no reason not to have SQL accessing two tables living in one DAO.

And for the record, I have banished the acronym DTO from my vocabulary and code.

like image 168
pkananen Avatar answered Sep 29 '22 03:09

pkananen