Using data-source with ActionForm

2002-09-28 Thread V. Cekvenich

Vincent, in response to:

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg42254.html

(others asked related questions on JDBC / connection pool, closing, etc.)

You are right, you do not do it in a getter in a setter.
Mostly you have a bean. And even the bean delegates to DAO.
DAO handles the connection, etc.

A good practices is: a property has a getter/setter in a bean, and a 
bean has a DAO it delegates to.

You could have a DAO with a class/static initialize that gets the data 
source.
I do not link philosophical answers so here is a  code sample, note use 
of static:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/basicPortal_07/src/org/commons/DAO/BasicDAOImpl.java?rev=1.1.1.1&content-type=text/vnd.viewcvs-markup

It uses DBCP from Jakarta commons connection pool with PostgreSQL from 
DBExperts.net, a FREE full ANSI SQL compliant DB, but you get the point 
of how to use a static class initialize to get a handle to a data source 
so you can look up the data source once, and then just dish out connection.

Also I use rowset over resultset, which makes it very easy to close, and 
destroy, unlike resultset. (con.close,rs.close, stmnt.close, plus it 
loses data on a connection disconect)
Rowset also does not reduces need for GC generated by VO/DTO and 
collections, since a disconnected rowset has the values. I use an open 
source rowset from sourceforge called jxutil.

Also, at basicPortal.sf.net you can download for free a 350 page book a 
bit more advanced that talks about db quite a bit.

hth,
V.

ps: A benefit of MVC is modular, hence each layer is unit testable, such 
as a bean that delegates to DAO interface, which above also enables.

ps2: Answer to what is the most popular hands on training class and who 
teaches it?
http://www.mail-archive.com/mvc-programmers%40basebeans.com/msg00242.html




--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Using data-source with ActionForm - MVC2

2002-09-24 Thread Galbreath, Mark

No problem, but there is still no widely recognized term, "MVC2."

-Original Message-
From: Vincent Berruchon [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 24, 2002 12:07 PM
To: Struts Users Mailing List
Subject: Re: Using data-source with ActionForm - MVC2


Just a word about MVC2 and what I've read about it:
  MVC2 is the evolution of the MVC model, the main difference seem to be 
  the preference for an unique controller module (a unique controller 
servlet with Struts),
because in first versions of the Model View Controller, MVC, most of the 
time many modules acted as controllers.
MVC2 is also called Model 2...

I'm not an expert, but it seems that MVC2 means something even if we 
often talk now about MVC in place of MVC2

Thanks for your answer
Vincent


Galbreath, Mark wrote:
> First, there's no such thing as "MVC2 Model."  It's "MVC" or, when applied
> to web apps, "Model 2."  This is clearly explained in the Struts'
> Introduction on the Jakarta website.
> 
> Accessing the database from an ActionForm does not violate MVC, but it
does
> violate standard usage of JavaBeans and is generally not a good idea from
a
> maintenance perspective.  If you need to pre-set an ActionForm's state,
have
> your associated Action class do it by calling an EJB session bean or DAO
> (data access object). Read the Struts User Guide and get hold of a copy of
> (at least) Alur, et al, "Core J2EE Patterns" (Sun/PrenticeHall 2001).
> 
> Mark
> 
> -Original Message-
> From: Vincent Berruchon [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 20, 2002 11:12 AM
> To: Struts Users Mailing List
> Subject: Re: Using data-source with ActionForm
> 
> 
> SHould I avoid to access database in the getXXX methods of an ActionForm 
> to respect MVC2 model?
> 
> Vincent Berruchon wrote:
> 
>>Hello,
>>I'm a newbie with Struts, I'd like to know how I could smartly use 
>>data-source to fill things like "select" drop down combo in my forms.
>>
>>here what I'm trying to do, can you tell me if I'm wrong:
>>
>>I'v defined a data-source in struts-config.xml to use a mySql DB.
>>I'd like to get data from this DB to fill inputs fields in my forms.
>>
>>So I suppose I could get a connection in data-source pool in each of the 
>>   "getMyProperty" of my actionForm methods and get the 
>>data that will fill HTML/JSP input...
>>
>>something like that:
>>   DataSource dataSource = (DataSource)
>>   servlet.getServletContext().getAttribute("mysql");
>>   Connection conn = dataSource.getConnection();
>>
>>but it seems to be a bit expensive to get a connection in each "getXXX" 
>>methods...(i'll do the same things several times for one actionForm 
>>use/1 request) where can I place the getConnection to use it in methods 
>>of my actionForm (1 connection for 1 actionForm use/1 request)
>>
>>Tell me if there's something I didn't understand.
>>
>>Thanx
>>Vincent
>>
>>
>>-- 
>>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]>
> 
> --
> 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]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Using data-source with ActionForm - MVC2

