You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Dirk Verbeeck <di...@pandora.be> on 2003/10/08 22:43:28 UTC

[DBCP] fixing issue 23491 Can't configure PerUserPoolDataSource for use with tomcat

  Any thoughts on how to fix this issue?
or how the current code should work?

I got it to work by adding the following to 
InstanceKeyObjectFactory.getObjectInstance
                    if (obj == null) {
                        PerUserPoolDataSource ds = new 
PerUserPoolDataSource();
                        ds.setDataSourceName((String)ra.getContent());
                        obj = ds;
                    }

and the following server.xml
 <Resource name="jdbc/bookstoreCPDS" auth="Container"
            type="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"/>
  <ResourceParams name="jdbc/bookstoreCPDS">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS</value>
    </parameter>
        <parameter><name>user</name><value>sa</value></parameter>
        <parameter><name>password</name><value></value></parameter>
        <parameter>
            <name>driver</name>
            <value>org.hsqldb.jdbcDriver</value></parameter>
        <parameter>
             <name>url</name>
             <value>jdbc:hsqldb:database</value>
        </parameter>
  </ResourceParams>
<Resource name="jdbc/PerUserBookstore" auth="SERVLET"
                    
type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"/>
<ResourceParams name="jdbc/PerUserBookstore">
  <parameter>
    <name>factory</name>
    
<value>org.apache.commons.dbcp.datasources.InstanceKeyObjectFactory</value>
  </parameter>
  <parameter>
    <name>instanceKey</name>
    <value>java:/comp/env/jdbc/bookstoreCPDS</value>
  </parameter>
</ResourceParams>

I did a quick test and found no problems this way.
Without the extra code I can't get it to work but maybe there is another 
way to automagically create the PerUserPoolDataSource.

Dirk



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [DBCP] fixing issue 23491 Can't configure PerUserPoolDataSource for use with tomcat

Posted by John McNally <jm...@apache.org>.
The way I wrote InstanceKeyObjectFactory it expected that an instance of
PerUserPoolDataSource would be created and bound to a jndi context.  In
such a case, the Reference as returned by getReference() method of
InstanceKeyDataSource would be used and things should work properly.

It appears in the case of tomcat and using server.xml to specify the
datasource properties, tomcat does not bind a Reference created from the
Referenceable object to the jndi name.  Rather it creates a reference
based on the parameters given in server.xml and that is passed to the
ObjectFactory.

Something along the lines of what you show below will be needed, though
that would limit the app to one connection pool.  I was thinking of
creating a map, possibly keyed on description.  Though description is
not required, I'm not sure what else to use.

I will work on this more tonight,
john mcnally   

On Wed, 2003-10-08 at 13:43, Dirk Verbeeck wrote:
>   Any thoughts on how to fix this issue?
> or how the current code should work?
> 
> I got it to work by adding the following to 
> InstanceKeyObjectFactory.getObjectInstance
>                     if (obj == null) {
>                         PerUserPoolDataSource ds = new 
> PerUserPoolDataSource();
>                         ds.setDataSourceName((String)ra.getContent());
>                         obj = ds;
>                     }
> 
> and the following server.xml
>  <Resource name="jdbc/bookstoreCPDS" auth="Container"
>             type="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"/>
>   <ResourceParams name="jdbc/bookstoreCPDS">
>     <parameter>
>       <name>factory</name>
>       <value>org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS</value>
>     </parameter>
>         <parameter><name>user</name><value>sa</value></parameter>
>         <parameter><name>password</name><value></value></parameter>
>         <parameter>
>             <name>driver</name>
>             <value>org.hsqldb.jdbcDriver</value></parameter>
>         <parameter>
>              <name>url</name>
>              <value>jdbc:hsqldb:database</value>
>         </parameter>
>   </ResourceParams>
> <Resource name="jdbc/PerUserBookstore" auth="SERVLET"
>                     
> type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource"/>
> <ResourceParams name="jdbc/PerUserBookstore">
>   <parameter>
>     <name>factory</name>
>     
> <value>org.apache.commons.dbcp.datasources.InstanceKeyObjectFactory</value>
>   </parameter>
>   <parameter>
>     <name>instanceKey</name>
>     <value>java:/comp/env/jdbc/bookstoreCPDS</value>
>   </parameter>
> </ResourceParams>
> 
> I did a quick test and found no problems this way.
> Without the extra code I can't get it to work but maybe there is another 
> way to automagically create the PerUserPoolDataSource.
> 
> Dirk
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org