Dan,

The way I would solve this is with a one-to-many relationship, and what
is termed "complex" models in Torque speak.   Basically as part of the
construction of the "owning" DAO, in your case Customer, it builds a
collection (usually a simple Vector) of dependent objects, which are
called with a get<OtherTable>() method, in this case
"customerDaoImpl.getContacts();".

Its not a good idea to make them call methods of each other, but placing
groups into a collection inside a composite object is fine, if you
wanted to make it even more bullet-proof, use interfaces to abstract all
DAOs, as long as the contained DAO object implements the interface all
will keep spinning. 


Best regards,

Cameron Gray
Operations Director, UltraSpeed UK Limited

Tel/Fax: 0800 689 9898 W: www.ultraspeed.co.uk
AIM: UltraSpeedNetOps ICQ: 159796008

Murphy's Third Law: In any field of scientific endeavor, anything that
can go wrong will go wrong.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dan Allen
Sent: 09 December 2003 21:45
To: [EMAIL PROTECTED]
Subject: [Struts-apps] question on DAO design

THE QUESTION:

Does it (make sense|is it general practice) to call one DAO from within
another DAO?

I was hoping that someone on this list could help me free myself from
the shackles of confusion.  At my job, I am developing a web application
using JDBC (required unfortunately) to abstract the data access but I am
running into a problem, one I realize would be solved by Hibernate, but
interesting to attempt to tackle anyway.

Assume I have two entities in my system (amoungst many others), Contacts
and Customers.  Contacts are the end user, and the customers are the
accounts (think of it like online banking).  The contacts can manipulate
these customer accounts by ordering, viewing, requesting service.

Naturally I made a ContactDAO which retrieves contacts, profile
information, etc.  My next object is CustomerDAO which retrieves
information about the customer (the agency name, mailing address, etc).
A contact can be associated with many customers and vice versa, each
relationship represented by a role.  Naturally I created a
CustomerContact object which links these two entities:

 +----------------+
 | CustomerContact|
 + ---------------+
 | roleName       |
 | contact        |
 | customer       |
 +----------------+

Here comes my problem.  My ContactDAO takes care of the data access to
the contact table.  The CustomerDAO however contains methods which must
get at the contact data with queries such as getContactsForCustomer and
getCustomersForContact which return CustomerContact[] arrays (since the
ContactDAO shouldn't have methods dealing with the customer relationship
since it is not a dependency of a contact, but is of a customer).  In my
CustomerDAO, to create the CustomerContact transfer object, I need to
talk to my ContactDAO to get that information, if I don't want to
duplicate the calls in the CustomerDAO.

In short, at some point, one DAO needs to use the methods in the other
DAO since there is cross over.  The main confusion here is how to deal
with information that seems to want to be in both DAOs.

THE QUESTION:

Does it (make sense|is it general practice) to call one DAO from within
another DAO?

Thanks,

Dan

--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Daniel
Allen, <[EMAIL PROTECTED]> http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Microsoft's Law of Software Engineering: 
Don't worry if it doesn't work right. 
If everything did, we'd be out of a job.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for
IBM's Free Linux Tutorials.  Learn everything from the bash shell to sys
admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Struts-apps mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/struts-apps




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Struts-apps mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/struts-apps

Reply via email to