struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "V. Cekvenich" <v...@users.sourceforge.net>
Subject Using data-source with ActionForm
Date Sun, 29 Sep 2002 03:02:45 GMT
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:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message