2002-09-24 Thread Vincent Berruchon

Just a word about MVC2 and what I've read about it:
  MVC2 is the evolution of the MVC model, the main difference seem to be 
  the preference for an unique controller module (a unique controller 
servlet with Struts),
because in first versions of the Model View Controller, MVC, most of the 
time many modules acted as controllers.
MVC2 is also called Model 2...

I'm not an expert, but it seems that MVC2 means something even if we 
often talk now about MVC in place of MVC2

Thanks for your answer
Vincent


Galbreath, Mark wrote:
> First, there's no such thing as "MVC2 Model."  It's "MVC" or, when applied
> to web apps, "Model 2."  This is clearly explained in the Struts'
> Introduction on the Jakarta website.
> 
> Accessing the database from an ActionForm does not violate MVC, but it does
> violate standard usage of JavaBeans and is generally not a good idea from a
> maintenance perspective.  If you need to pre-set an ActionForm's state, have
> your associated Action class do it by calling an EJB session bean or DAO
> (data access object). Read the Struts User Guide and get hold of a copy of
> (at least) Alur, et al, "Core J2EE Patterns" (Sun/PrenticeHall 2001).
> 
> Mark
> 
> -Original Message-
> From: Vincent Berruchon [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 20, 2002 11:12 AM
> To: Struts Users Mailing List
> Subject: Re: Using data-source with ActionForm
> 
> 
> SHould I avoid to access database in the getXXX methods of an ActionForm 
> to respect MVC2 model?
> 
> Vincent Berruchon wrote:
> 
>>Hello,
>>I'm a newbie with Struts, I'd like to know how I could smartly use 
>>data-source to fill things like "select" drop down combo in my forms.
>>
>>here what I'm trying to do, can you tell me if I'm wrong:
>>
>>I'v defined a data-source in struts-config.xml to use a mySql DB.
>>I'd like to get data from this DB to fill inputs fields in my forms.
>>
>>So I suppose I could get a connection in data-source pool in each of the 
>>   "getMyProperty" of my actionForm methods and get the 
>>data that will fill HTML/JSP input...
>>
>>something like that:
>>   DataSource dataSource = (DataSource)
>>   servlet.getServletContext().getAttribute("mysql");
>>   Connection conn = dataSource.getConnection();
>>
>>but it seems to be a bit expensive to get a connection in each "getXXX" 
>>methods...(i'll do the same things several times for one actionForm 
>>use/1 request) where can I place the getConnection to use it in methods 
>>of my actionForm (1 connection for 1 actionForm use/1 request)
>>
>>Tell me if there's something I didn't understand.
>>
>>Thanx
>>Vincent
>>
>>
>>-- 
>>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]>
> 
> --
> 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]>




RE: Using data-source with ActionForm

2002-09-20 Thread Galbreath, Mark

First, there's no such thing as "MVC2 Model."  It's "MVC" or, when applied
to web apps, "Model 2."  This is clearly explained in the Struts'
Introduction on the Jakarta website.

Accessing the database from an ActionForm does not violate MVC, but it does
violate standard usage of JavaBeans and is generally not a good idea from a
maintenance perspective.  If you need to pre-set an ActionForm's state, have
your associated Action class do it by calling an EJB session bean or DAO
(data access object). Read the Struts User Guide and get hold of a copy of
(at least) Alur, et al, "Core J2EE Patterns" (Sun/PrenticeHall 2001).

