I'm new to ibatis. I have a question regarding jndi support. If I
understand everything correctly, to use JNDI, you need to set a data
source (and connection pool) inside the application server first, for
example, a data source with jndi name "testDB". Then in web.xml, I
need to have this section:
   <resource-ref>
      <description>test dat resource</description>
      <res-ref-name>testDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>APPLICATION</res-auth>
   </resource-ref>
Then with iBATIS, I can use:
   <transactionManager type="JDBC">
      <dataSource type="JNDI">
         <property name="DataSource" value="java:comp/env/testDB"/>
      </dataSource>
   </transactionManager>

And I did get this to work. The problem is in my case, the user can
add multiple data sources on the fly, and we don't really want them to
touch "web.xml" every single time. So I found one way to get around
this is to have these setting in the sqlMapConfig.xml (and then I
don't need to do anything in web.xml):
   <transactionManager type="JDBC">
      <dataSource type="JNDI">
         <property name="context.java.naming.factory.initial"
value="weblogic.jndi.WLInitialContextFactory"/>
         <property name="context.java.naming.provider.url"
value="t3://localhost:7001"/>
         <property name="DataSource" value="testDB"/>
      </dataSource>
   </transactionManager>
which basically initialize the context for you I assume. The "testDB"
part I need to figure out a way to pass in as a parameter.

This is again a little too specific. Ideally, we don't want the user
to set up the classname (for different app. server), or hostname, etc.
So my question is, is there any other ways to setup JNDI lookup so the
user doesn't have to touch the descriptor files every time? Thanks.

Reply via email to