Perhaps the idea here is to hide the JNDI look-up of the connection factory in
the servlet, thereby making the service code cleaner? In that case, your ideas
would still apply, but it's the ConnectionPool itself that needs to be passed
to the service, rather than the a specific connection. If the OP has a service
handler that knows about the special connection pool but not about the servlet
environment, then this would work. It might might make the service handler
testable away from the J2EE environment, which would be good.

On Thu, 8 Dec 2005, Ron Reynolds wrote:

> you mean how do you pass it forward from your servlet to your service handler?
>  i can see three ways - use a static ThreadLocal (singleton) to hold the
> connection and thus associate a Connection with the thread - the same thread
> will be used to call the service handler at which point it can call
> MyThreadSpecificConnectionHolder.get() to get the connection assigned to the
> thread back out.  OR you can put the connection into the MessageContext (which
> itself is stored in a ThreadLocal) using its setProperty()/getProperty()
> methods to pass it forward.
>
> tho in most cases its the service-handler's code that calls
> ConnectionPool.getConnection() when the connection is needed to avoid the
> overhead and additional dependency created using the above 2 methods (the
> first requires that you know that your thread's specific connection is stored
> in a singleton and the second requires that some string/key be used by both
> your servlet and your service handler).  if your service-handler doesn't need
> a connection to process the request you've created added work for yourself
> that doesn't provide any return on investment.
>
> just my $0.02 worth...
> .................ron.
> > Dear All:
> >
> > I've wrote a small servlet that extends AxisServlet.
> > This home-made servlet can get database connection from our connection
> > pooling mechanism.
> >
> > The question is : When I write the java code of my service , how can I
> > get a database connection ? I find no way to send a database connection
> > to my service from my own AxisServlet.
> >
> > Any idea ?
> >
> > Ken
> > --
> > ¬ãµo³¡             ­J­««Â             Ken Hu          [EMAIL PROTECTED]
> >
> > ©sµØ¬ì§ÞªÑ¥÷¦³­­¤½¥q
> > http://www.mmti.com.tw
> >
> > °ª¶¯É]804¹ª¤s°Ï½¬®ü¸ô70¸¹
> > °ê¥ß¤¤¤s¤j¾Ç³Ð·s¨|¦¨¤¤¤ß511«Ç
> >
> > ¹q¸Ü      07-5253020
> > ¶Ç¯u      07-5252165
> > ¦æ°Ê      0937083880
> >
> >
>
>

Guy Rixon                                       [EMAIL PROTECTED]
Institute of Astronomy                          Tel: +44-1223-337542
Madingley Road, Cambridge, UK, CB3 0HA          Fax: +44-1223-337523

Reply via email to