commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Isaac Arias <iar...@yahoo.com>
Subject re: [DBCP] NamedDataSourceFactory to share DataSources between Servlet Contexts
Date Thu, 22 Aug 2002 23:16:22 GMT
Hi Matthew,

Thanks for your feedback. I agree with you 100%. It
makes more sense to use inheritance. I have made the
changes you proposed (except that I'm recycling the
dataSource variable) and compiled it. I tested it in
one of our development servers and it seems to work
fine (no reason why it shouldn't :).

I'm attaching the new file. Let me know if you think
about other ways of making this work. The
<global-naming-resources> in Tomcat 4.1 should make
this superfluous but until then...

Thanks again,

Ike
_________________________________
Isaac Arias - CTO
Tokenzone, Inc.

--- Matthew Firth <commons-dev@matthew.matera.net.au>
wrote:
> Isaac,
> 
> My thought would be that an extension of
> BasicDataSourceFactory is
> better than creating a paralell implementation.   If
> new resource
> parameters are supported by BasicDataSource &
> BasicDataSourceFactory (I
> have a list of them I plan to add sometime....) then
> this will work
> transparantly - i.e. without having to place
> identical changes into two
> separate classes.
> 
> I would have implemented it as below.  No idea if
> this code even compiles,
> let alone functions properly (and will probably be
> mangled by MTAs
> everywhere).  My apologies if there something
> obvious here that I have
> overlooked & grossly simplified!
> 
> 
> matthew
> 
> 
> public class NamedDataSourceFactory extends
> BasicDataSourceFactory
> 
> static private Hashtable namedPools = new
> Hashtable();
> 
> public Object getObjectInstance(Object obj, Name
> name, 
> 		Context nameCtx, Hashtable environment)
>         throws Exception {
> 
>         Reference ref = (Reference) obj;
>         RefAddr ra = null;
>         String poolName = "defaultPoolName";
> 
>         // Get the name of the pool to use
>         ra = ref.get("poolName");
>         if (ra != null) {
>             poolName = ra.getContent().toString();
>         }
> 
>         // Check the Map to see if a pool with that
> name already exists
>         BasicDataSource namedDataSource = 
> 		(BasicDataSource)namedPools.get(poolName);
>         if (namedDataSource != null) 
>           return namedDataSource
>         else {
>           Object dataSource =
> 	
>
super.getObjectInstance(obj,name,nameCtx,environment);
>          
>           // Put the DataSource in the namedPools
> Map
>           namedPools.put(poolName, dataSource);
> 
>           return (dataSource);
>        }
> }
> 
> 



__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
Mime
View raw message