https://issues.apache.org/bugzilla/show_bug.cgi?id=55078

            Bug ID: 55078
           Summary: Configuring a DataSource Resource with dataSourceJNDI
                    does not work as expected
           Product: Tomcat 7
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: timothy.stew...@gmail.com

Documentation at http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
indicates that one may use the dataSourceJNDI attribute to indicate the JNDI
name of the datasource to provide connections to the pool.  This actually
doesn't work.

In the code for class org.apache.tomcat.jdbc.pool.PooledConnection, we have an
outstanding "TODO".

Because of this TODO, the dataSourceJNDI is ignored, and the code ends up going
down the connectUsingDriver path, which ultimately logs a SQLException and
throws a NamingException.


The following is my current Resource configuration:

        <Resource name="jdbc/dmi/source/dse"
            auth="Container"
            type="com.dmotorworks.lib.sql.ConnectionPoolDataSource"
            factory="org.apache.naming.factory.BeanFactory"
            user="dse@$dse"
            aliases="dse|dse@$dse" />

        <Resource name="jdbc/dmi/dse"
            maxIdle="16" maxActive="16"
            maxAge="3600000"
            maxWait="2000"
            validationQuery="select 1 from dual"
            auth="Container"
            type="org.apache.tomcat.jdbc.pool.DataSource"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            dataSourceJNDI="java:comp/env/jdbc/dmi/source/dse" />

Note the "connection source" is an internal corporate datasource instantiated
as a bean.  We want to use that bean to provide connections into the Tomcat
JDBC pool and have it configured using a dataSourceJNDI reference.

The root-cause stack trace that is logged is:

java.sql.SQLException
        at
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:243)
        at
org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:176)
        at
org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:659)
        at
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:601)
        at
org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:464)
        at
org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:130)
        at
org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:112)
        at
org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:99)
        at
org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:499)
        at
org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:222)
        at
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
        at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:826)


PooledConnection code is below.  The problem is clearly the outstanding TODO.


    public void connect() throws SQLException {
        if (released.get()) throw new SQLException("A connection once released,
can't be reestablished.");
        if (connection != null) {
            try {
                this.disconnect(false);
            } catch (Exception x) {
                log.debug("Unable to disconnect previous connection.", x);
            } //catch
        } //end if
        if (poolProperties.getDataSource()==null &&
poolProperties.getDataSourceJNDI()!=null) {
            //TODO lookup JNDI name
        }

        if (poolProperties.getDataSource()!=null) {
            connectUsingDataSource();
        } else {
            connectUsingDriver();
        }

        //set up the default state, unless we expect the interceptor to do it
        if (poolProperties.getJdbcInterceptors()==null ||
poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0
||
               
poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getSimpleName())<0)
{
            if
(poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION)
connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
            if (poolProperties.getDefaultReadOnly()!=null)
connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
            if (poolProperties.getDefaultAutoCommit()!=null)
connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
            if (poolProperties.getDefaultCatalog()!=null)
connection.setCatalog(poolProperties.getDefaultCatalog());
        }
        this.discarded = false;
        this.lastConnected = System.currentTimeMillis();
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to