You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Darren Hall <dh...@utrs.com> on 2006/09/11 21:03:55 UTC

DAO and getDataSource

Hopefully this will be a quick question.

I'm using struts 1.2.9 and I need to implement a database connection for my
web application and wanted to use a standard DAO pattern. I noticed that
struts provides a mechanism for implementing datasource configuration in the
struts-config file and in my online searches I found many examples that used
getDataSource() to retrieve the datasource and thereby get a database
connection. However I notice that in the struts documentation it says:
"Ideally, the business logic layer should encapsulate the data access
details, including acquiring a database connection. However, some older
application designs expect that the caller be able to provide a database
connection or DataSource instance. When you need to access a legacy design,
the Struts DataSource manager can make it easy for your Action class to
produce these resources on demand." 
And also - 
"It is preferred that data connectivity be handled directly by the business
classes, usually via JNDI. The Struts DataSource manager should only be used
with legacy business classes that don't provide their own connectivity. When
possible, we strongly recommend use of the standard DAO pattern, so that the
Action classes do not need to know anything about the persitence mechanism.
The DataSource manager is being retained in Struts 1.x for backward
compatibility but may not be retained in Struts 2.x or later."

So, should I use the datasource functionality provided in struts, or should
I "roll my own" database connection solution by creating a datasource
factory that can be used to retrieve connections?

Thanks,

Darren


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org