Hi Jeff I'm at the same point as you in developing an app. I'm going to use the Jakarta commons-dbpc & commons-pool.
I find your description of "passing DataSource into model at init time" ambiguous - surely you don't have any model components hanging around in sessions or application scope? You must mean when your Action perform() invokes a model component by its constructor? From general discussion on this list your assumption about the 'right way' would be correct - pass all you need into the model components as parameters. I did read about a "Register" design pattern on http://martinfowler.com/isa/ , where objects (your configuration singleton class in model-land?) are held in a hashtable indexed by thread Id for thread safety, but the author then said he didn't like this since "global data is inherently dangerous". Doing this would then couple your model and your control layers together, which you didn't want to do - they would both have to know where it's stored. Adam Jeffrey Keays wrote: > Hi All, > > I am a relative struts newbie, using the following: Struts 1.0.2, Sun > JDK1.3.1, Tomcat3.3, MySQL, mm.mysql jdbc driver. > > In my application, the only components that need JDBC are model > components, which I am trying to keep decoupled from any one > particular front-end for the sake of reusability. > > I would like to use the connection pooling available in Struts by > passing a javax.sql.DataSource into model-land at initialization time. > Unfortunately I have not found a good way to do that. > > I have tried the obvious method of writing a simple servlet (subclass > of HttpServlet) and set it up in web.xml to load AFTER Struts > ActionServlet when the webapp is started. I hoped I could somehow get > the DataSource via ActionServlet.findDataSource(), the only > widely-documented way to get it. I would then pass this DataSource to > a configuration singleton class in model-land for use from there. > > I was hoping that ActionServlet would leave a reference to itself in > the ServletContext, but alas. It appears that the only way to have > access to the ActionServlet, and hence the DataSource, is to be an > Action invoked by it. > > Would the 'right way' be to subclass ActionServlet and initialize my > model from init() after calling the superclass? What it the right way > to (generically) initialize model components with things like > DataSource, log sink, parameters & resources from the struts / webapp > framework? > > --Jeff > > P.S. as an OT aside, could anyone recomend a decent OSS java > connection-pooling implementation? (I have already ruled out PoolMan) > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>