Mark

-Original Message-
From: Vincent Berruchon [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 20, 2002 11:12 AM
To: Struts Users Mailing List
Subject: Re: Using data-source with ActionForm


SHould I avoid to access database in the getXXX methods of an ActionForm 
to respect MVC2 model?

Vincent Berruchon wrote:
> Hello,
> I'm a newbie with Struts, I'd like to know how I could smartly use 
> data-source to fill things like "select" drop down combo in my forms.
> 
> here what I'm trying to do, can you tell me if I'm wrong:
> 
> I'v defined a data-source in struts-config.xml to use a mySql DB.
> I'd like to get data from this DB to fill inputs fields in my forms.
> 
> So I suppose I could get a connection in data-source pool in each of the 
>"getMyProperty" of my actionForm methods and get the 
> data that will fill HTML/JSP input...
> 
> something like that:
>DataSource dataSource = (DataSource)
>servlet.getServletContext().getAttribute("mysql");
>Connection conn = dataSource.getConnection();
> 
> but it seems to be a bit expensive to get a connection in each "getXXX" 
> methods...(i'll do the same things several times for one actionForm 
> use/1 request) where can I place the getConnection to use it in methods 
> of my actionForm (1 connection for 1 actionForm use/1 request)
> 
> Tell me if there's something I didn't understand.
> 
> Thanx
> Vincent
> 
> 
> -- 
> 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]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: Using data-source with ActionForm

2002-09-20 Thread Vincent Berruchon

SHould I avoid to access database in the getXXX methods of an ActionForm 
to respect MVC2 model?

Vincent Berruchon wrote:
> Hello,
> I'm a newbie with Struts, I'd like to know how I could smartly use 
> data-source to fill things like "select" drop down combo in my forms.
> 
> here what I'm trying to do, can you tell me if I'm wrong:
> 
> I'v defined a data-source in struts-config.xml to use a mySql DB.
> I'd like to get data from this DB to fill inputs fields in my forms.
> 
> So I suppose I could get a connection in data-source pool in each of the 
>"getMyProperty" of my actionForm methods and get the 
> data that will fill HTML/JSP input...
> 
> something like that:
>DataSource dataSource = (DataSource)
>servlet.getServletContext().getAttribute("mysql");
>Connection conn = dataSource.getConnection();
> 
> but it seems to be a bit expensive to get a connection in each "getXXX" 
> methods...(i'll do the same things several times for one actionForm 
> use/1 request) where can I place the getConnection to use it in methods 
> of my actionForm (1 connection for 1 actionForm use/1 request)
> 
> Tell me if there's something I didn't understand.
> 
> Thanx
> Vincent
> 
> 
> -- 
> To unsubscribe, e-mail:   
> 
> For additional commands, e-mail: 
> 
> 
> 
> 



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Using data-source with ActionForm

2002-09-20 Thread Vincent Berruchon

Hello,
I'm a newbie with Struts, I'd like to know how I could smartly use 
data-source to fill things like "select" drop down combo in my forms.

here what I'm trying to do, can you tell me if I'm wrong:

I'v defined a data-source in struts-config.xml to use a mySql DB.
I'd like to get data from this DB to fill inputs fields in my forms.

So I suppose I could get a connection in data-source pool in each of the 
"getMyProperty" of my actionForm methods and get the 
data that will fill HTML/JSP input...

something like that:
DataSource dataSource = (DataSource)
servlet.getServletContext().getAttribute("mysql");
Connection conn = dataSource.getConnection();

but it seems to be a bit expensive to get a connection in each "getXXX" 
methods...(i'll do the same things several times for one actionForm 
use/1 request) where can I place the getConnection to use it in methods 
of my actionForm (1 connection for 1 actionForm use/1 request)

Tell me if there's something I didn't understand.

Thanx
Vincent


--
To unsubscribe, e-mail:   
For additional commands, e-mail: