Forums Register Login

Relationship between tables in DAO pattern

+Pie Number of slices to send: Send
I use DAO pattern.
I wanna get data from 4 tables, which dto will I use ?
Create new dto content all attribute I need ?
and create new DAO interface, DAO implements class ?
Thanks for rely !
+Pie Number of slices to send: Send
If the 4 tables represent 4 INDEPENDENT entities, i believe you should create separate DTOs for each of them.
Ex:
Tables:
CONTINENT ( Name varchar , poupulation Integer);
COUNTRY (Name varchar, poulation Integer, Number literacyRate);
VILLAGE (Name varchar, population Integer, Number literacyRate);

You would have DTOs as follows:

class ContinentDTO {
String name;
int population;
//This would be a collection of Country DTO
Collection countries;


}

class CountryDTO {
String name;
int population;
double literacyRate;
//This would be a collection of Village DTO
Collection villages;

//this would refer to the continent DTO to which this country belongs
ContinentDTO continent;


}

class VillageDTO {
String name;
int population;
double literacyRate;

//this would refer to the country to which this village belongs
CountryDTO country;
}
+Pie Number of slices to send: Send
That is a good ideal but I wanna get data from 4 tables so that Object return contents attributes exist in 4 tables. Will i create new dto object
Example :
Have 4 tables : A, B, C, D with attribute A.a, B.b, C.c, D.d
"select A.a, B.b, C.c, D.d where ...."
which DAO object I can put in ?
+Pie Number of slices to send: Send
 

Originally posted by jaikiran pai:
If the 4 tables represent 4 INDEPENDENT entities, i believe you should



Who told you this? The purpose of a Transfer object is to transfer data between the data access layer and the client requesting the data. The Transfer Object has nothing to do with entities! A Transfer Object can simply be used to represent the data returned by the consolidation of many remote calls into a single call.

I think you should read the Design Pattern definition again ;-)
+Pie Number of slices to send: Send
Sorry, my thinking was wrong.
+Pie Number of slices to send: Send
You should create 4 DAOs for for 4 tables and probably a single DTO with the help of Data Transfer Object Assembler.

-Jignesh
+Pie Number of slices to send: Send
I agree in DAO pattern 1 Table map to a DAO. But my query section get data from 4 tables. How can u do ?
+Pie Number of slices to send: Send
Hello Huy,

You appear to be using FireStorm/DAO. You could look at the FAQ

http://www.codefutures.com/products/firestorm/faq/jdbc/complexqueries.html


FireStorm/DAO supports Table DAOs, View DAOs, Stored Procedure DAOs, and Custom SQL DAOs. Custom SQL DAOs can be used to expose pretty much any SQL statement as a DAO object (multi-table joins, bulk updates, etc.)
+Pie Number of slices to send: Send
PJ

FAQ does not say how we can relate result columns to getter/setter methods.

As an example if we have the first query:

SELECT a.*, b.* FROM a, b WHERE a.id = b.id AND b.install_date between ? and ?

How are we going to name setter/getter methods? (we may have fields with the same column name coming from different tables).

I am not able to find the answer for this.

Would you please forward me to a tutorial or a reference?

Siamak
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4370 times.
Similar Threads
How to implement DAO design pattern in Struts?
Designing DTO and ActionForm
Diff b/w Dao's and valueobjectpattern?
Session Bean + DAO
OO Design
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:50:37.