tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remy Maucherat" <r...@apache.org>
Subject Re: Tomcat & JNDI
Date Tue, 07 Nov 2000 07:41:26 GMT
> If I recall correctly, it's actually sort of tricky to get this right.
You
> might want to check the source for the Tomcat 4 implementation for
ideas -- I
> believe it depends on the servlet container calling
> Thread.setContextClassLoader() once you know which webapp you're running
in.
> This only works in a Java2 environment, though.

Almost. I use thread binding instead (which is more or less the same here).
I'll add class loader binding as an alternative to thread binding.

What is supported right now :

Only Tyrex is supported right now as the provider for javax.sql.DataSource
type (so get Tyrex first (http://tyrex.exolab.org). Then put it into the
"lib" directory in the Catalina distribution.

Then add to the web.xml :
    <resource-ref>
      <description>Test DataSource</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>
(that's an exemple, you can give it another name)

Of course, the factory doesn't really know what to do, so it will go to the
defaults, and try to create a memory based data source using hSQL. So to use
the defaults, you also need to get Hypersonic SQL from Sourceforge (and put
the hsql.jar file into "lib").

To set parameters for the data source, use env-entries with special names.
Here's a (self explanatory, IMO) example :
    <env-entry>
      <env-entry-name>jdbc/TestDB/user</env-entry-name>
      <env-entry-value>sa</env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>jdbc/TestDB/password</env-entry-name>
      <env-entry-value></env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>jdbc/TestDB/driverClassName</env-entry-name>
      <env-entry-value>org.hsql.jdbcDriver</env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>jdbc/TestDB/driverName</env-entry-name>
      <env-entry-value>jdbc:HypersonicSQL:database</env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

That's it. The lookup on "java:/comp/jdbc/TestDB" should return a usable
data source. A new instance of the data source is instantiated each time you
do the lookup, so I recommend that you bind that data source into the
per-web app writable initial context which is also provided to your servlet.

For transactions support a UserTransaction object is mapped at
"java:/comp/UserTransaction". I didn't test that functionality yet, so it
may not work.

Both resource-env-ref and ejb-ref are unsupported right now (actually, they
are, but there is no factory to instantiate the objects).
Resource references to JMS, JavaMail, .... types are also unsupported.

Remy


Mime
View raw message