You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/07/22 18:55:02 UTC

when to populate dependent entities?

Subject: when to populate dependent entities?
From: "David Chu" <da...@aol.net>
 ===
I am quite confused about what seems to be a very generic operation.  I
really want to find the best practice for this situation.  Assume the
following model of the business:

(no ejbs)
company 1..* departments
department 1..* employee

I have my Action classes (the Model(?)) call a DataFactory object's method
getCompany() which in turn return CompanyBean objects.  They are populated
with companyName, companyAddress, etc. However, the list of DepartmentBean
objects for this CompanyBean is not populated because it would be expensive.
Also, at the time of calling getCompany(), it is unclear whether the list of
DepartmentBean objects will get used.

The problem is how do I implement CompanyBean.getDepartmentList() to only
retrieve the DepartmentBeans from the DataFactory when I need to?  In
particular:
    - CompanyBean.getDepartmentList()  is called from the jsp (the View)
    - I could solve the problem by having each CompanyBean maintain a
reference to the DataFactory... but I did not think this was correct OOD.
Thoughts?
    - The jsp should not have knowledge of the DataFactory, right?
    - Should I design for several Actions, some that use the DataFactory to
populate the DepartmentList and others that do not, depending on need?

You can imagine that this problem cascasdes down to encompass the getting of
the EmployeeBean list from the DepartmentBean as well.  What are good
solutions to this problem, or have I just confused everyone? ;)

Thanks so much for any input.

--
-david

------------------------------
David C. Chu
America Online
Network Tools Intern
------------------------------



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: when to populate dependent entities?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hi David,
it sounds like you need to do some use case analysis to work out exactly 
when you need to getCompanyBeanWithDepartments() and when you need to 
getCompanyBeanWithout()

Same for employee beans.

I wouldn't have the beans hang on to a factory reference - what if they 
fall over when trying to do something with the DB while in the JSP? You 
might have posted your error messages already.

Take care of the situation in the Action, so the JSP gets exactly what 
it needs.

Adam



Struts Newsgroup (@Basebeans.com) wrote:
> Subject: when to populate dependent entities?
> From: "David Chu" <da...@aol.net>
>  ===
> I am quite confused about what seems to be a very generic operation.  I
> really want to find the best practice for this situation.  Assume the
> following model of the business:
> 
> (no ejbs)
> company 1..* departments
> department 1..* employee
> 
> I have my Action classes (the Model(?)) call a DataFactory object's method
> getCompany() which in turn return CompanyBean objects.  They are populated
> with companyName, companyAddress, etc. However, the list of DepartmentBean
> objects for this CompanyBean is not populated because it would be expensive.
> Also, at the time of calling getCompany(), it is unclear whether the list of
> DepartmentBean objects will get used.
> 
> The problem is how do I implement CompanyBean.getDepartmentList() to only
> retrieve the DepartmentBeans from the DataFactory when I need to?  In
> particular:
>     - CompanyBean.getDepartmentList()  is called from the jsp (the View)
>     - I could solve the problem by having each CompanyBean maintain a
> reference to the DataFactory... but I did not think this was correct OOD.
> Thoughts?
>     - The jsp should not have knowledge of the DataFactory, right?
>     - Should I design for several Actions, some that use the DataFactory to
> populate the DepartmentList and others that do not, depending on need?
> 
> You can imagine that this problem cascasdes down to encompass the getting of
> the EmployeeBean list from the DepartmentBean as well.  What are good
> solutions to this problem, or have I just confused everyone? ;)
> 
> Thanks so much for any input.
> 
> --
> -david
> 
> ------------------------------
> David C. Chu
> America Online
> Network Tools Intern
> ------------------------------
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>