Confusion about ConnectionPooling with Tomcat 4

2002-04-18 Thread rainer jünger

Hi,

I am getting a little confused about the topic weather Tomcat 4.x ist having a 
Connection Pooling implementet or not.
I was following the discussions the last few days and the answers have been a little 
contradicting.
Therfore my question loud and clear ; ) 
Is there a Connection Pooling using JNDI with Tomcat 4.x or not?
Below some postings concerning this topic from the last few days...

Thanks Rainer


past postings
Tomcat:  As far as I'm concerned, JNDI support is a now and forever more
feature of Tomcat 4 and later.  It's the standard access mechanism for
J2EE app servers as well.

Recommendation:  If you can, you should use JNDI based access to data
sources.  This is both portable across containers, and portable across
Struts versus non-Struts applications.  In addition, it can be used from
directly from within a JavaBean implementing your business logic, without
requiring a reference to ActionServlet or the servlet context (or the web
layer at all).


  In the javabean.
  
  import javax.naming.NamingException;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingEnumeration;
  import javax.naming.directory.InitialDirContext;
 
  class mybean() {
  java.sql.Connection conn
  
  get getPooledDatabaseConnection() {
  Context ctx = new  InitialContext();
  Context envCtx = (Context) ctx.lookup(java:/comp/env/);
  DataSource ds = (DataSource) envCtx.lookup(jdbc/dbpool);
  conn = ds.getConnection();
  }
  ...
  }

Yep ... that is exactly the pattern you can use.  Nice, isn't it?

 Soefara.


Craig


###


Unfortunately by using the Tomcat (4.0.x) default JNDI datasource factory
(aka Tyrex) you not only do not have a pool manager interface but you don't
have a pool.  The Tyrex factory only sets up one physical connection and one
pool instance AFAIK.

In order to create a pool you either can use the jakarta-commons DBCP
factory or write your own implementation.  Craig McClanahan recently posted
this DBCP implementation which works with TC 4.0.x.

 Craig's post
 It should be possible to use the DBCP based pool even with Tomcat 4.0.x by
 overriding the default JNDI factory for javax.sql.DataSource objects (I
 haven't tested this, but in theory it should all work).
 This requires the following steps:
 
 * Download recent nightly builds of the Collections, Pool, and DBCP
 packages from Jakarta Commons
 (http://jakarta.apache.org/builds/jakarta-commons/nightly/) and put
 the JAR files into $CATALINA_HOME/common/lib along with your JDBC
 driver.
 
 * Configure the factory parameter in the ResourceParams element
 to set the JNDI ObjectFactory class for this resource:
 
   ResourceParams name=jdbc/EmployeeDB
 parameter
   namefactory/name
   valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
 /parameter
 ... other configuration parameters ...
   /ResourceParams
 
 * Configure the other parameter values of the ResourceParams element
 from the list of supported properties below:
 - driverClassName - Fully qualified Java class name of the JDBC driver
 - maxActive   - Maximum number of active connections at one time
 - maxIdle - Maximum number of idle connections at one time
 (if more are returned to the pool, they will be
 closed to release database resources)
 - maxWait - Number of milliseconds the pool will wait when there
 are no available connections before causing
 getConnection() to throw an exception
 - password- Database password
 - url - Connection URL (also accepts driverName for
 backwards compatibility)
 - user- Database username
 - validationQuery - Optional SQL SELECT statement used to validate a
 connection before returning it to the application
 (must return at least one row).  This is helpful
 in catching stale connections because of timeouts
 or recycling of the database without stopping
 Tomcat.
 
 Alternatively, you can use any other connection pool you like, if you
 create your own javax.naming.spi.ObjectFactory implementation class (the
 JNDI object factory interface) and registering its name with the factory
 parameter.  Documentation is in the JNDI Specification and the
 corresponding Service Provider Interface document, at:
 
 http://java.sun.com/products/jndi/docs.html

As I said this implementation works fine for TC 4.0.x. and as Craig mentions
the DBCP BasicDataSourceFactory class is a good model for writing your own
implementation.

HTH

Steven

##

Yes, I have been able to get pooling data sources to work with mySql using
the mm drivers.  

RE: Confusion about ConnectionPooling with Tomcat 4.

2002-04-18 Thread Clearwater, Pete

Hi Rainer.

I am having the same confusion as you.  Based on testing the time required to get each 
connection, it appears as though the standard JNDI DataSource lookups do not return 
any sort of a pooled connection - it took virtually identical times to get a
connection from the JNDI DataSource as it did from a standard JDBC connection call.

I've tried implementing the latest pooling factory as set out by Craig (using 
org.apache.commons.dbcp.BasicDataSourceFactory), but I can't get this to work.  No 
matter what I try to do I always get the following error when I try to get a 
connection from
the returned DataSource:

java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:380)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.getConnection(Unknown Source)
at ubc.pubs.server.security.DBAccess.getDBConnection(DBAccess.java:47)
at ubc.pubs.server.security.DBAccess.getConnection(DBAccess.java:26)

Anyways, that's my 2 cents worth...  

If anybody can help with info on getting a jdbc connection pool going, I would be 
greatly appreciative.

pete.


 Hi, I am getting a little confused about the topic weather Tomcat 4.x ist 
 having a Connection Pooling implementet or not. I was following the discussions
 the last few days and the answers have been a little contradicting. Therfore my
 question loud and clear ; ) Is there a Connection Pooling using JNDI with 
Tomcat 4.x or not? Below some postings concerning this topic from the last few 
days... 

Thanks Rainer 


___
Pete Clearwater
Systems Analyst   Enrolment Services
Student Systems   Brock Hall
tel: 604.822.8662 2016-1874 East Mall
[EMAIL PROTECTED] Vancouver BC, Canada, V6T 1Z1



--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]




RE: Confusion about ConnectionPooling with Tomcat 4.

2002-04-18 Thread Clearwater, Pete


Found out my problem with the commons pooling stuff: it requires a ResourceParam of 
username instead of user - not sure if this is a bug or a feature but it does seem 
reasonable that the standard DataSource and this Pooled DataSource should take the
same parameters...

pete.

-Original Message-
From: Clearwater, Pete [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 18, 2002 9:25 AM
To: '[EMAIL PROTECTED]'
Subject: RE: Confusion about ConnectionPooling with Tomcat 4.


Hi Rainer.

I am having the same confusion as you.  Based on testing the time required to get each 
connection, it appears as though the standard JNDI DataSource lookups do not return 
any sort of a pooled connection - it took virtually identical times to get a
connection from the JNDI DataSource as it did from a standard JDBC connection call.

I've tried implementing the latest pooling factory as set out by Craig (using 
org.apache.commons.dbcp.BasicDataSourceFactory), but I can't get this to work.  No 
matter what I try to do I always get the following error when I try to get a 
connection from
the returned DataSource:

java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:380)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.getConnection(Unknown Source)
at ubc.pubs.server.security.DBAccess.getDBConnection(DBAccess.java:47)
at ubc.pubs.server.security.DBAccess.getConnection(DBAccess.java:26)

Anyways, that's my 2 cents worth...  

If anybody can help with info on getting a jdbc connection pool going, I would be 
greatly appreciative.

pete.


 Hi, I am getting a little confused about the topic weather Tomcat 4.x ist 
 having a Connection Pooling implementet or not. I was following the discussions
 the last few days and the answers have been a little contradicting. Therfore my
 question loud and clear ; ) Is there a Connection Pooling using JNDI with 
Tomcat 4.x or not? Below some postings concerning this topic from the last few 
days... 

Thanks Rainer 


___
Pete Clearwater
Systems Analyst   Enrolment Services
Student Systems   Brock Hall
tel: 604.822.8662 2016-1874 East Mall
[EMAIL PROTECTED] Vancouver BC, Canada, V6T 1Z1



--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]

--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]