DAO - best practices

Discussion in 'Java' started by R, Apr 18, 2006.

  1. R

    R Guest

    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
     
    R, Apr 18, 2006
    #1
    1. Advertising

  2. R

    PremKumar Guest

    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
     
    PremKumar, Apr 18, 2006
    #2
    1. Advertising

  3. R

    Guest

    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.
     
    , Apr 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Izvra
    Replies:
    0
    Views:
    544
    Izvra
    Dec 23, 2003
  2. karim
    Replies:
    0
    Views:
    467
    karim
    Jul 13, 2003
  3. John Dalberg
    Replies:
    3
    Views:
    575
    samuelhon
    Nov 16, 2006
  4. lightning
    Replies:
    1
    Views:
    403
    EricF
    Jul 8, 2008
  5. Chicken McNuggets

    Best book on C gotchas and best practices?

    Chicken McNuggets, Jul 31, 2013, in forum: C Programming
    Replies:
    9
    Views:
    270
    Fred J. Tydeman
    Aug 5, 2013
Loading...

Share This Page