You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Craig R. McClanahan" <cr...@apache.org> on 2001/03/12 21:48:44 UTC

Re: Question about struts application model (DataSource, Business Log ic beans)


On Mon, 12 Mar 2001, Carles Pi-Sunyer wrote:

> Hi,
> 
> I'm using Struts for a new application that I'm developing. I have a
> question about the separation between the Action classes and the Business
> Logic beans. 
> 
> My Business Logic beans are making database accesses to manipulate the
> underlying data model. I am planning on using the struts db connection pool,
> which is supplied through the DataSource. My problem is that access to the
> DataSource is through the servlet.getDataSource() call. How do I make the
> Business Logic beans unaware of the servlet/http layer (as suggested in the
> developers guide) while still making the DataSource available to the
> Business Logic beans? Do I have to pass a reference to the DataSource on
> every call the Business Logic beans (not an option that I like), or is there
> a cleaner way to do this? I also have a similar issues with logging
> services.
> 
> I believe that a common way to solve this problem is to bind the DataSource
> to a jndi service. I am using tomcat 3.2.1, and I don't believe that this
> functionality is supplied in either Tomcat or Struts.
>

Binding the data source to a JNDI context is definitely attractive -- and
it is also the approach that is suggested if you are running in a
J2EE-compatible application server (which is required to support this
approach).  In such a scenario, you would configure the data source using
the tools provided by your app server, rather than declaring it in
struts-config.xml, and you'd define a <resource-ref> entry in your web.xml
file to link the data source you need to the facilities set up by your app
server.

Tomcat 3.2 does not support a JNDI context for this kind of thing, but
Tomcat 4.0 does.  By default, it uses the data source and transaction
implementations from Tyrex (http://tyrex.exolab.org), but you can also
create your own object factories if you want to do something different.

 
> Thank You,
> Carles
> 

Craig