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/12 03:32:36 UTC

getDataSource, DAO pattern, and Struts

(reposted. Was "DAO and getDataSource" - however that post was made by doing
a reply to another message and simply changing the subject. I didn't realize
that this was thread hijacking. Please accept my apologies, and disregard
the earlier post.)

 

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 (this is due to the
fact that I will be using connection pooling as well as other datastores to
store application data, and want to decouple the data retrieval
implementation from the business objects as much as possible). 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

 


Re: Struts Model Layer in the MVC framework

Posted by Larry Meadors <lm...@apache.org>.
On 9/12/06, Ray Madigan <ra...@madigans.org> wrote:
> Is there an alternative to Spring Integration.  I have a project that I need
> to get a prototype out to the client FAST and I simply want to implement a
> Model layer with connection pooling.  I have gone to the Spring Framework
> site and I don't have the time to come up to speed on how to make this
> useful.  Any alternatives would be appreciated.

Ray,

At the risk of telling you what you don't want to hear: give yourself
4 hours with Spring.

If you still think it's too hard, fire up an IRC client and get on
#spring at irc.freenode.org or  #FunkyCodeMonkey at irc.darkmyst.org
and ask for help.

In a day, you will be further along in your project, better positioned
for future growth, and have less code to maintain than if you try to
roll your own.

Larry

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


Re: getDataSource, DAO pattern, and Struts

Posted by Angelo zerr <an...@gmail.com>.
Hello Darren,
I'm aggree with Larry. If you want you can see Architecture shema with
Service/DAO pattern in my open source project Gestcv at
http://gestcv.sourceforge.net/fr/architecture.html (sorry it's in frensh).
You can download the application WEB to see how I use Spring with Struts.

Regards Angelo

2006/9/12, Larry Meadors <lm...@apache.org>:
>
> On 9/11/06, Darren Hall <dh...@utrs.com> wrote:
> > 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?
>
> I wouldn't do either. If you can, use Spring to do this, and to wire
> together not just the DAO, but also to wire your services to the
> actions, and the DAOs to the services.
>
> Spring will give you simple abstraction if that is all you want, or
> all sorts of things beyond just that simple abstraction if you want.
>
> Larry
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts Model Layer in the MVC framework

Posted by Laurie Harper <la...@holoweb.net>.
Antonio Petrelli wrote:
> Ray Madigan ha scritto:
>> I have a project that I need
>> to get a prototype out to the client FAST and I simply want to 
>> implement a
>> Model layer with connection pooling.  I have gone to the Spring Framework
>> site and I don't have the time to come up to speed on how to make this
>> useful.  Any alternatives would be appreciated.
>>   
> 
> Use JNDI
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

Yep; to elaborate a little, the datasource support in Struts is a legacy 
feature dating back to a time when servlet containers didn't have 
consistent support for this. It's considered deprecated, and JNDI is the 
preferred approach.

On the topic of Spring, I second the recommendation and highly recommend 
investing the time to get to know it. Besides database connection 
handling and pooling, you'll also get declarative transaction management 
which is a huge win, and the DAO support layer will make writing your 
DAOs much easier and faster. You may actually end up saving yourself 
time :-)

L.


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


Re: Struts Model Layer in the MVC framework

Posted by Antonio Petrelli <br...@tariffenet.it>.
Ray Madigan ha scritto:
> I have a project that I need
> to get a prototype out to the client FAST and I simply want to implement a
> Model layer with connection pooling.  I have gone to the Spring Framework
> site and I don't have the time to come up to speed on how to make this
> useful.  Any alternatives would be appreciated.
>   

Use JNDI
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html



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


Struts Model Layer in the MVC framework

Posted by Ray Madigan <ra...@madigans.org>.
Is there an alternative to Spring Integration.  I have a project that I need
to get a prototype out to the client FAST and I simply want to implement a
Model layer with connection pooling.  I have gone to the Spring Framework
site and I don't have the time to come up to speed on how to make this
useful.  Any alternatives would be appreciated.

Thanks


-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com]On Behalf
Of Larry Meadors
Sent: Monday, September 11, 2006 6:43 PM
To: Struts Users Mailing List
Subject: Re: getDataSource, DAO pattern, and Struts


On 9/11/06, Darren Hall <dh...@utrs.com> wrote:
> 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?

I wouldn't do either. If you can, use Spring to do this, and to wire
together not just the DAO, but also to wire your services to the
actions, and the DAOs to the services.

Spring will give you simple abstraction if that is all you want, or
all sorts of things beyond just that simple abstraction if you want.

Larry

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


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


Re: getDataSource, DAO pattern, and Struts

Posted by Larry Meadors <lm...@apache.org>.
On 9/11/06, Darren Hall <dh...@utrs.com> wrote:
> 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?

I wouldn't do either. If you can, use Spring to do this, and to wire
together not just the DAO, but also to wire your services to the
actions, and the DAOs to the services.

Spring will give you simple abstraction if that is all you want, or
all sorts of things beyond just that simple abstraction if you want.

Larry

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