DAO - best practices

R

R

Hi All,

I know this is a little bit OT

Suppose I have 2 tables customers and products, customer can buy many
products, product can be bought by many customers - typical n:m
relationship so 3rd table is a must: i.e. purchases

So I need 3 DAO: ProductDAO, CustomerDAO and PurchaseDAO.

How do you deal with i.e. reports - table joins, left joins or
statistics (group by, max, min etc)?

do you create DAOs for that? (especially table joins - probably not)

raports and statistics from i.e. 7 tables can be only read-only, so
insert, update, delete methods
are inadequate.

thanks in advance for shedding some light on this
best regards
R
 
P

PremKumar

Hi,
Yep, 3 tables needed; for customer details, product details and
purchase details.
No need for U to have 3 DAO's

In one DAO you can get all the detials U need like;
pick list for products
pick list for customers
for repo's etc.,

Cheers
 
R

richardsosborn

you need to change your thinking. DAO is an intersection between DB
and the java code you're writing. you should think if it as the person
coming into it after you for the first time will see it.

your method names, as the last poster said, should start to crossover
from describing the business action performs, to which database
interaction needs to take place. ("pickProductList()" as opposed to
"pickListFromProductItemsTable()") this is the point of DAO.

if you want another layer of abstraction, i've seen projects which
start to describe which queries or database actions will be performed
(IE "callPickListForProductItems()"). and even then contain these in a
specialized class for each database vendor, in case your application
would re-platform.

but the pattern serves you, not the other way around. be aware of the
future and utilize as much or as little as you think you will need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top