This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relationship between tables in DAO pattern

 
Huy Hang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Huy Hang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jack Wiesenthaler
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ;-)
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, my thinking was wrong.
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should create 4 DAOs for for 4 tables and probably a single DTO with the help of Data Transfer Object Assembler.

-Jignesh
 
Huy Hang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree in DAO pattern 1 Table map to a DAO. But my query section get data from 4 tables. How can u do ?
 
Pj Murray
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Siamak Saarmann
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic