You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by aner <an...@ncstech.com> on 2001/08/31 19:23:10 UTC

Naming factory for generic java beans

Hi,

I recently worked on getting a JDBC connection pool/DataSource working on
Tomcat 4.0b7.  I was interested in trying out the OracleConnectionCacheImpl
which Oracle provides in their JDBC drivers.

I eventually found out that the only way to make an instance of this class
available from JNDI was to create my own Factory class for it.  It seemed
to me like there should be a simpler way to do something like this so I
created a factory class (BeanFactory) which can instantiate any class which
conforms to the JavaBeans spec (i.e. most classes...).

What would I have to do to contribute this class so it ships as a standard
part of Tomcat?  The class has worked out well for my purposes but I am not
sure if the ClassLoader portion of the code is doing the right thing, I copied
it from one of the other factory classes in org.apache.naming.factory.

Using this class, I am able to make the Oracle DataSource implementation
available to all my servlets using the following xml fragment in server.xml

<DefaultContext>
  <Resource name="jdbc/myDataSource" auth="SERVLET"
    type="oracle.jdbc.pool.OracleConnectionCacheImpl"/>
  <ResourceParams name="jdbc/myDataSource">
    <parameter>
      <name>factory</name>
      <value>org.apache.naming.factory.BeanFactory</value>
    </parameter>
    <parameter><name>driverType</name><value>thin</value></parameter>
    <parameter><name>serverName</name><value>hue</value></parameter>
    <parameter><name>networkProtocol</name><value>tcp</value></parameter> 
    <parameter><name>databaseName</name><value>XXXX</value></parameter>
    <parameter><name>portNumber</name><value>NNNN</value></parameter>
    <parameter><name>user</name><value>XXXX</value></parameter>
    <parameter><name>password</name><value>XXXX</value></parameter>
    <parameter><name>maxLimit</name><value>5</value></parameter>
  </ResourceParams>
</DefaultContext>

Similarly, you could make ANY JavaBean available from jndi using this factory.

I have attached my implementation to this message if anybody is interested in
getting it incorporated into Tomcat.

Thanks,

	- Aner

Re: Naming factory for generic java beans

Posted by Remy Maucherat <re...@apache.org>.
> Hi,
>
> I recently worked on getting a JDBC connection pool/DataSource working on
> Tomcat 4.0b7.  I was interested in trying out the
OracleConnectionCacheImpl
> which Oracle provides in their JDBC drivers.
>
> I eventually found out that the only way to make an instance of this class
> available from JNDI was to create my own Factory class for it.  It seemed
> to me like there should be a simpler way to do something like this so I
> created a factory class (BeanFactory) which can instantiate any class
which
> conforms to the JavaBeans spec (i.e. most classes...).

That looks like a good idea. Of course, in some cases, you'll probably still
need a custom factory.

> What would I have to do to contribute this class so it ships as a standard
> part of Tomcat?  The class has worked out well for my purposes but I am
not
> sure if the ClassLoader portion of the code is doing the right thing, I
copied
> it from one of the other factory classes in org.apache.naming.factory.

If the code builds and works, that's more than enough. If it's fine, then
I'll commit it.
Thanks !

> Using this class, I am able to make the Oracle DataSource implementation
> available to all my servlets using the following xml fragment in
server.xml
>
> <DefaultContext>
>   <Resource name="jdbc/myDataSource" auth="SERVLET"
>     type="oracle.jdbc.pool.OracleConnectionCacheImpl"/>
>   <ResourceParams name="jdbc/myDataSource">
>     <parameter>
>       <name>factory</name>
>       <value>org.apache.naming.factory.BeanFactory</value>
>     </parameter>
>     <parameter><name>driverType</name><value>thin</value></parameter>
>     <parameter><name>serverName</name><value>hue</value></parameter>
>     <parameter><name>networkProtocol</name><value>tcp</value></parameter>
>     <parameter><name>databaseName</name><value>XXXX</value></parameter>
>     <parameter><name>portNumber</name><value>NNNN</value></parameter>
>     <parameter><name>user</name><value>XXXX</value></parameter>
>     <parameter><name>password</name><value>XXXX</value></parameter>
>     <parameter><name>maxLimit</name><value>5</value></parameter>
>   </ResourceParams>
> </DefaultContext>

Looks good. I'll add the example to the Javadoc header of the factory.

Remy