commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] Commented: (DBCP-309) First example for FSContext is invalid
Date Mon, 30 Nov 2009 16:26:20 GMT


Phil Steitz commented on DBCP-309:

Strike last comment.  DataSoources do not implement Referenceable, so direct references will
not work.  When using the FileSystem provider, datasources are created new for each lookup
(as reported in the issue).  Tomcat's in-memory provider, however, returns the same datasource
for repeated lookups.  The following test, for example, succeeds with the Tomcat provider,
but fails with the FS provider

Hashtable environment = new Hashtable();
        InitialContext ic = new InitialContext(environment);
        // Construct BasicDataSource reference
        Reference ref = new Reference("javax.sql.DataSource",
          "org.apache.commons.dbcp.BasicDataSourceFactory", null);
        ref.add(new StringRefAddr("driverClassName", "TesterDriver"));
        ref.add(new StringRefAddr("url", "jdbc:apache:commons:testdriver"));
        ref.add(new StringRefAddr("username", "username"));
        ref.add(new StringRefAddr("password", "password"));
        ic.rebind("jdbc/basic", ref);
        // Use
        InitialContext ic2 = new InitialContext(environment);
        DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
        ((BasicDataSource) ds).setAccessToUnderlyingConnectionAllowed(true);
        Connection conn = ds.getConnection();
        Connection uconn = ((DelegatingConnection) conn).getInnermostDelegate();
        DataSource ds2 = (DataSource) ic2.lookup("jdbc/basic");
        ((BasicDataSource) ds2).setAccessToUnderlyingConnectionAllowed(true);
        Connection conn2 = ds2.getConnection();
        Connection uconn2 = ((DelegatingConnection) conn2).getInnermostDelegate();
        Assert.assertEquals(ds, ds2);
        Assert.assertEquals(uconn2, uconn);

To make the examples less misleading, it seems we have two choices - 1) change to use the
Tomcat provider or 2) comment that the FS provider creates new datasources each time.  Would
appreciate comments / patches from JNDI spi experts on this.

> First example for FSContext is invalid
> --------------------------------------
>                 Key: DBCP-309
>                 URL:
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>            Reporter: Ondrej Tisler
>            Priority: Trivial
> First example on page is invalid,
with this code every call of  
>   InitialContext ic2 = new InitialContext();
>   DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
>   Connection conn = ds.getConnection();
>   conn.close();
> ends with new datasource with unclosed connection in it becase new Reference("javax.sql.DataSource",
 "org.apache.commons.dbcp.BasicDataSourceFactory", null); reference creates new DataSource
instead using created one while calling  ic2.lookup("jdbc/basic").
> At the end it ends with many opened connections to DB until JVM is ended.
> Second example I didn't test, i use direct aproach with manualy creating SharedPoolDataSource
and registring it in FSContext JNDI itself.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message