11 Replies Latest reply on Apr 12, 2007 12:01 PM by asavitsky

    JBoss Tx on Tomcat - how to configure DataSource?

      Hi,

      I'm currently researching the possibility to use JBoss Transactions with our Tomcat apps. I've already figured it out with the UserTransaction lookup (a custom ObjectFactory implementation returning com.arjuna.ats.jta.UserTransaction.userTransaction()), but I'm stuck at the datasource configuration, and would appreciate any help offered.

      The usual DataSource declaration in Tomcat's server.xml (or META-INF/context.xml) looks like that:

      <Resource name="DataSource" auth="Container" type="javax.sql.DataSource" username="username"
       password="password" driverClassName="oracle.jdbc.driver.OracleDriver" url="dburl" />
      


      Typically, JTA setup involves specifying a factory class that would return JTA-aware data sources specific to the JTA provider used (it works that way, say, in JOTM and Atomikos). However, I couldn't find any mention of such factory in JBoss Tx, not any means to create a JTA-aware DS. The Programmer's Guide mentions the TransactionalDriver, which wraps the regular JDBC driver, to make it transaction-aware... is this something that should be used in Tomcat setup? Do I simply put the TransactionalDriver class as the driverClassName property, adding ":arjuna" to the JDBC URL? How would I configure it to use Oracle's driver underneath, then? Or did I completely misunderstood this part, and it's configured in some entirely different way?

      Thanks in advance,

      Alex

        • 1. Re: JBoss Tx on Tomcat - how to configure DataSource?
          marklittle

          By JTA-aware datasource, do you mean an XADataSource?

          • 2. Re: JBoss Tx on Tomcat - how to configure DataSource?

            Yes, that's what I mean - got a little mixed up in terminology...

            • 3. Re: JBoss Tx on Tomcat - how to configure DataSource?
              marklittle

              The TransactionalDriver doesn't give you back an XADataSource, but a wrapped JDBC connection. It's really meant to be used when outside of the application server, i.e., stand alone.

              • 4. Re: JBoss Tx on Tomcat - how to configure DataSource?

                Yes, I figured as much about the TransactionalDriver. Now, what about the DataSource? I'm looking for a JTA setup that is deployable on Tomcat (that part is working) and that has the XADataSource that is configured in Tomcat's context files (that's the part I have trouble with).

                • 5. Re: JBoss Tx on Tomcat - how to configure DataSource?
                  jhalliday

                  Hi Alex

                  I'm not clear what you are trying to achieve here. Do you want a datasource which will handle the resource enlistment for you, or just one that supplies XAConnections?

                  • 6. Re: JBoss Tx on Tomcat - how to configure DataSource?

                    Resource enlistment is not a requirement at this point, XA support should be enough.

                    Thanks,

                    Alex

                    • 7. Re: JBoss Tx on Tomcat - how to configure DataSource?
                      jhalliday

                      In that case there is nothing specific to the JTA implementation and hence your question would probably be better placed on the tomcat mailing lists. However, off the top of my head I'd probably go with a custom resource factory. The standard one in tomcat is basically a wrapper around the DBCP, which knows nothing about XA. You would need an implementation with enough knowhow to create XAConnections in whatever driver specific manner. Pooling is also trickier in an XA environment. You may be better off delegating to the driver's own XADataSource rather than reimplementing that functionality, assuming of course that you don't need to support too many different database drivers!

                      http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#Adding%20Custom%20Resource%20Factories

                      Or just use a stripped down JBossAS configuration, which will give you tomcat plus XA aware JDBC connections straight out of the box.

                      • 8. Re: JBoss Tx on Tomcat - how to configure DataSource?

                        So, basically, you are saying that for straight XA setup, without resource enlistment, there's nothing JBoss Tx-specific in data source setup, and I could simply use Oracle's own XA? I guess the factories that other JTA providers are using in data source definitions, are mostly for resource enlistment then. Good, it makes more sense to me now :)

                        Now, in an (unlikely) case that we might require enlistment functionality (I must admit I'm not entirely clear what is it used for) does JBoss Tx offer anything there?

                        Thanks,

                        Alex

                        • 9. Re: JBoss Tx on Tomcat - how to configure DataSource?
                          jhalliday

                          Getting an XAConnection is only part of the picture. The resource enlistment is the step that binds the connection and hence the database changes done over it, to a transaction. Without that bit the connection and the transaction don't have anything to do with one another and you may as well use a regular connection with no XA. I was really asking: does your application expect the datasource to enlist the connection on its behalf or does it do this itself. You earlier reply implies the latter, since enlistment is not optional and you don't want the datasource to do it. However, your more recent reply indicates that may not be the case... Anyhow, as for having a datasource that will automatically enlist resources, no we don't. The transactional driver is the closest you will get. You could maybe write a tomcat custom resource factory that wraps the transactional driver. Or once again: use JBossAS, which does have the required functionality. Reinventing the wheel is a Bad Thing.

                          • 10. Re: JBoss Tx on Tomcat - how to configure DataSource?
                            weston.price

                             


                            Anyhow, as for having a datasource that will automatically enlist resources, no we don't.


                            Or use JCA which provides for automatic transaction enlistment, pooling, security etc.

                            If using JBoss as a whole in your application is putting you off, you can simply remove all the services that are not relevant to your applications (ie EJB).

                            • 11. Re: JBoss Tx on Tomcat - how to configure DataSource?

                              Thanks for the clarification. I guess I'll use the non-XA setup for now, as the main goal was to have a JTA implementation up and running (I'm deploying JBoss Seam on Tomcat, and it requires a JTA provider). The JBoss AS is off-limits for our environment - we're using plain Tomcat, with AS environments being reserved for more complex/critical applications. I'd be interested in adding the JCA to the picture, however - is it available as a separate module?

                              Thanks,

                              Alex